Commit 4527bfe
Phase 7: conditional formatting (#129)
* Add conditional formatting: the simple cell rules
xl_cond_cell() covers the rules that pair a condition with a format --
comparisons, text matches, time periods, above/below average, top/bottom N,
duplicates, uniques, blanks, errors and arbitrary formulas -- reaching
worksheet_conditional_format_range(). xl_sheet(conditional =) takes one or a
list of them through the Phase 0 overlay stage.
The 34 criteria are partitioned by rule type and libxlsxwriter checks none of
the pairing, so a text criteria on a cell rule produces a file Excel accepts and
then silently ignores. .CONDITIONAL_CRITERIA_FOR maps each type to what it
accepts, and a mismatch is an error naming both the criteria and the type and
listing what would be valid there. Where the two are redundant the type is
inferred from the criteria instead.
The format is an ordinary xl_format, so it goes through the existing registry
unchanged -- but conditional formats are emitted as differential formats. That
was worth verifying rather than assuming: a rule's fill lands in <dxfs> in
styles.xml and the rule references it by dxfId, which a test now pins.
The API consistency gate added in the previous review caught this before it
shipped: xl_cond_cell() had criteria before type while xl_validation() has type
before criteria, and the two share six arguments. Reordered to match, since in
both functions the type is what determines which criteria are legal.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Add colour scales, data bars and icon sets
xl_cond_scale() writes two- and three-colour scales, xl_cond_bar() in-cell data
bars with control over the negative and border colours, axis and direction, and
xl_cond_icons() one of Excel's seventeen built-in icon sets. Each is a separate
constructor because the clusters share almost no fields; all four flow through
one overlay kind.
Corrects the conditional type table. Three of libxlsxwriter's type constants --
2_COLOR_SCALE, 3_COLOR_SCALE and DATA_BAR -- carry no TYPE_ in their names, so
an earlier reading of the header missed them and put icon_sets at 14 rather
than 17. That is the index of a two-colour scale, so every icon set would have
silently written a scale instead. The commit before this one only used indices
0 to 13 and was unaffected.
The corrected mapping is pinned by enumerating all seventeen styles against the
names Excel stores, which is the test that would have caught the original
error: 5_quarters must give 5Quarters, 4_ratings must give 4Rating, and so on.
A further test asserts the map still has seventeen entries, so a style added by
a libxlsxwriter update fails here rather than being quietly unreachable.
Icon sets embed nothing: Excel draws them itself, and a test asserts no xl/media
part appears.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>1 parent addb67a commit 4527bfe
26 files changed
Lines changed: 1126 additions & 4 deletions
File tree
- R
- man
- src
- tests/testthat
- vignettes
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
33 | 38 | | |
34 | 39 | | |
35 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
43 | 48 | | |
44 | 49 | | |
45 | 50 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
158 | 161 | | |
159 | 162 | | |
160 | 163 | | |
| |||
174 | 177 | | |
175 | 178 | | |
176 | 179 | | |
177 | | - | |
| 180 | + | |
178 | 181 | | |
179 | 182 | | |
180 | 183 | | |
| |||
204 | 207 | | |
205 | 208 | | |
206 | 209 | | |
207 | | - | |
| 210 | + | |
| 211 | + | |
208 | 212 | | |
209 | 213 | | |
210 | 214 | | |
| |||
472 | 476 | | |
473 | 477 | | |
474 | 478 | | |
475 | | - | |
| 479 | + | |
| 480 | + | |
476 | 481 | | |
477 | 482 | | |
478 | 483 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments