SheetJS (the xlsx package) decodes shared-formula relative references
incorrectly when reading a binary .xlsb workbook. The same workbook saved
as .xlsx parses correctly, which isolates the defect to .xlsb formula
decoding.
pnpm install
pnpm startThis runs against the two bundled fixtures — the same one-sheet workbook in both formats — and prints the contrast:
=== XLSX (parses correctly): shared-formula-fixture.xlsx ===
formula cells: 69 corrupt: 0
repro!L5: =SUM(A1:L1)/SUM(A3:L3)
=== XLSB (corrupt): shared-formula-fixture.xlsb ===
formula cells: 69 corrupt: 69
repro!L5: =SUM(XFE1048577:L1048577)/SUM(XFE1048579:L1048579) <-- CORRUPT
cached value (correct): 0.4479166666666667
RESULT: BUG REPRODUCED — .xlsb decoding emitted impossible references.
Check any other workbook with pnpm start path/to/workbook.xlsb.
Sheet repro has shared formulas with negative-offset relative references:
- row 5 (cols L onward): a 12-wide trailing window
=SUM(<c-11>1:<c>1)/SUM(<c-11>3:<c>3) - row 10 (all cols): a vertical 2-row sum
=SUM(<c>8:<c>9)
shared-formula-fixture.xlsx was authored programmatically; the .xlsb is that
exact file re-saved by Excel (Excel emits the shared-formula records that
trigger the bug; SheetJS's own .xlsb writer does not emit them).
| cell | expected | SheetJS actual |
|---|---|---|
| L5 | =SUM(A1:L1)/SUM(A3:L3) |
=SUM(XFE1048577:L1048577)/SUM(XFE1048579:L1048579) |
| M5 | =SUM(B1:M1)/SUM(B3:M3) |
=SUM(XFF1048577:M1048577)/SUM(XFF1048579:M1048579) |
The column wraps toward the XF* band (near max column 16384) and the row
wraps to 1048577 — one past Excel's max row (1,048,576) — so the reference is
impossible. The cells' cached values decode correctly, so the file is valid;
Excel and LibreOffice open it with the correct formulas.
Read-only value extraction is unaffected (cached values are intact). Any
consumer that recalculates formulas (a formula engine, or re-saving a
recalculated workbook) gets wrong results or #DIV/0!, because the corrupt
ranges point at empty far-corner cells.
Reproduced identically on:
xlsx@0.18.5(npm — the last npm release)xlsx@0.20.3(https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz)
To test 0.20.3:
pnpm add https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz
pnpm start