From the first review round:
- 468 (0x1D4) is CONVERT, with 3 arguments. [MS-XLSB]'s Ftab table has no row for it, though
its grammar lists convert-params among the fixed-argument functions; Excel writes
=CONVERT(1,"m","ft") in .xlsb as a PtgFunc calling 0x1D4 (observed in Excel). It was the only
unassigned number from 0x17C to 0x1E4. The module doc says it isn't the specification's row.
- A BrtShrFmla's tokens and extra data are borrowed from the worksheet part instead of copied: a
record may claim up to 256 MiB, and each shared formula is kept for the rest of the sheet, so
the copies could cost as much again as the part. BrtArrFmla's are used at once and borrowed too.
- A formula record's cell metadata goes with its formula: when the formula is kept as its value
(tokens the reader can't decode, an unreadable BrtArrFmla), the cell loses its `cm`, which
would otherwise mark a dynamic-array formula that isn't there. A value cell keeps its cell
metadata, as the file has it.
The CONVERT and cell-metadata tests fail without this commit. The Excel-saved workbook still
reads with all 33 formulas as in its .xlsx.
They were "token streams that are not decoded". The README now says what the decoder gives
(text in the file's spelling, shared and array kinds and ranges, cell metadata, each shared copy's
own text), what keeps its saved result and why, that the function table and printer are this
crate's own, and the binary_formula_text limit with the decoder's fixed bounds.
From gridcraft#3821's review (CodeRabbit, still open there): a shared formula's copies are
checked against the formula text allowance with the first cell's length, which a copy can
exceed. A copy that was decoded and printed, then kept as its value because it didn't fit, or
because it couldn't be decoded, charged nothing, so a file with many cells of one long shared
formula could repeat that work for each of them. The PR's case was GridCraft's 8,192-character
rejection, which isn't here; the allowance and decode failures are the same path.
After one such copy the group keeps every later copy as its value without decoding it, so a
group costs at most one wasted decode. A new test shows a later copy that would have fit kept
as its value; it fails without this commit.
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.
A BIFF12 decoder for cell formulas (xlsb/formula.rs), separate from craft-xls's BIFF8 one because
nearly every operand differs (32-bit rows, 14-bit columns, UTF-16 strings, its own array-constant
codes, newer functions called through hidden names). It reads references, 3-D references,
constants, array constants, functions by number (xlsb/ftab.rs) and newer functions through
Excel's hidden _xlfn. names. A formula cell's CellFormula holds the text as an .xlsx file holds it
(`_xlfn.CONCAT`, `_xlpm.x`, no implicit `@`), and a BrtCellMeta before a cell gives it
cell_metadata, as `cm` does. Reverse-Polish tokens group by order alone, so the decoded tree
gets the parentheses its text needs from operator precedence; Excel's own text is unchanged. A
chain of string constants joined with & prints as one flat chain.
What a formula refers to must be readable too, so shared, array and data-table forms, user
defined names (XLSB names aren't read yet), table references, external links and PY(index, ...)
(code stored elsewhere in the package) keep only their saved results, with a warning saying why.
So does a formula past Limits::binary_formula_text (128 MiB of text over the workbook). The
workbook's links and names are optional: if they can't be read, the file opens with values only,
as before, and a warning says so.
Ported from storytold/gridcraft#3818 (issue gridcraft#3806), with its two review fixes
(grouping by precedence, the flat & chain). Changed from the GridCraft PR:
- The tree and its A1 printer (xlsb/expr.rs) are a copy of craft-xls's expr.rs, with
BinOp::precedence added; the decoder's stack and depth guards are copies of craft-xls's. The
PR used GridCraft's formula crate and shared these with GridCraft's .xls decoder.
- No fmla::from_file, implicit `@`, parse check or Python-cell adoption: those are GridCraft's
reading of the text, not the file's. A single-cell dynamic-array formula is read (with its
cell metadata) instead of being kept as its value; the PR left dynamic arrays to the next PR.
- The links are read with the workbook part and kept by Package for its sheets.
Its tests come along in tests/xlsb.rs, with the expected text in the file's spelling.
Checked against Excel: of the formulas in a workbook Excel saved both as .xlsb and as .xlsx,
every one this reads (26) has the text of the .xlsx; the other 12 are the kinds above.
[MS-XLSB]'s Ftab (2.5.98.10) continues the [MS-XLS] table from 0x17C: the cube functions, the old
Analysis ToolPak functions, IFERROR, COUNTIFS, SUMIFS and AVERAGEIF(S). Excel writes these by
number in .xlsb (PtgFunc / PtgFuncVar) where .xls calls them by name, so an XLSB formula decoder
needs them. Generated from the spec with the same argument-count rule as the existing entries.
Ported from storytold/gridcraft#3810 (issue gridcraft#3806). There the entries were appended to
GridCraft's .xls table, which is now craft-xls's. Here the table is craft-xlsx's own
(xlsb/ftab.rs): craft-xls's 0-379, which match GridCraft's table before the PR, then the PR's
entries. The two formats follow separate specifications and develop separately; they can share a
table later if both readers settle on one. The PR's table checks come along. Its decoding checks
(IFERROR, SUMIFS by number) go with the decoder in the next commit, and its check that every new
name is a GridCraft function stays in GridCraft.
mapped/placed say where a picture lies in document space for a source and a
painted display alike. A size-changing preview the app paints (a rotation
centred off the document's origin) gets its checkerboard and edge under the
preview, not at 0..size. Trial with offset areas; story RasterDisplay rotated.
FormDialog::preview(Bind<bool>) adds the Preview check box under the side buttons, with one
word (formDialog.preview) and hold-to-compare in FormOutput::comparing. ParamDialog,
HostedAdjustDialog and HostedLayerStyle use it; their own boxes and the paramDialog.preview,
adjust.preview and layerStyle.preview words are gone.
The hosted story helpers take the knob values the dialog is built from and replace the open
dialog when they change. The Export As story asks for a preview only while preview_ready is on.
Each opens on a DialogHost as a StackDialog that owns what its dialog edits
and binds the dialog's open state to its own field, so it opens again after
closing. HostedCanvasSize and HostedImageSize share SizingOutput::hosted.
HostedExportAs keeps its preview and save requests for the app as
HostedSaveForWeb does; HostedAbout keeps the activated link. HostedAlert
holds an Alert's content. HostedLayerStyle frames the Layer Style body in a
form dialog with side buttons and the Preview box, and queues the page's asks
as LayerStyleAsk. HostedAdjustDialog<V, E> frames any adjustment editor the
same way, resizable and remembered for Curves, with the editor's asks as E.
Stories open the hosted dialogs through a story host bound to the card's
open value (dialog::stories::hosted), so the card holds them behind its
button and story-render shows them open. Trials open each on a DialogHost
and check Escape, OK and the asks.