Skip to content

Fix styled stream pivot fields and formula XML - #184

Merged
Zncl2222 merged 2 commits into
Zncl2222:mainfrom
zfuchen:fix-styled-stream-pivot-fields-formulas
May 10, 2026
Merged

Fix styled stream pivot fields and formula XML#184
Zncl2222 merged 2 commits into
Zncl2222:mainfrom
zfuchen:fix-styled-stream-pivot-fields-formulas

Conversation

@zfuchen

@zfuchen zfuchen commented May 8, 2026

Copy link
Copy Markdown
Contributor

Summary

This fixes two regressions in the StreamWriter + PivotTable path after the large streamed data range fix in #183:

  • Preserve styled source headers when seeding pivot source headers before AddPivotTable.
  • Normalize formulas before passing them to excelize so worksheet XML does not contain formulas starting with =.

Root Cause

seedPivotSourceHeaders reads the source header row from ew.Content[sheet]["Data"] and seeds those values back into excelize so AddPivotTable can validate fields after streamed worksheets are flushed.

For styled StreamWriter sheets, performStreamWrite mutates each styled cell from the original []interface{}{value, style} into an excelize.Cell. The previous getCellScalarValue only unwrapped []interface{} and returned any other value as-is. As a result, styled header cells were written back as struct values such as:

{111 Category}
{112 42}

Those names no longer matched the PivotTable field definitions, so pivot cache fields could be malformed and pageFields, rowFields, or dataFields could be missing from the generated pivot table XML.

Separately, formulas were passed to excelize with the leading = included. Excelize expects formula text without that leading =, otherwise worksheet XML can contain invalid formulas like <f>=SUM(A2:A3)</f>.

Changes

  • Unwrap excelize.Cell.Value in getCellScalarValue.
  • Add normalizeFormula and strip one leading = before setting formulas in both StreamWriter and NormalWriter paths.
  • Add regression coverage for:
    • excelize.Cell scalar extraction.
    • styled StreamWriter pivot cache field names and row/page/data fields.
    • StreamWriter and NormalWriter formula XML without leading =.

Validation

~/go/bin/go1.24.0 test ./pyfastexcel/core -run 'TestCreateCell|TestWriteExcelWritesFormulaXMLWithoutLeadingEquals|TestGetCellScalarValueFromExcelizeCell|TestWriteExcelCreatesPivotTableForStyledStreamedData|TestWriteExcelCreatesPivotTableForLargeStreamedDataRange' -count=1
~/go/bin/go1.24.0 test ./...

Both commands pass locally.

I also validated the generated shared library against a representative styled StreamWriter pivot workbook. Without any Python-side OOXML repair, the generated workbook now has:

  • clean pivot cache field names, e.g. Category, Amount, Region
  • present pageFields, rowFields, and dataFields
  • worksheet formulas without leading = in <f> XML nodes

@codacy-production

codacy-production Bot commented May 8, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 35 complexity · 14 duplication

Metric Results
Complexity 35
Duplication 14

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@zfuchen
zfuchen force-pushed the fix-styled-stream-pivot-fields-formulas branch from a161170 to f85d88d Compare May 8, 2026 08:28
@codecov-commenter

codecov-commenter commented May 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.44%. Comparing base (1f20511) to head (8fe73a1).

Files with missing lines Patch % Lines
pyfastexcel/core/writer.go 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #184      +/-   ##
==========================================
+ Coverage   86.14%   86.44%   +0.30%     
==========================================
  Files           8        8              
  Lines         837      841       +4     
==========================================
+ Hits          721      727       +6     
+ Misses         78       75       -3     
- Partials       38       39       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Zncl2222
Zncl2222 force-pushed the fix-styled-stream-pivot-fields-formulas branch from 51dd187 to 47c82da Compare May 10, 2026 12:13
@Zncl2222
Zncl2222 force-pushed the fix-styled-stream-pivot-fields-formulas branch from 47c82da to 8fe73a1 Compare May 10, 2026 12:16
@Zncl2222
Zncl2222 merged commit ae79d76 into Zncl2222:main May 10, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants