Conditional formatting from a script¶
Regex rules, CSS styling, top-N and below-average highlighting — the same rules the GUI dialog builds, created headlessly and saved with the workbook.
You'll need: abax only.
Run it¶
What you should see¶
C2 88 -> fill #2e7d32
B3 BLOCKED -> fill #c62828, text #ffffff, bold
C3 35 -> fill #ff8f00
C4 72 -> fill #2e7d32
B5 blocked -> fill #c62828, text #ffffff, bold
C5 41 -> fill #ff8f00
C6 95 -> fill #2e7d32
C7 60 -> fill #ff8f00
Saved out/formatted.abax — open it to see the colours:
abax out/formatted.abax
How it works¶
- A
CondRuleis range + kind + value:kind="regex"withvalue="(?i)blocked"matches any case of "blocked". - The regex rule uses
css=instead of a plain fill — white bold text on red, exactly like typing that CSS in the GUI dialog. kind="top_n"(value 3) andkind="below_avg"are range-aware: they need one scan of the whole range, whichscale_context()precomputes once sostyle_at()stays cheap per cell — the same pattern the GUI grid uses on every repaint.- Rules live on
sheet.cond_rulesand persist inside the.abaxfile; openingout/formatted.abaxshows the colours in the grid.
Next steps¶
- The conditional-formatting guide documents every rule kind (comparisons, between, contains, duplicates, colour scales, …) with worked examples.
- In the GUI: Format → Conditional formatting….