Files
craft-libs/crates
kiwi4boy 734ade8cd9 craft-xlsx: read shared, array and dynamic-array formulas from .xlsb files (port of gridcraft#3821)
A cell whose tokens are only PtgExp (row) + PtgExtraCol (column) belongs to the shared or array
formula starting there; its first cell is followed by BrtShrFmla or BrtArrFmla.

- Shared formulas: each cell's copy is decoded from the shared tokens at its own cell, as
  [MS-XLSB] defines it (PtgRefN/PtgAreaN offsets, wrapping around the grid). Every cell of the
  group gets FormulaKind::Shared, its own text and the group's index (`si`, counted per sheet);
  the first also gets the group's range. Its first cell is the first that uses it, anywhere in
  its range. Copies are charged to the formula text allowance before they are decoded, so a long
  formula shared by a million cells stops costing once the allowance is spent.
- Ctrl+Shift+Enter and dynamic arrays: the first cell gets FormulaKind::Array with its range; a
  dynamic one also has its cell metadata (BrtCellMeta, which now also holds across a BrtValueMeta
  written in between), as `cm` marks it in .xlsx. The other cells of an array keep their cached
  values and have no formula, as in .xlsx.
- A record that can't be read leaves its range as values and never fails the file, with a
  warning; so does a first cell with no formula record after it.

Ported from storytold/gridcraft#3821 (issue gridcraft#3806), with its review fixes (each copy
decoded at its own cell; a shared formula may start inside its range). Changed from the
GridCraft PR:
- In .xlsx a shared formula's other cells have empty text. Here they have their own decoded text
  (and CellFormula's doc says so), because that is exact where shifting the first cell's text is
  not, as the PR's review found.
- Clearing an array's other cells for recalculation, marking dynamic arrays to spill, and the
  check against GridCraft's parser's 8,192-character limit are GridCraft's reading, not the
  file's: the cells keep what the file holds. That test becomes one that a copy may be longer
  than its first cell.
The PR's tests come along in tests/xlsb.rs, with craft-xlsx's model in the expectations.

Checked against Excel: in a workbook Excel saved both as .xlsb and as .xlsx, every formula this
reads (33, shared, array and dynamic ones included) has the .xlsx text, kind and range; the other
5 use tables, an external link or defined names.
2026-11-12 23:34:15 -05:00
..
2026-11-12 10:38:37 -05:00
2026-11-12 06:26:09 -05:00
2026-11-12 10:37:55 -05:00