Fix #42: pivot cache triggers Excel repair#74
Open
senoff wants to merge 1 commit into
Open
Conversation
…nt + axial-only sharedItems
5 tasks
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.
Original Problem
Workbooks with programmatically created pivot tables opened in Excel with a repair dialog: "Repaired Records: PivotTable report from /xl/pivotCache/pivotCacheDefinition1.xml part (PivotTable cache)". This made the feature unusable for production. See #42.
Cause
Two independent bugs in the pivot cache serialization:
recordCounton<pivotCacheDefinition>was set tocacheFields.length + 1(the number of columns plus one). Excel validates this attribute against thecountattribute of<pivotCacheRecords>, which is the number of data rows. A mismatch is one of the triggers for the repair dialog.makeCacheFieldsinlib/doc/pivot-table.jsenumerated fullsharedItemsfor ALL source fields, including value fields (e.g. a "Counter" column) and unused fields (e.g. a long-text "Description" column). Excel's strict cache validator flags full sharedItems enumeration for non-axial fields, especially when those fields contain high-cardinality or long strings.Fix
lib/xlsx/xform/pivot-table/pivot-cache-definition-xform.js: computerecordCount = Math.max(0, sourceSheet.getSheetValues().length - 2)(data rows = total rows minus header row, minus the one-based offset ofgetSheetValues).lib/doc/pivot-table.js: pass only axial field names ([...rows, ...columns, ...pages]) asfieldNamesWithSharedItemstomakeCacheFields. Addedinspect()helper that derives type hints (containsNumber, containsString, containsBlank) for non-axial fields without enumerating their values. Non-axial fields now produce{name, sharedItems: null, hints}.lib/xlsx/xform/pivot-table/cache-field.js: updated thesharedItems === nullrender path to emit a lightweight<sharedItems .../>with correct type attributes derived fromhints(was hard-codedcontainsNumber="1" containsInteger="1"which was wrong for string/mixed fields).Files changed
lib/doc/pivot-table.js—makePivotTable(axialFieldNames),makeCacheFields(signature +inspecthelper + result loop)lib/xlsx/xform/pivot-table/pivot-cache-definition-xform.js—recordCountcomputationlib/xlsx/xform/pivot-table/cache-field.js—constructor(acceptshints),render(lightweight sharedItems)spec/integration/issues/issue-42-pivot-cache-repair.spec.js— new test (5 cases)Test Run
5 tests verify: cache definition present, recordCount matches ROW_COUNT (20), Description field has no enumerated items (self-closing sharedItems), Repo/Severity axial fields retain full enumeration, workbook round-trips without error.
Cross-PR check
lib/doc/pivot-table.jsis also touched by PR #57 (formatter sweep, formatting only — no logic). No other open senoff PR touches the pivot cache files.Excel/soffice verification
sofficeis not available in this worker environment. The test verifies the XML structure through JSZip inspection:recordCountmatches the data row count and non-axialsharedItemsis self-closing. Recommend maintainer open the output file in Excel to confirm the repair dialog no longer appears before merge.grace-review summary
Run 1 — gpt-5.5: HIGH (non-axial text fields serialized as numeric records). Dismissed:
pivot-cache-records-xform.jsalready branches onNumber.isFinite(value)— text values emit<s v="..."/>not<n v="..."/>. gemini: HIGH (incomplete sharedItems attributes). Addressed: added correct containsString/containsSemiMixedTypes/containsNumber attrs for all hint combinations.Note: committed with
--no-verifyper AGENTS.md Rule 1.