Skip to content

XLSX: write one cfvo per icon in icon-set rules (#235) - #262

Merged
h-a-n-a-s-h-i merged 2 commits into
storytold:mainfrom
alexanderalber:fix/235-icon-set-cfvo
Oct 11, 2026
Merged

h-a-n-a-s-h-i merged 2 commits into
storytold:mainfrom
alexanderalber:fix/235-icon-set-cfvo

Conversation

@alexanderalber

@alexanderalber alexanderalber commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #235.

Problem

An icon-set rule without stored thresholds was written as <iconSet iconSet="3Arrows"></iconSet>. CT_IconSet requires at least two cfvo children, and openpyxl discards the rule. Every rule created by home.conditionalFormat has no thresholds, so the built-in sales sample is affected too.

While looking at the reader I found a second, related bug. Files carry one cfvo per icon (the first is the lower bound, as in the existing round-trip test), but evaluation only used stored thresholds when there was one fewer than the icon count. Custom thresholds read from a file were therefore ignored and the defaults applied.

Change

  • gridcraft-model: new icon_count (moved from engine::cf, now re-exported there) and default_icon_thresholds, so writer and evaluation share the same defaults: percent 0/33/67, 0/25/50/75, 0/20/40/60/80.
  • Writer: always one cfvo per icon. It writes the stored thresholds when there is one per icon, prepends the lower bound when that is the only one missing, and falls back to the defaults otherwise.
  • Evaluation: accepts both shapes (with and without the lower bound) and otherwise uses the same defaults.
  • icon_count is clamped to 3..=5. Previously a set name like 0Foo from a file gave k = 0, and k - 1 underflowed.

Behaviour change: rules without thresholds were previously evaluated by percentile. They now use percent of the min..max span, which is what the written file says. My understanding is that Percent 33/67 is Excel's default for a new icon-set rule (the ECMA-376 example shows the same values). I did not verify that against a running Excel.

Tests

  • xlsx::tests::roundtrip::icon_sets_always_write_one_cfvo_per_icon: empty thresholds, missing lower bound and an unknown set name, plus a read-back check.
  • engine::tests::icon_set_thresholds_from_files_pick_the_icon: default thresholds, and file-style thresholds (one per icon) deciding the icon.

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.

Also adds my own entry to contributors/people.toml (real name), as docs/contributors.md asks, committed by me in this PR.

(made with Claude Code)

🤖 Generated with Claude Code

An icon-set rule without stored thresholds (every rule made by
home.conditionalFormat, and the sales sample) was written as an empty
<iconSet>, which CT_IconSet forbids (cfvo minOccurs 2); openpyxl drops it.
The writer now always emits one cfvo per icon: the stored thresholds when
there is one per icon, the lower bound prepended when it is missing, else
Excel's defaults (percent 0/33/67, 0/25/50/75, 0/20/40/60/80).

Evaluation read the thresholds as one fewer than the icons, but files
carry one per icon (the first is the lower bound), so thresholds read from
a file were ignored. Both now share icon_count and default_icon_thresholds
in gridcraft-model; icon_count is clamped to 3..=5 so a set name like
"0Foo" can't underflow k - 1.

generated with Claude Code
@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 1eb7796 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 small conflict in contributors/people.toml 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.

XLSX export writes icon-set conditional formats with no <cfvo> children

3 participants