Repository navigation
fix(xlsx): read and write PivotTable grand totals in Excel's direction - #1882
Conversation
rowGrandTotals is the Grand Total row under the report and colGrandTotals the Grand Total column at its right. Both were mapped the other way round; a GridCraft round trip hid it, but an Excel file with only one grand total opened with the other one.
The rowGrandTotals/colGrandTotals fix moved to its own PR at review's request.
|
An Excel check of the direction. I used Excel for Mac 16.114 on a synthetic workbook built in Excel: a PivotTable with Region in rows, Sum of Amount, and no column field. The screen was locked, so the grand totals were set through the object model (RowGrand/ColumnGrand), which the Design > Grand Totals menu sets, rather than through the ribbon itself.
With no column field, neither file has a Grand Total column, so this only tests the row side. I've added it to the Evidence section. |
|
A follow-up to my earlier comment: I repeated the check through the ribbon, this time with a column field. I used Excel for Mac 16.114 on a synthetic PivotTable: Region in rows, Product in columns, Sum of Amount. Each option was chosen from PivotTable Design > Grand Totals with real clicks and then saved. I opened and refreshed each saved file in GridCraft:
This covers the column side as well, and it replaces the scripting-only check in my earlier comment. The Evidence section is updated. |
|
Merged — thank you @neilcawse for the contribution! |
A PivotTable saved by Excel with only one grand total opened with the other one.
rowGrandTotalswas read intogrand_totals_rows, which the model defines as the Grand Total column ("On for Rows"), andcolGrandTotalsinto the Grand Total row. The writer used the same swapped mapping, so a GridCraft round trip hid the bug.Split out of #722, as requested in review.
What changed
crates/xlsx/src/pivot.rs:rowGrandTotalsnow maps togrand_totals_cols(the Grand Total row under the report) andcolGrandTotalstogrand_totals_rows(the Grand Total column at its right), when reading and when writing. The model, the engine and thepivot.*commands are unchanged; they already used the meanings documented incrates/model/src/features.rs.docs/file-format-parity.md: header and revision-history row.Evidence
Two files from public test suites, both last saved by Excel (
docProps/app.xml: "Microsoft Excel Online" 16.0300 and "Microsoft Excel" 15.0300):sc/qa/unit/data/xlsx/pivot/Pivot2_Row_Subtotals.xlsx(row fields only)rowGrandTotals="0"TemplateWithTableSourcePivotTables.xlsx, pivotTable5 on StressedAssetsPivot (row and column fields)colGrandTotals="0"A scan of 3,075 corpus files saved by Excel found 20 PivotTables with exactly one of the two attributes off. In 14 of them the saved cells show the expected grand total: 12 have a Grand Total row and 2 a Grand Total column. All 14 match this mapping and none matches the old one. The other 6 show no grand total at all, because the axis that would carry it has no field, so they don't tell the two mappings apart.
Excel for Mac 16.114, on a synthetic workbook built in Excel: a PivotTable with Region in rows, Product in columns and Sum of Amount. Each option was chosen from PivotTable Design > Grand Totals with real clicks and then saved. Each file was then opened and refreshed (
data.refreshAll) with this PR and withmain(6e984bb).mainrowGrandTotals="0"colGrandTotals="0"="0"An earlier run on a PivotTable with no column field, with the setting made through Excel's scripting (
RowGrand/ColumnGrand), agreed on the row side.Tests
grand_totals_read_in_excel_direction(new) readsrowGrandTotals="0",colGrandTotals="0"and neither, and checks both model flags.pivot_xml_detailsnow also checks which attribute the writer emits for each of the two fixture pivots.cargo test -p gridcraft-xlsx -p gridcraft-enginepasses (507 tests), andcargo xtask cipasses all 8 steps on 383bb7b.Review
docProps/app.xml) is now stated.Summary by CodeRabbit