Implement Charts#683
Open
ddimaria wants to merge 3 commits into
Open
Conversation
…eet layout Add style support for Calamine xlsx files. Public API: - `Xlsx::worksheet_style(sheet)` returns a row x col grid of cell styles using run-length encoding for memory efficiency on large workbooks. - `Xlsx::worksheet_layout(sheet)` returns column widths and row heights. Style types (in `src/style.rs`): - `Style` with optional Font / Fill / Borders / Alignment / NumberFormat / Protection. - `Color` with theme + tint resolution and indexed-color fallback. - `RichText` / `TextRun` for cells with mixed inline formatting. - `StyleRange` with RLE storage and a `cells()` iterator. Parser in `src/xlsx/style_parser.rs` handles fonts (bold / italic / underline / strikethrough / sz / color), fills, borders (with color and style per side), number formats (built-in + custom format codes), alignment (horizontal / vertical / wrap / indent / shrink / text rotation incl. stacked), protection (locked default per OOXML), theme colors with tint, and sysClr lastClr fallback. Shared-string reader now decodes rich text runs and preserves their formatting, while also handling plain text that precedes rich runs (consistent with upstream PR tafia#637). Includes benchmarks in `benches/style.rs` and test fixtures (styles.xlsx, borders.xlsx, EMSI_JobChange_UK.xlsx, problematic_formats.xlsx, styles_1M.xlsx) covering the various code paths. Co-authored-by: Cursor <cursoragent@cursor.com>
Add conditional formatting parsing for xlsx files. Builds on the
styles work added in the preceding commit.
Public API:
```rust
// vector of conditional formatting blocks for the named sheet
let cfs = xlsx.worksheet_conditional_formatting("Sheet1")?;
for cf in &cfs {
println!("range {}: {} rule(s)", cf.sqref, cf.rules.len());
for rule in &cf.rules {
match &rule.rule_type {
ConditionalFormatRuleType::CellIs { operator, formulas } => { /* ... */ }
ConditionalFormatRuleType::ColorScale3 { /* ... */ } => { /* ... */ }
/* ... */
}
}
}
```
Supported rule types (`src/conditional_format.rs`):
- `CellIs` (greaterThan, lessThan, between, equal, etc.)
- `ColorScale2` and `ColorScale3`
- `DataBar` (with fill and optional border color)
- `IconSet` (3TrafficLights, 5Arrows, ..., with `reversed` / `showValue`)
- `Top10` (top / bottom, percent / count)
- `AboveAverage` (above / below, equal-average, stdDev)
- `Text` (contains, notContains, beginsWith, endsWith)
- `ContainsBlanks` / `NotContainsBlanks`
- `ContainsErrors` / `NotContainsErrors`
- `DuplicateValues` / `UniqueValues`
- `Expression`
- `TimePeriod`
- `Unknown` (forwards the raw type for unrecognised rules)
Each rule carries `priority`, `stop_if_true`, the optional resolved
`Format` (looked up from the `<dxfs>` table), and any per-rule formula
strings.
Includes a criterion benchmark (`benches/conditional_formatting.rs`),
an example (`examples/conditional_formatting.rs`), and a fixture
covering all 25 supported rule variants (`tests/conditional_formatting.xlsx`).
Co-authored-by: Cursor <cursoragent@cursor.com>
Adds Xlsx::worksheet_charts / worksheet_charts_at to read the charts embedded in a worksheet or chartsheet, with a public data model in the new `chart` module (API modelled after rust_xlsxwriter's chart types). Supported: - All classic ECMA-376 chart families (bar, column, line, pie, doughnut, pie-of-pie, area, scatter, radar, stock, bubble, surface) including stacked, percent-stacked and 3D variants, and combo charts. - Excel 2016+ chart-ex parts (funnel, treemap, sunburst, histogram, pareto, box & whisker, waterfall, filled map), including the mc:AlternateContent drawing anchors and chartEx relationship type, hierarchical category levels and series layout options (binning, subtotals, statistics, element visibility, parent label layout). - Series data (range formulas plus cached values, multi-level category caches), titles (rich and formula-linked), legends, axes (position, scaling, tick marks, crossing partner, display units, text rotation), data labels (including per-point overrides), trendlines, error bars, up/down bars, drop/high-low/series lines, data tables, 3D view settings, and solid/gradient/pattern fills (with gradient angle) with theme color resolution. - Anchor fidelity: twoCellAnchor editAs and absoluteAnchor position. - Chart-space flags: autoTitleDeleted, plotVisOnly, showDLblsOverMax, date1904. Also exposes the workbook theme palette via Xlsx::theme_colors(), a named-slot ThemeColors struct (dark/light, accent1-6, hyperlink colors) parsed once from xl/theme/theme1.xml, cached, and falling back to the default Office palette, so consumers can reproduce Excel's accent-cycle coloring of unstyled series without re-parsing the package. Co-authored-by: Cursor <cursoragent@cursor.com>
ddimaria
force-pushed
the
implement-charts
branch
from
July 20, 2026 20:36
30a8fe2 to
d69ae3c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds chart reading to the XLSX reader via two new methods:
The reader walks the worksheet (or chartsheet) relationships to the drawing part, collects the anchored chart frames (two-cell, one-cell and absolute anchors, including their positions), and parses each chart part into a public
Chartdata model in the newchartmodule. The API is modelled afterrust_xlsxwriter's chart types so the two crates feel symmetrical (write withrust_xlsxwriter, read back withcalamine).Also exposes the workbook theme palette:
ThemeColorshas named slots (dark1/light1/dark2/light2,accent1–accent6,hyperlink,followed_hyperlink), parsed once fromxl/theme/theme1.xml, cached and reused by chart/style/conditional-formatting parsing, and falling back to the default Office palette (never errors). Consumers need it to color unstyled chart series the way Excel does (the theme accent cycle) without re-opening the package themselves.Supported
standardvsclustered3D grouping distinguished), wireframe/contour surfaces, and combo charts (multiple plot groups per chart).xl/charts/chartExN.xml): funnel, treemap, sunburst, histogram, pareto, box & whisker, waterfall and filled map, including themc:AlternateContentdrawing anchors, thechartExrelationship type, and per-series layout options (ChartExLayout: histogram binning, waterfall subtotals/connector lines, box & whisker statistics and element visibility, treemap parent label layout).c:dLbloverrides with delete/custom text/position), trendlines (all six types), error bars, invert-if-negative.c:crossAx), cross-between, display units, gridlines, number formats, titles, fonts and label text rotation.rotX/rotY/perspective/depth, per Correct MBSC to MBCS in vba.rs #180 in rust_xlsxwriter), gap/overlap, hole size, first slice angle, bubble scale/size-represents, pie-of-pie split settings (includingc:custSplitpoint lists), up/down bars, drop lines, high-low lines, series lines, data tables,dispBlanksAs, and the chart-space flagsautoTitleDeleted/plotVisOnly/showDLblsOverMax/date1904.ChartPositioncarries the anchor cells/extents pluseditAs(move/size behavior) and the absolute anchor x/y position.Not read (documented in the module docs)
Pivot chart sources, manual plot-area layouts, and surface band formats.
Test plan
tests/charts.xlsxfixture (pre-generated, committed totests/per the feedback on feat(xlsx): implement cell style extraction with rich text and worksheet layout #653 — no generator or dev-dependency added) with 18 classic charts + 5 chart-ex charts exercising every family and the options above.resolve_chart_typemapping tests, theme palette tests against both a default-theme and a real Excel theme, and a real Excel-generated chartsheet (tests/issue438.xlsx).--all-features; clippy and rustdoc clean.Notes
Stacked on #653 (styles) and #628 (conditional formatting); the first two commits here are those PRs. Only the
feat(xlsx): implement chart readingcommit is new — happy to rebase once the parents land.