Repository navigation
XLSX: write @ as _xlfn.SINGLE in a dynamic-array formula (#64) - #267
Merged
h-a-n-a-s-h-i merged 1 commit intoOct 11, 2026
Merged
Conversation
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
Member
|
Merged — thank you for the contribution! (I resolved a test-file conflict with #262 in roundtrip.rs while merging.) If you haven't already, come join us on the ArtCraft Discord: https://discord.gg/artcraft |
cloudbring
added a commit
to speedcraft-labs/gridcraft
that referenced
this pull request
Nov 7, 2026
This was referenced Nov 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #64. The export side of #64 is already fixed by #83; the issue is still open, and its read side is not addressed here (see below).
Problem
The file format has no
@operator, but a formula with an explicit implicit intersection was written with a literal@:Excel writes
@xas_xlfn.SINGLE(x)in a dynamic-array formula (that is also how an@shows up in pre-dynamic-array Excel). As far as I know, Excel does not accept a literal@in<f>. I could not verify this, because there is no Excel on this machine.Change
fmla::expr_to_file:@xbecomes_xlfn.SINGLE(x), next to the existingx#→_xlfn.ANCHORARRAY(x).SINGLE(x)(with or without_xlfn.) reads back as@x, just asANCHORARRAY(A1)already reads back asA1#.array_formula::needs_array: a formula containing@getscm="1", because_xlfn.SINGLEbelongs to dynamic-array formulas.After the change:
Changed expectations in the #83 test
implicit_intersection_metadata_respects_function_argument_contextexpectedSQRT(@A1:A3)and@A1:A3*2to be written as ordinary formulas withoutcm. In legacy Excel the@there is redundant, so the alternative would be to drop it and write<f>A1:A3*2</f>. That is only lossless if the reader puts the@back on formulas withoutcm. Today it doesn't, so the formula would come back as=A1:A3*2and spill in GridCraft. Until the read side exists, these two cases now expectcm. Once the reader inserts@into legacy formulas, writing redundant@s as plain legacy formulas becomes possible and the two expectations can flip back.Not in this PR: the read side of #64
A formula without
cmin an Excel-authored file is a legacy formula, and Excel evaluates it with implicit intersection. GridCraft still evaluates it with array semantics. Excel 365 handles this on load by inserting@wherever implicit intersection could occur. Doing the same would change how GridCraft computes every legacy file it opens, so I'd rather discuss it before sending a PR.Tests
fmla::tests::implicit_intersection: writer and reader text mapping.tests::roundtrip::implicit_intersection_is_written_as_single:cm,_xlfn.SINGLE, no literal@, metadata part present, and the formula reads back as@A1:A3*2. An ordinaryA1*2stays a plain formula.cargo xtask cion Windows: fmt, clippy, test, assets, layers and wasm pass.parityreportsdocs/parity-checklist.mdas out of date, but regenerating it gives no content diff (LF vs CRLF on a Windows checkout), so it is unrelated to this change.(made with Claude Code)
🤖 Generated with Claude Code