Skip to content

XLSX: write @ as _xlfn.SINGLE in a dynamic-array formula (#64) - #267

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
alexanderalber:fix/64-write-at-as-single
Oct 11, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
alexanderalber:fix/64-write-at-as-single

Conversation

@alexanderalber

Copy link
Copy Markdown
Contributor

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 @:

<c r="D3"><f>@A1:A3*2</f><v>10</v></c>
<c r="D2" cm="1"><f t="array" ref="D2">SUM(@A1:A3*B1:B3)</f><v>36</v></c>

Excel writes @x as _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: @x becomes _xlfn.SINGLE(x), next to the existing x# → _xlfn.ANCHORARRAY(x).
  • Parser: SINGLE(x) (with or without _xlfn.) reads back as @x, just as ANCHORARRAY(A1) already reads back as A1#.
  • array_formula::needs_array: a formula containing @ gets cm="1", because _xlfn.SINGLE belongs to dynamic-array formulas.

After the change:

<c r="D3" cm="1"><f t="array" ref="D3">_xlfn.SINGLE(A1:A3)*2</f><v>10</v></c>
<c r="D2" cm="1"><f t="array" ref="D2">SUM(_xlfn.SINGLE(A1:A3)*B1:B3)</f><v>36</v></c>

Changed expectations in the #83 test

implicit_intersection_metadata_respects_function_argument_context expected SQRT(@A1:A3) and @A1:A3*2 to be written as ordinary formulas without cm. 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 without cm. Today it doesn't, so the formula would come back as =A1:A3*2 and spill in GridCraft. Until the read side exists, these two cases now expect cm. 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 cm in 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 ordinary A1*2 stays a plain formula.
  • cargo xtask ci on Windows: fmt, clippy, test, assets, layers and wasm pass. parity reports docs/parity-checklist.md as 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

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
@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 85f0320 into storytold:main Oct 11, 2026
@echelon

echelon commented Oct 11, 2026

Copy link
Copy Markdown
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

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.

3 participants