Skip to content

Fix Excel ooxml compatibility#1

Open
rolandboon wants to merge 5 commits into
litejs:mainfrom
rolandboon:fix/excel-ooxml-compatibility
Open

Fix Excel ooxml compatibility#1
rolandboon wants to merge 5 commits into
litejs:mainfrom
rolandboon:fix/excel-ooxml-compatibility

Conversation

@rolandboon

Copy link
Copy Markdown

Generated XLSX files opened in LibreOffice but Excel 365 reported them as corrupted. This PR fixes Open XML conformance issues so output passes the Microsoft Open XML SDK validator and opens correctly in Excel.

Fixed issues:

  • Compute dimension from the widest used row/column range, not just the first row
  • Include a complete styles.xml: cellStyleXfs, cellStyles, full cellXfs, fonts in schema order with <b val="1"/>, and 8-digit ARGB fill colors
  • Place dimension before sheetViews and fix freeze-pane topLeftCell when rows/cols is 0

I've extended the unit tests and updated the existing snapshots to reflect these changes.

In the last commit I've added a helper script to validate snapshots against the official Open XML Validator (which helped enormously in fixing these compatibility issues).

The dimension element must cover the full used range (CT_SheetDimension).
Derive the ref from the maximum column and row index across all rows,
including sparse rows and rows wider than the first row.
Emit a complete styleSheet part per SpreadsheetML: cellXfs with numFmtId,
fillId, borderId and xfId; required cellStyleXfs and cellStyles sections;
CT_Font children in schema order with boolean val attributes; and 8-digit
ARGB rgb values (ST_UnsignedIntHex) for solid fills.
Place dimension before sheetViews per CT_Worksheet child sequence. Treat
freeze rows and cols of zero explicitly so topLeftCell stays a valid ST_CellRef
and xSplit/ySplit are omitted when no split is requested.

Detect CommonJS module.exports for the IIFE export target.
Run Microsoft Open XML SDK validation on snapshot xlsx files via npx
(@xarsh/ooxml-validator), without adding a package dependency. Wired into
the Coverage CI job.
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.

1 participant