@@ -10,32 +10,32 @@ from excelbench_rust import UmyaBook
1010book = UmyaBook.open(" dashboard.xlsx" )
1111rules = book.read_conditional_formats(" Sheet1" )
1212for r in rules:
13- print (f " { r[' ranges ' ]} : { r[' type ' ]} " )
14- # [' A1:A100'] : cellIs
15- # [' B1:B100'] : colorScale
13+ print (f " { r[' range ' ]} : { r[' rule_type ' ]} " )
14+ # A1:A100: cellIs
15+ # B1:B100: colorScale
1616```
1717
1818## Writing Conditional Formats
1919
20- ### Cell Value Rules
21-
2220``` python
21+ from excelbench_rust import UmyaBook
22+
2323book = UmyaBook()
2424book.add_sheet(" Sales" )
2525
2626# Highlight cells greater than 1000
2727book.add_conditional_format(" Sales" , {
28- " ranges " : [ " B2:B50" ] ,
29- " type " : " cellIs" ,
28+ " range " : " B2:B50" ,
29+ " rule_type " : " cellIs" ,
3030 " operator" : " greaterThan" ,
3131 " formula" : " 1000" ,
3232 " format" : {" bg_color" : " #C6EFCE" , " font_color" : " #006100" }, # green
3333})
3434
3535# Highlight cells below target
3636book.add_conditional_format(" Sales" , {
37- " ranges " : [ " B2:B50" ] ,
38- " type " : " cellIs" ,
37+ " range " : " B2:B50" ,
38+ " rule_type " : " cellIs" ,
3939 " operator" : " lessThan" ,
4040 " formula" : " 500" ,
4141 " format" : {" bg_color" : " #FFC7CE" , " font_color" : " #9C0006" }, # red
@@ -44,54 +44,12 @@ book.add_conditional_format("Sales", {
4444book.save(" output.xlsx" )
4545```
4646
47- ### Color Scales
48-
49- ``` python
50- # 2-color scale (red to green)
51- book.add_conditional_format(" Sales" , {
52- " ranges" : [" C2:C50" ],
53- " type" : " colorScale" ,
54- " color_scale" : {
55- " min_color" : " #FF0000" ,
56- " max_color" : " #00FF00" ,
57- },
58- })
59-
60- # 3-color scale (red / yellow / green)
61- book.add_conditional_format(" Sales" , {
62- " ranges" : [" D2:D50" ],
63- " type" : " colorScale" ,
64- " color_scale" : {
65- " min_color" : " #FF0000" ,
66- " mid_color" : " #FFFF00" ,
67- " max_color" : " #00FF00" ,
68- },
69- })
70- ```
71-
72- ### Data Bars
73-
74- ``` python
75- book.add_conditional_format(" Sales" , {
76- " ranges" : [" E2:E50" ],
77- " type" : " dataBar" ,
78- " data_bar" : {" color" : " #638EC6" },
79- })
80- ```
81-
8247## Rule Types
8348
84- | Type | Description | Key fields |
49+ | Type | Description | Notes |
8550| ------| -------------| -----------|
86- | ` cellIs ` | Compare cell value | ` operator ` , ` formula ` , ` format ` |
87- | ` colorScale ` | Gradient fill | ` color_scale ` with 2-3 colors |
88- | ` dataBar ` | In-cell bar chart | ` data_bar ` with color |
89- | ` top10 ` | Top/bottom N | ` rank ` , ` percent ` , ` bottom ` |
90- | ` containsText ` | Text matching | ` text ` , ` format ` |
91-
92- ## Rule Priority
93-
94- !!! info "Evaluation order"
95- When multiple rules apply to the same cell, rules are evaluated
96- in the order they were added. The first matching rule determines
97- the formatting. This matches Excel's "Stop if True" default behavior.
51+ | ` cellIs ` | Compare cell value | Writing supported (operator/formula + basic colors) |
52+ | ` expression ` | Formula-based condition | Writing supported (formula + basic colors) |
53+ | ` colorScale ` | Gradient fill | Currently read-only in the Python API |
54+ | ` dataBar ` | In-cell bar chart | Currently read-only in the Python API |
55+ | ` iconSet ` | Icon set | Currently read-only in the Python API |
0 commit comments