pub struct ConditionalFormattingRule {
pub range: String,
pub condition: ConditionalFormattingCondition,
pub format: CellFormat,
}Expand description
A conditional formatting rule (<cfRule>, CT_CfRule) applied over a cell range
(<conditionalFormatting sqref="..">, CT_ConditionalFormatting).
Only the two most common rule types are modeled — see ConditionalFormattingCondition.
CT_CfRule’s many other types (colorScale, dataBar, iconSet, top10, uniqueValues,
duplicateValues, containsText, timePeriod, aboveAverage..) are not modeled — this
crate’s scope here is deliberately narrow.
Fields§
§range: StringThe cell range this rule applies to (sqref, e.g. "A1:A10").
condition: ConditionalFormattingConditionThe rule’s condition.
format: CellFormatThe formatting applied to cells in range when condition is met — reuses CellFormat,
the same subset already modeled for plain cell styles, as the shape of the underlying
differential format record (<dxf>, CT_Dxf — confirmed via ECMA-376 to be a sequence of
the same kind of optional font/numFmt/fill/ alignment/border/protection children
CellFormat already covers, minus borders/protection). Distinct CellFormats across a
workbook’s conditional formatting rules are deduplicated into shared xl/styles.xml
<dxfs> entries by the writer, see writer.rs::collect_dxfs.
Implementations§
Source§impl ConditionalFormattingRule
impl ConditionalFormattingRule
Sourcepub fn cell_is(
range: impl Into<String>,
operator: ComparisonOperator,
formula1: impl Into<String>,
format: CellFormat,
) -> ConditionalFormattingRule
pub fn cell_is( range: impl Into<String>, operator: ComparisonOperator, formula1: impl Into<String>, format: CellFormat, ) -> ConditionalFormattingRule
Creates a cellIs rule.
Examples found in repository?
17fn main() -> office_toolkit::Result<()> {
18 let path = output_path("xlsx_conditional_formatting_and_validation.xlsx");
19
20 let cell_is_sheet = Sheet::new("Cell-is rule")
21 .with_row(Row::new().with_number(45.0))
22 .with_row(Row::new().with_number(72.0))
23 .with_row(Row::new().with_number(91.0))
24 .with_conditional_formatting_rule(ConditionalFormattingRule::cell_is(
25 "A1:A3",
26 ComparisonOperator::GreaterThan,
27 "70",
28 CellFormat::new()
29 .with_fill_color("FFC6EFCE")
30 .with_font_color("FF006100"),
31 ));
32
33 let scales_and_bars_sheet = Sheet::new("Color scale and data bar")
34 .with_row(Row::new().with_number(10.0))
35 .with_row(Row::new().with_number(50.0))
36 .with_row(Row::new().with_number(90.0))
37 .with_conditional_formatting_rule(ConditionalFormattingRule::color_scale(
38 "A1:A3",
39 vec![
40 ColorScaleStop::new(CfvoPosition::Min, "FFF8696B"),
41 ColorScaleStop::new(CfvoPosition::Max, "FF63BE7B"),
42 ],
43 ))
44 .with_row(Row::new().with_number(10.0))
45 .with_row(Row::new().with_number(50.0))
46 .with_row(Row::new().with_number(90.0))
47 .with_conditional_formatting_rule(ConditionalFormattingRule::data_bar(
48 "B1:B3",
49 CfvoPosition::Min,
50 CfvoPosition::Max,
51 "FF638EC6",
52 ));
53
54 let icon_set_and_ranking_sheet = Sheet::new("Icon set, top-10, duplicates")
55 .with_row(Row::new().with_number(1.0))
56 .with_row(Row::new().with_number(2.0))
57 .with_row(Row::new().with_number(3.0))
58 .with_conditional_formatting_rule(ConditionalFormattingRule::icon_set(
59 "A1:A3",
60 IconSetType::ThreeTrafficLights,
61 ))
62 .with_row(Row::new().with_number(4.0))
63 .with_row(Row::new().with_number(5.0))
64 .with_row(Row::new().with_number(6.0))
65 .with_conditional_formatting_rule(ConditionalFormattingRule::top10(
66 "B1:B3",
67 1,
68 false,
69 CellFormat::new().with_bold(true),
70 ))
71 .with_row(Row::new().with_text("A"))
72 .with_row(Row::new().with_text("A"))
73 .with_row(Row::new().with_text("B"))
74 .with_conditional_formatting_rule(ConditionalFormattingRule::duplicate_values(
75 "C1:C3",
76 CellFormat::new().with_fill_color("FFFFC7CE"),
77 ));
78
79 let data_validation_sheet = Sheet::new("Data validation")
80 .with_row(Row::new().with_text("Pick one"))
81 .with_data_validation_rule(DataValidationRule::list("A1:A1", "\"Small,Medium,Large\""))
82 .with_row(Row::new().with_number(0.0))
83 .with_data_validation_rule(
84 DataValidationRule::whole_number("B1:B1", ComparisonOperator::LessThanOrEqual, "100")
85 .with_input_message(
86 Message::new("Enter a whole number from 0 to 100.").with_title("Valid range"),
87 )
88 .with_error_message(
89 Message::new("That value is out of range.").with_title("Invalid entry"),
90 ),
91 );
92
93 let workbook = Workbook::new()
94 .with_sheet(cell_is_sheet)
95 .with_sheet(scales_and_bars_sheet)
96 .with_sheet(icon_set_and_ranking_sheet)
97 .with_sheet(data_validation_sheet);
98
99 workbook.save_to_file(&path)?;
100 println!("Wrote {}", path.display());
101 Ok(())
102}Sourcepub fn with_second_formula(
self,
formula2: impl Into<String>,
) -> ConditionalFormattingRule
pub fn with_second_formula( self, formula2: impl Into<String>, ) -> ConditionalFormattingRule
Sets the second comparison formula (for Between/NotBetween) and returns the rule for
chaining. A no-op if this rule isn’t a CellIs condition.
Sourcepub fn expression(
range: impl Into<String>,
formula: impl Into<String>,
format: CellFormat,
) -> ConditionalFormattingRule
pub fn expression( range: impl Into<String>, formula: impl Into<String>, format: CellFormat, ) -> ConditionalFormattingRule
Creates an expression rule.
Sourcepub fn color_scale(
range: impl Into<String>,
stops: Vec<ColorScaleStop>,
) -> ConditionalFormattingRule
pub fn color_scale( range: impl Into<String>, stops: Vec<ColorScaleStop>, ) -> ConditionalFormattingRule
Creates a color scale rule. format is ignored for this variant (see
ConditionalFormattingCondition::ColorScale’s doc comment) — always
CellFormat::default().
Examples found in repository?
17fn main() -> office_toolkit::Result<()> {
18 let path = output_path("xlsx_conditional_formatting_and_validation.xlsx");
19
20 let cell_is_sheet = Sheet::new("Cell-is rule")
21 .with_row(Row::new().with_number(45.0))
22 .with_row(Row::new().with_number(72.0))
23 .with_row(Row::new().with_number(91.0))
24 .with_conditional_formatting_rule(ConditionalFormattingRule::cell_is(
25 "A1:A3",
26 ComparisonOperator::GreaterThan,
27 "70",
28 CellFormat::new()
29 .with_fill_color("FFC6EFCE")
30 .with_font_color("FF006100"),
31 ));
32
33 let scales_and_bars_sheet = Sheet::new("Color scale and data bar")
34 .with_row(Row::new().with_number(10.0))
35 .with_row(Row::new().with_number(50.0))
36 .with_row(Row::new().with_number(90.0))
37 .with_conditional_formatting_rule(ConditionalFormattingRule::color_scale(
38 "A1:A3",
39 vec![
40 ColorScaleStop::new(CfvoPosition::Min, "FFF8696B"),
41 ColorScaleStop::new(CfvoPosition::Max, "FF63BE7B"),
42 ],
43 ))
44 .with_row(Row::new().with_number(10.0))
45 .with_row(Row::new().with_number(50.0))
46 .with_row(Row::new().with_number(90.0))
47 .with_conditional_formatting_rule(ConditionalFormattingRule::data_bar(
48 "B1:B3",
49 CfvoPosition::Min,
50 CfvoPosition::Max,
51 "FF638EC6",
52 ));
53
54 let icon_set_and_ranking_sheet = Sheet::new("Icon set, top-10, duplicates")
55 .with_row(Row::new().with_number(1.0))
56 .with_row(Row::new().with_number(2.0))
57 .with_row(Row::new().with_number(3.0))
58 .with_conditional_formatting_rule(ConditionalFormattingRule::icon_set(
59 "A1:A3",
60 IconSetType::ThreeTrafficLights,
61 ))
62 .with_row(Row::new().with_number(4.0))
63 .with_row(Row::new().with_number(5.0))
64 .with_row(Row::new().with_number(6.0))
65 .with_conditional_formatting_rule(ConditionalFormattingRule::top10(
66 "B1:B3",
67 1,
68 false,
69 CellFormat::new().with_bold(true),
70 ))
71 .with_row(Row::new().with_text("A"))
72 .with_row(Row::new().with_text("A"))
73 .with_row(Row::new().with_text("B"))
74 .with_conditional_formatting_rule(ConditionalFormattingRule::duplicate_values(
75 "C1:C3",
76 CellFormat::new().with_fill_color("FFFFC7CE"),
77 ));
78
79 let data_validation_sheet = Sheet::new("Data validation")
80 .with_row(Row::new().with_text("Pick one"))
81 .with_data_validation_rule(DataValidationRule::list("A1:A1", "\"Small,Medium,Large\""))
82 .with_row(Row::new().with_number(0.0))
83 .with_data_validation_rule(
84 DataValidationRule::whole_number("B1:B1", ComparisonOperator::LessThanOrEqual, "100")
85 .with_input_message(
86 Message::new("Enter a whole number from 0 to 100.").with_title("Valid range"),
87 )
88 .with_error_message(
89 Message::new("That value is out of range.").with_title("Invalid entry"),
90 ),
91 );
92
93 let workbook = Workbook::new()
94 .with_sheet(cell_is_sheet)
95 .with_sheet(scales_and_bars_sheet)
96 .with_sheet(icon_set_and_ranking_sheet)
97 .with_sheet(data_validation_sheet);
98
99 workbook.save_to_file(&path)?;
100 println!("Wrote {}", path.display());
101 Ok(())
102}Sourcepub fn data_bar(
range: impl Into<String>,
min: CfvoPosition,
max: CfvoPosition,
color: impl Into<String>,
) -> ConditionalFormattingRule
pub fn data_bar( range: impl Into<String>, min: CfvoPosition, max: CfvoPosition, color: impl Into<String>, ) -> ConditionalFormattingRule
Creates a data bar rule. format is ignored, same as color_scale.
Examples found in repository?
17fn main() -> office_toolkit::Result<()> {
18 let path = output_path("xlsx_conditional_formatting_and_validation.xlsx");
19
20 let cell_is_sheet = Sheet::new("Cell-is rule")
21 .with_row(Row::new().with_number(45.0))
22 .with_row(Row::new().with_number(72.0))
23 .with_row(Row::new().with_number(91.0))
24 .with_conditional_formatting_rule(ConditionalFormattingRule::cell_is(
25 "A1:A3",
26 ComparisonOperator::GreaterThan,
27 "70",
28 CellFormat::new()
29 .with_fill_color("FFC6EFCE")
30 .with_font_color("FF006100"),
31 ));
32
33 let scales_and_bars_sheet = Sheet::new("Color scale and data bar")
34 .with_row(Row::new().with_number(10.0))
35 .with_row(Row::new().with_number(50.0))
36 .with_row(Row::new().with_number(90.0))
37 .with_conditional_formatting_rule(ConditionalFormattingRule::color_scale(
38 "A1:A3",
39 vec![
40 ColorScaleStop::new(CfvoPosition::Min, "FFF8696B"),
41 ColorScaleStop::new(CfvoPosition::Max, "FF63BE7B"),
42 ],
43 ))
44 .with_row(Row::new().with_number(10.0))
45 .with_row(Row::new().with_number(50.0))
46 .with_row(Row::new().with_number(90.0))
47 .with_conditional_formatting_rule(ConditionalFormattingRule::data_bar(
48 "B1:B3",
49 CfvoPosition::Min,
50 CfvoPosition::Max,
51 "FF638EC6",
52 ));
53
54 let icon_set_and_ranking_sheet = Sheet::new("Icon set, top-10, duplicates")
55 .with_row(Row::new().with_number(1.0))
56 .with_row(Row::new().with_number(2.0))
57 .with_row(Row::new().with_number(3.0))
58 .with_conditional_formatting_rule(ConditionalFormattingRule::icon_set(
59 "A1:A3",
60 IconSetType::ThreeTrafficLights,
61 ))
62 .with_row(Row::new().with_number(4.0))
63 .with_row(Row::new().with_number(5.0))
64 .with_row(Row::new().with_number(6.0))
65 .with_conditional_formatting_rule(ConditionalFormattingRule::top10(
66 "B1:B3",
67 1,
68 false,
69 CellFormat::new().with_bold(true),
70 ))
71 .with_row(Row::new().with_text("A"))
72 .with_row(Row::new().with_text("A"))
73 .with_row(Row::new().with_text("B"))
74 .with_conditional_formatting_rule(ConditionalFormattingRule::duplicate_values(
75 "C1:C3",
76 CellFormat::new().with_fill_color("FFFFC7CE"),
77 ));
78
79 let data_validation_sheet = Sheet::new("Data validation")
80 .with_row(Row::new().with_text("Pick one"))
81 .with_data_validation_rule(DataValidationRule::list("A1:A1", "\"Small,Medium,Large\""))
82 .with_row(Row::new().with_number(0.0))
83 .with_data_validation_rule(
84 DataValidationRule::whole_number("B1:B1", ComparisonOperator::LessThanOrEqual, "100")
85 .with_input_message(
86 Message::new("Enter a whole number from 0 to 100.").with_title("Valid range"),
87 )
88 .with_error_message(
89 Message::new("That value is out of range.").with_title("Invalid entry"),
90 ),
91 );
92
93 let workbook = Workbook::new()
94 .with_sheet(cell_is_sheet)
95 .with_sheet(scales_and_bars_sheet)
96 .with_sheet(icon_set_and_ranking_sheet)
97 .with_sheet(data_validation_sheet);
98
99 workbook.save_to_file(&path)?;
100 println!("Wrote {}", path.display());
101 Ok(())
102}Sourcepub fn icon_set(
range: impl Into<String>,
icon_set: IconSetType,
) -> ConditionalFormattingRule
pub fn icon_set( range: impl Into<String>, icon_set: IconSetType, ) -> ConditionalFormattingRule
Creates a 3-icon-set rule with Excel’s own default equal-thirds percent thresholds. format
is ignored, same as color_scale.
Examples found in repository?
17fn main() -> office_toolkit::Result<()> {
18 let path = output_path("xlsx_conditional_formatting_and_validation.xlsx");
19
20 let cell_is_sheet = Sheet::new("Cell-is rule")
21 .with_row(Row::new().with_number(45.0))
22 .with_row(Row::new().with_number(72.0))
23 .with_row(Row::new().with_number(91.0))
24 .with_conditional_formatting_rule(ConditionalFormattingRule::cell_is(
25 "A1:A3",
26 ComparisonOperator::GreaterThan,
27 "70",
28 CellFormat::new()
29 .with_fill_color("FFC6EFCE")
30 .with_font_color("FF006100"),
31 ));
32
33 let scales_and_bars_sheet = Sheet::new("Color scale and data bar")
34 .with_row(Row::new().with_number(10.0))
35 .with_row(Row::new().with_number(50.0))
36 .with_row(Row::new().with_number(90.0))
37 .with_conditional_formatting_rule(ConditionalFormattingRule::color_scale(
38 "A1:A3",
39 vec![
40 ColorScaleStop::new(CfvoPosition::Min, "FFF8696B"),
41 ColorScaleStop::new(CfvoPosition::Max, "FF63BE7B"),
42 ],
43 ))
44 .with_row(Row::new().with_number(10.0))
45 .with_row(Row::new().with_number(50.0))
46 .with_row(Row::new().with_number(90.0))
47 .with_conditional_formatting_rule(ConditionalFormattingRule::data_bar(
48 "B1:B3",
49 CfvoPosition::Min,
50 CfvoPosition::Max,
51 "FF638EC6",
52 ));
53
54 let icon_set_and_ranking_sheet = Sheet::new("Icon set, top-10, duplicates")
55 .with_row(Row::new().with_number(1.0))
56 .with_row(Row::new().with_number(2.0))
57 .with_row(Row::new().with_number(3.0))
58 .with_conditional_formatting_rule(ConditionalFormattingRule::icon_set(
59 "A1:A3",
60 IconSetType::ThreeTrafficLights,
61 ))
62 .with_row(Row::new().with_number(4.0))
63 .with_row(Row::new().with_number(5.0))
64 .with_row(Row::new().with_number(6.0))
65 .with_conditional_formatting_rule(ConditionalFormattingRule::top10(
66 "B1:B3",
67 1,
68 false,
69 CellFormat::new().with_bold(true),
70 ))
71 .with_row(Row::new().with_text("A"))
72 .with_row(Row::new().with_text("A"))
73 .with_row(Row::new().with_text("B"))
74 .with_conditional_formatting_rule(ConditionalFormattingRule::duplicate_values(
75 "C1:C3",
76 CellFormat::new().with_fill_color("FFFFC7CE"),
77 ));
78
79 let data_validation_sheet = Sheet::new("Data validation")
80 .with_row(Row::new().with_text("Pick one"))
81 .with_data_validation_rule(DataValidationRule::list("A1:A1", "\"Small,Medium,Large\""))
82 .with_row(Row::new().with_number(0.0))
83 .with_data_validation_rule(
84 DataValidationRule::whole_number("B1:B1", ComparisonOperator::LessThanOrEqual, "100")
85 .with_input_message(
86 Message::new("Enter a whole number from 0 to 100.").with_title("Valid range"),
87 )
88 .with_error_message(
89 Message::new("That value is out of range.").with_title("Invalid entry"),
90 ),
91 );
92
93 let workbook = Workbook::new()
94 .with_sheet(cell_is_sheet)
95 .with_sheet(scales_and_bars_sheet)
96 .with_sheet(icon_set_and_ranking_sheet)
97 .with_sheet(data_validation_sheet);
98
99 workbook.save_to_file(&path)?;
100 println!("Wrote {}", path.display());
101 Ok(())
102}Sourcepub fn top10(
range: impl Into<String>,
rank: u32,
percent: bool,
format: CellFormat,
) -> ConditionalFormattingRule
pub fn top10( range: impl Into<String>, rank: u32, percent: bool, format: CellFormat, ) -> ConditionalFormattingRule
Creates a top10 rule (top rank items/percent).
Examples found in repository?
17fn main() -> office_toolkit::Result<()> {
18 let path = output_path("xlsx_conditional_formatting_and_validation.xlsx");
19
20 let cell_is_sheet = Sheet::new("Cell-is rule")
21 .with_row(Row::new().with_number(45.0))
22 .with_row(Row::new().with_number(72.0))
23 .with_row(Row::new().with_number(91.0))
24 .with_conditional_formatting_rule(ConditionalFormattingRule::cell_is(
25 "A1:A3",
26 ComparisonOperator::GreaterThan,
27 "70",
28 CellFormat::new()
29 .with_fill_color("FFC6EFCE")
30 .with_font_color("FF006100"),
31 ));
32
33 let scales_and_bars_sheet = Sheet::new("Color scale and data bar")
34 .with_row(Row::new().with_number(10.0))
35 .with_row(Row::new().with_number(50.0))
36 .with_row(Row::new().with_number(90.0))
37 .with_conditional_formatting_rule(ConditionalFormattingRule::color_scale(
38 "A1:A3",
39 vec![
40 ColorScaleStop::new(CfvoPosition::Min, "FFF8696B"),
41 ColorScaleStop::new(CfvoPosition::Max, "FF63BE7B"),
42 ],
43 ))
44 .with_row(Row::new().with_number(10.0))
45 .with_row(Row::new().with_number(50.0))
46 .with_row(Row::new().with_number(90.0))
47 .with_conditional_formatting_rule(ConditionalFormattingRule::data_bar(
48 "B1:B3",
49 CfvoPosition::Min,
50 CfvoPosition::Max,
51 "FF638EC6",
52 ));
53
54 let icon_set_and_ranking_sheet = Sheet::new("Icon set, top-10, duplicates")
55 .with_row(Row::new().with_number(1.0))
56 .with_row(Row::new().with_number(2.0))
57 .with_row(Row::new().with_number(3.0))
58 .with_conditional_formatting_rule(ConditionalFormattingRule::icon_set(
59 "A1:A3",
60 IconSetType::ThreeTrafficLights,
61 ))
62 .with_row(Row::new().with_number(4.0))
63 .with_row(Row::new().with_number(5.0))
64 .with_row(Row::new().with_number(6.0))
65 .with_conditional_formatting_rule(ConditionalFormattingRule::top10(
66 "B1:B3",
67 1,
68 false,
69 CellFormat::new().with_bold(true),
70 ))
71 .with_row(Row::new().with_text("A"))
72 .with_row(Row::new().with_text("A"))
73 .with_row(Row::new().with_text("B"))
74 .with_conditional_formatting_rule(ConditionalFormattingRule::duplicate_values(
75 "C1:C3",
76 CellFormat::new().with_fill_color("FFFFC7CE"),
77 ));
78
79 let data_validation_sheet = Sheet::new("Data validation")
80 .with_row(Row::new().with_text("Pick one"))
81 .with_data_validation_rule(DataValidationRule::list("A1:A1", "\"Small,Medium,Large\""))
82 .with_row(Row::new().with_number(0.0))
83 .with_data_validation_rule(
84 DataValidationRule::whole_number("B1:B1", ComparisonOperator::LessThanOrEqual, "100")
85 .with_input_message(
86 Message::new("Enter a whole number from 0 to 100.").with_title("Valid range"),
87 )
88 .with_error_message(
89 Message::new("That value is out of range.").with_title("Invalid entry"),
90 ),
91 );
92
93 let workbook = Workbook::new()
94 .with_sheet(cell_is_sheet)
95 .with_sheet(scales_and_bars_sheet)
96 .with_sheet(icon_set_and_ranking_sheet)
97 .with_sheet(data_validation_sheet);
98
99 workbook.save_to_file(&path)?;
100 println!("Wrote {}", path.display());
101 Ok(())
102}Sourcepub fn with_bottom(self, bottom: bool) -> ConditionalFormattingRule
pub fn with_bottom(self, bottom: bool) -> ConditionalFormattingRule
Sets top10’s bottom flag (highlight the bottom rank instead) and returns the rule for
chaining. A no-op for any other condition.
Sourcepub fn above_average(
range: impl Into<String>,
above: bool,
format: CellFormat,
) -> ConditionalFormattingRule
pub fn above_average( range: impl Into<String>, above: bool, format: CellFormat, ) -> ConditionalFormattingRule
Creates an aboveAverage rule.
Sourcepub fn duplicate_values(
range: impl Into<String>,
format: CellFormat,
) -> ConditionalFormattingRule
pub fn duplicate_values( range: impl Into<String>, format: CellFormat, ) -> ConditionalFormattingRule
Creates a duplicateValues rule.
Examples found in repository?
17fn main() -> office_toolkit::Result<()> {
18 let path = output_path("xlsx_conditional_formatting_and_validation.xlsx");
19
20 let cell_is_sheet = Sheet::new("Cell-is rule")
21 .with_row(Row::new().with_number(45.0))
22 .with_row(Row::new().with_number(72.0))
23 .with_row(Row::new().with_number(91.0))
24 .with_conditional_formatting_rule(ConditionalFormattingRule::cell_is(
25 "A1:A3",
26 ComparisonOperator::GreaterThan,
27 "70",
28 CellFormat::new()
29 .with_fill_color("FFC6EFCE")
30 .with_font_color("FF006100"),
31 ));
32
33 let scales_and_bars_sheet = Sheet::new("Color scale and data bar")
34 .with_row(Row::new().with_number(10.0))
35 .with_row(Row::new().with_number(50.0))
36 .with_row(Row::new().with_number(90.0))
37 .with_conditional_formatting_rule(ConditionalFormattingRule::color_scale(
38 "A1:A3",
39 vec![
40 ColorScaleStop::new(CfvoPosition::Min, "FFF8696B"),
41 ColorScaleStop::new(CfvoPosition::Max, "FF63BE7B"),
42 ],
43 ))
44 .with_row(Row::new().with_number(10.0))
45 .with_row(Row::new().with_number(50.0))
46 .with_row(Row::new().with_number(90.0))
47 .with_conditional_formatting_rule(ConditionalFormattingRule::data_bar(
48 "B1:B3",
49 CfvoPosition::Min,
50 CfvoPosition::Max,
51 "FF638EC6",
52 ));
53
54 let icon_set_and_ranking_sheet = Sheet::new("Icon set, top-10, duplicates")
55 .with_row(Row::new().with_number(1.0))
56 .with_row(Row::new().with_number(2.0))
57 .with_row(Row::new().with_number(3.0))
58 .with_conditional_formatting_rule(ConditionalFormattingRule::icon_set(
59 "A1:A3",
60 IconSetType::ThreeTrafficLights,
61 ))
62 .with_row(Row::new().with_number(4.0))
63 .with_row(Row::new().with_number(5.0))
64 .with_row(Row::new().with_number(6.0))
65 .with_conditional_formatting_rule(ConditionalFormattingRule::top10(
66 "B1:B3",
67 1,
68 false,
69 CellFormat::new().with_bold(true),
70 ))
71 .with_row(Row::new().with_text("A"))
72 .with_row(Row::new().with_text("A"))
73 .with_row(Row::new().with_text("B"))
74 .with_conditional_formatting_rule(ConditionalFormattingRule::duplicate_values(
75 "C1:C3",
76 CellFormat::new().with_fill_color("FFFFC7CE"),
77 ));
78
79 let data_validation_sheet = Sheet::new("Data validation")
80 .with_row(Row::new().with_text("Pick one"))
81 .with_data_validation_rule(DataValidationRule::list("A1:A1", "\"Small,Medium,Large\""))
82 .with_row(Row::new().with_number(0.0))
83 .with_data_validation_rule(
84 DataValidationRule::whole_number("B1:B1", ComparisonOperator::LessThanOrEqual, "100")
85 .with_input_message(
86 Message::new("Enter a whole number from 0 to 100.").with_title("Valid range"),
87 )
88 .with_error_message(
89 Message::new("That value is out of range.").with_title("Invalid entry"),
90 ),
91 );
92
93 let workbook = Workbook::new()
94 .with_sheet(cell_is_sheet)
95 .with_sheet(scales_and_bars_sheet)
96 .with_sheet(icon_set_and_ranking_sheet)
97 .with_sheet(data_validation_sheet);
98
99 workbook.save_to_file(&path)?;
100 println!("Wrote {}", path.display());
101 Ok(())
102}Sourcepub fn unique_values(
range: impl Into<String>,
format: CellFormat,
) -> ConditionalFormattingRule
pub fn unique_values( range: impl Into<String>, format: CellFormat, ) -> ConditionalFormattingRule
Creates a uniqueValues rule.
Sourcepub fn contains_text(
range: impl Into<String>,
operator: TextComparisonOperator,
text: impl Into<String>,
format: CellFormat,
) -> ConditionalFormattingRule
pub fn contains_text( range: impl Into<String>, operator: TextComparisonOperator, text: impl Into<String>, format: CellFormat, ) -> ConditionalFormattingRule
Creates a text-comparison rule (containsText/notContains/ beginsWith/endsWith).
Trait Implementations§
Source§impl Clone for ConditionalFormattingRule
impl Clone for ConditionalFormattingRule
Source§fn clone(&self) -> ConditionalFormattingRule
fn clone(&self) -> ConditionalFormattingRule
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more