Skip to content

Preserve array evaluation for non-spilling XLSX formulas - #83

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
harrisonoconnorhover:codex/nonspilling-array-export
Oct 10, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
harrisonoconnorhover:codex/nonspilling-array-export

Conversation

@harrisonoconnorhover

@harrisonoconnorhover harrisonoconnorhover commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Addresses #64 (XLSX export).

SUM(Data!A1:A20*Data!B1:B20) can return a different value after export if Excel reads it with legacy implicit intersection. This preserves array evaluation for formulas that need it without converting every ordinary formula into a single-cell array.

The export-only classifier follows range/array operands, scalar function arguments, scoped names, structured references and indirect references. SUM(A1:A20), A1*2, ordinary table-row formulas and legacy array-aware SUMPRODUCT expressions remain ordinary formulas. Array-sensitive expressions receive cm="1" and an array reference; actual spills and legacy CSE arrays keep their respective representations. Explicit @ scalarizes its result while retaining any array-sensitive operations inside it. Analysis is bounded and conservative for unresolved reference dimensions; it does not evaluate formulas or change import behavior.

Rebased onto main at 1ded850, including #85. Its #SPILL!/#CALC! → #VALUE! cached-error behavior and regression coverage remain intact.

Validation:

  • All 52 XLSX tests pass, including eight focused export groups. Six updated groups failed under the original blanket-metadata policy before the classifier was added.
  • An original CLI workbook preserves live/reopened results for range arithmetic, scalar functions over ranges, names, INDIRECT, SUMPRODUCT and scalar controls. Saved XML confirms only affected formulas carry array metadata, while scalar table formulas do not.
  • Formatting, asset attribution, layering, WASM compilation, parity and diff checks pass. No dependency or layering changes.
  • Required cargo xtask ci stops at the existing core/src/date.rs:108 Clippy error. Scoped XLSX Clippy stops only at the existing sheet_read.rs:146 diagnostic; no suppressions added.

Excel-native recalculation was not run for this revision, and exact metadata parity for every function is not claimed. The reading-side legacy semantics in #64 remain separate. Policy and boundaries are documented in docs/decisions.md.

@nihilist-narwhal

nihilist-narwhal commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for picking this up. I checked this branch against Excel for Mac 16.113 (full recalculation and save) with the workbooks from #64:

main this PR classifier
Values match Excel (69 formulas) 38 / 69 69 / 69 69 / 69
cm matches what Excel itself writes (69) 31 / 69 41 / 69 69 / 69

So this fixes the wrong values. The trade-off: plain formulas like SUM(A1:A20) or A1*2, which Excel saves without cm, are all written as one-cell array formulas, and Excel keeps that on later saves. Excel 365 shows no difference. Older Excel versions are documented to open such formulas as legacy CSE (not tested here).

If you'd prefer to match Excel's own output, I have a branch that only flags formulas whose legacy reading could differ (array operands, arrays reaching single-value parameters, array results). Happy to open it as a PR, or not, as you prefer.

(Separate: cached #SPILL! values make Excel refuse the file; that's fixed in #85.)

@echelon

echelon commented Oct 10, 2026

Copy link
Copy Markdown
Member

Thank you for this — the implicit-intersection concern is real (SUM(A1:A3*B1:B3) must not be intersected). We'd like a narrower policy before merging, though: marking every non-CSE formula as a single-cell dynamic array (cm="1" + t="array") grows every file and makes pre-dynamic-array Excel and LibreOffice show all formulas as legacy {=…} arrays, which differs from what Excel itself writes. Could you limit it to formulas whose result can change under implicit intersection (a range/array expression where a scalar is expected, names, INDIRECT…)? Also, this now needs a rebase onto main (#85 touched the same lines of write_cell).

If you haven't already, please come join us on Discord: https://discord.gg/artcraft — happy to talk any of this through there.

@harrisonoconnorhover
harrisonoconnorhover force-pushed the codex/nonspilling-array-export branch from 5c7d609 to eec1bfe Compare October 10, 2026 16:19
@harrisonoconnorhover
harrisonoconnorhover force-pushed the codex/nonspilling-array-export branch from eec1bfe to 42854f2 Compare October 10, 2026 16:19
h-a-n-a-s-h-i pushed a commit that referenced this pull request Oct 10, 2026
Add static pictures inside cells with XLSX roundtrip

Rebased onto main (conflicts with #83/#98 and main resolved by maintainer); the contributor's branch does not allow maintainer edits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 59c8e36 into storytold:main Oct 10, 2026
@echelon

echelon commented Oct 10, 2026

Copy link
Copy Markdown
Member

Landed — thank you, Harrison! The narrower classifier is exactly what we asked for: only array-sensitive formulas get the dynamic-array marker, with bounded traversal and a safe fallback. Your branch doesn't allow maintainer edits, so I rebased it onto main myself and added a small fix-up (LET bindings via split_last/as_chunks to satisfy a newer clippy lint and avoid slice indexing).

If you haven't already, please come join us on Discord: https://discord.gg/artcraft

h-a-n-a-s-h-i pushed a commit that referenced this pull request Oct 10, 2026
…hed values refilled on recalc)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
h-a-n-a-s-h-i pushed a commit that referenced this pull request Oct 11, 2026
The file format has no `@` operator, but formulas with an explicit
implicit intersection were written with a literal `@`
(`<f>@A1:A3*2</f>`). Excel writes `@x` as `_xlfn.SINGLE(x)`, which only
dynamic-array formulas carry. The writer now does the same and marks such
formulas cm="1"; the parser reads `SINGLE(x)` back as `@x`, as it already
does for `ANCHORARRAY` and `#`.

Two cases in the #83 metadata test expected a redundant `@` (`SQRT(@A1:A3)`,
`@A1:A3*2`) to be written as an ordinary formula. Dropping the `@` there is
only lossless if the reader puts it back on legacy formulas, which it
doesn't yet (the read side of #64), so they now expect cm.

generated with Claude Code
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.

4 participants