mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 15:55:14 +00:00
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.