pub struct PatternFill {
pub pattern_type: PatternType,
pub fg_color: Option<String>,
pub bg_color: Option<String>,
}Expand description
A cell’s non-solid pattern fill (<patternFill patternType="..">, CT_PatternFill).
Fields§
§pattern_type: PatternType§fg_color: Option<String>The pattern’s foreground color (8-hex-digit ARGB) — the color the pattern’s own lines/dots are drawn in.
bg_color: Option<String>The pattern’s background color (8-hex-digit ARGB) — the color showing through between the pattern’s lines/dots.
Implementations§
Source§impl PatternFill
impl PatternFill
Sourcepub fn new(pattern_type: PatternType) -> PatternFill
pub fn new(pattern_type: PatternType) -> PatternFill
Creates a pattern fill with no colors set yet (Excel’s own defaults — black foreground, white background — apply).
Examples found in repository?
examples/xlsx_cell_formatting.rs (line 41)
15fn main() -> office_toolkit::Result<()> {
16 let path = output_path("xlsx_cell_formatting.xlsx");
17
18 let borders_sheet =
19 Sheet::new("Borders").with_row(
20 Row::new()
21 .with_cell(Cell::text("Thin all around").with_format(
22 CellFormat::new().with_border(Border::all(BorderStyle::Thin, "FF000000")),
23 ))
24 .with_cell(Cell::text("Thick bottom only").with_format(
25 CellFormat::new().with_border(
26 Border::new().with_bottom(
27 BorderEdge::new(BorderStyle::Thick).with_color("FFC00000"),
28 ),
29 ),
30 )),
31 );
32
33 let fills_sheet = Sheet::new("Fills")
34 .with_row(Row::new().with_cell(
35 Cell::text("Solid fill").with_format(CellFormat::new().with_fill_color("FFFFF2CC")),
36 ))
37 .with_row(
38 Row::new().with_cell(
39 Cell::text("Pattern fill").with_format(
40 CellFormat::new().with_pattern_fill(
41 PatternFill::new(PatternType::LightGray)
42 .with_fg_color("FF4472C4")
43 .with_bg_color("FFFFFFFF"),
44 ),
45 ),
46 ),
47 )
48 .with_row(
49 Row::new().with_cell(Cell::text("Gradient fill").with_format(
50 CellFormat::new().with_gradient_fill(GradientFill::new(
51 90.0,
52 vec![
53 GradientStop::new(0.0, "FFFFFFFF"),
54 GradientStop::new(1.0, "FF4472C4"),
55 ],
56 )),
57 )),
58 );
59
60 let fonts_and_alignment_sheet =
61 Sheet::new("Fonts and alignment")
62 .with_row(
63 Row::new().with_cell(
64 Cell::text("Bold, red, 14pt").with_format(
65 CellFormat::new()
66 .with_bold(true)
67 .with_font_size(14.0)
68 .with_font_color("FFC00000"),
69 ),
70 ),
71 )
72 .with_row(
73 Row::new().with_cell(
74 Cell::text("Centered both ways").with_format(
75 CellFormat::new()
76 .with_horizontal_alignment(HorizontalAlignment::Center)
77 .with_vertical_alignment(VerticalAlignment::Center),
78 ),
79 ),
80 )
81 .with_row(Row::new().with_cell(
82 Cell::text("Indented text").with_format(CellFormat::new().with_indent(2)),
83 ));
84
85 let number_formats_sheet = Sheet::new("Number formats")
86 .with_row(Row::new().with_cell(
87 Cell::number(1234.5).with_format(CellFormat::new().with_number_format("#,##0.00")),
88 ))
89 .with_row(Row::new().with_cell(
90 Cell::number(0.0825).with_format(CellFormat::new().with_number_format("0.00%")),
91 ))
92 .with_row(Row::new().with_cell(
93 Cell::number(1234.5).with_format(CellFormat::new().with_number_format("$#,##0.00")),
94 ));
95
96 let named_styles_sheet = Sheet::new("Named styles").with_row(
97 Row::new().with_cell(
98 Cell::text("Uses a named style")
99 .with_format(CellFormat::new().with_named_style("Emphasis")),
100 ),
101 );
102
103 let workbook = Workbook::new()
104 .with_named_cell_style(NamedCellStyle::new(
105 "Emphasis",
106 CellFormat::new()
107 .with_bold(true)
108 .with_font_color("FF4472C4"),
109 ))
110 .with_sheet(borders_sheet)
111 .with_sheet(fills_sheet)
112 .with_sheet(fonts_and_alignment_sheet)
113 .with_sheet(number_formats_sheet)
114 .with_sheet(named_styles_sheet);
115
116 workbook.save_to_file(&path)?;
117 println!("Wrote {}", path.display());
118 Ok(())
119}Sourcepub fn with_fg_color(self, color: impl Into<String>) -> PatternFill
pub fn with_fg_color(self, color: impl Into<String>) -> PatternFill
Sets the foreground color and returns the fill for chaining.
Examples found in repository?
examples/xlsx_cell_formatting.rs (line 42)
15fn main() -> office_toolkit::Result<()> {
16 let path = output_path("xlsx_cell_formatting.xlsx");
17
18 let borders_sheet =
19 Sheet::new("Borders").with_row(
20 Row::new()
21 .with_cell(Cell::text("Thin all around").with_format(
22 CellFormat::new().with_border(Border::all(BorderStyle::Thin, "FF000000")),
23 ))
24 .with_cell(Cell::text("Thick bottom only").with_format(
25 CellFormat::new().with_border(
26 Border::new().with_bottom(
27 BorderEdge::new(BorderStyle::Thick).with_color("FFC00000"),
28 ),
29 ),
30 )),
31 );
32
33 let fills_sheet = Sheet::new("Fills")
34 .with_row(Row::new().with_cell(
35 Cell::text("Solid fill").with_format(CellFormat::new().with_fill_color("FFFFF2CC")),
36 ))
37 .with_row(
38 Row::new().with_cell(
39 Cell::text("Pattern fill").with_format(
40 CellFormat::new().with_pattern_fill(
41 PatternFill::new(PatternType::LightGray)
42 .with_fg_color("FF4472C4")
43 .with_bg_color("FFFFFFFF"),
44 ),
45 ),
46 ),
47 )
48 .with_row(
49 Row::new().with_cell(Cell::text("Gradient fill").with_format(
50 CellFormat::new().with_gradient_fill(GradientFill::new(
51 90.0,
52 vec![
53 GradientStop::new(0.0, "FFFFFFFF"),
54 GradientStop::new(1.0, "FF4472C4"),
55 ],
56 )),
57 )),
58 );
59
60 let fonts_and_alignment_sheet =
61 Sheet::new("Fonts and alignment")
62 .with_row(
63 Row::new().with_cell(
64 Cell::text("Bold, red, 14pt").with_format(
65 CellFormat::new()
66 .with_bold(true)
67 .with_font_size(14.0)
68 .with_font_color("FFC00000"),
69 ),
70 ),
71 )
72 .with_row(
73 Row::new().with_cell(
74 Cell::text("Centered both ways").with_format(
75 CellFormat::new()
76 .with_horizontal_alignment(HorizontalAlignment::Center)
77 .with_vertical_alignment(VerticalAlignment::Center),
78 ),
79 ),
80 )
81 .with_row(Row::new().with_cell(
82 Cell::text("Indented text").with_format(CellFormat::new().with_indent(2)),
83 ));
84
85 let number_formats_sheet = Sheet::new("Number formats")
86 .with_row(Row::new().with_cell(
87 Cell::number(1234.5).with_format(CellFormat::new().with_number_format("#,##0.00")),
88 ))
89 .with_row(Row::new().with_cell(
90 Cell::number(0.0825).with_format(CellFormat::new().with_number_format("0.00%")),
91 ))
92 .with_row(Row::new().with_cell(
93 Cell::number(1234.5).with_format(CellFormat::new().with_number_format("$#,##0.00")),
94 ));
95
96 let named_styles_sheet = Sheet::new("Named styles").with_row(
97 Row::new().with_cell(
98 Cell::text("Uses a named style")
99 .with_format(CellFormat::new().with_named_style("Emphasis")),
100 ),
101 );
102
103 let workbook = Workbook::new()
104 .with_named_cell_style(NamedCellStyle::new(
105 "Emphasis",
106 CellFormat::new()
107 .with_bold(true)
108 .with_font_color("FF4472C4"),
109 ))
110 .with_sheet(borders_sheet)
111 .with_sheet(fills_sheet)
112 .with_sheet(fonts_and_alignment_sheet)
113 .with_sheet(number_formats_sheet)
114 .with_sheet(named_styles_sheet);
115
116 workbook.save_to_file(&path)?;
117 println!("Wrote {}", path.display());
118 Ok(())
119}Sourcepub fn with_bg_color(self, color: impl Into<String>) -> PatternFill
pub fn with_bg_color(self, color: impl Into<String>) -> PatternFill
Sets the background color and returns the fill for chaining.
Examples found in repository?
examples/xlsx_cell_formatting.rs (line 43)
15fn main() -> office_toolkit::Result<()> {
16 let path = output_path("xlsx_cell_formatting.xlsx");
17
18 let borders_sheet =
19 Sheet::new("Borders").with_row(
20 Row::new()
21 .with_cell(Cell::text("Thin all around").with_format(
22 CellFormat::new().with_border(Border::all(BorderStyle::Thin, "FF000000")),
23 ))
24 .with_cell(Cell::text("Thick bottom only").with_format(
25 CellFormat::new().with_border(
26 Border::new().with_bottom(
27 BorderEdge::new(BorderStyle::Thick).with_color("FFC00000"),
28 ),
29 ),
30 )),
31 );
32
33 let fills_sheet = Sheet::new("Fills")
34 .with_row(Row::new().with_cell(
35 Cell::text("Solid fill").with_format(CellFormat::new().with_fill_color("FFFFF2CC")),
36 ))
37 .with_row(
38 Row::new().with_cell(
39 Cell::text("Pattern fill").with_format(
40 CellFormat::new().with_pattern_fill(
41 PatternFill::new(PatternType::LightGray)
42 .with_fg_color("FF4472C4")
43 .with_bg_color("FFFFFFFF"),
44 ),
45 ),
46 ),
47 )
48 .with_row(
49 Row::new().with_cell(Cell::text("Gradient fill").with_format(
50 CellFormat::new().with_gradient_fill(GradientFill::new(
51 90.0,
52 vec![
53 GradientStop::new(0.0, "FFFFFFFF"),
54 GradientStop::new(1.0, "FF4472C4"),
55 ],
56 )),
57 )),
58 );
59
60 let fonts_and_alignment_sheet =
61 Sheet::new("Fonts and alignment")
62 .with_row(
63 Row::new().with_cell(
64 Cell::text("Bold, red, 14pt").with_format(
65 CellFormat::new()
66 .with_bold(true)
67 .with_font_size(14.0)
68 .with_font_color("FFC00000"),
69 ),
70 ),
71 )
72 .with_row(
73 Row::new().with_cell(
74 Cell::text("Centered both ways").with_format(
75 CellFormat::new()
76 .with_horizontal_alignment(HorizontalAlignment::Center)
77 .with_vertical_alignment(VerticalAlignment::Center),
78 ),
79 ),
80 )
81 .with_row(Row::new().with_cell(
82 Cell::text("Indented text").with_format(CellFormat::new().with_indent(2)),
83 ));
84
85 let number_formats_sheet = Sheet::new("Number formats")
86 .with_row(Row::new().with_cell(
87 Cell::number(1234.5).with_format(CellFormat::new().with_number_format("#,##0.00")),
88 ))
89 .with_row(Row::new().with_cell(
90 Cell::number(0.0825).with_format(CellFormat::new().with_number_format("0.00%")),
91 ))
92 .with_row(Row::new().with_cell(
93 Cell::number(1234.5).with_format(CellFormat::new().with_number_format("$#,##0.00")),
94 ));
95
96 let named_styles_sheet = Sheet::new("Named styles").with_row(
97 Row::new().with_cell(
98 Cell::text("Uses a named style")
99 .with_format(CellFormat::new().with_named_style("Emphasis")),
100 ),
101 );
102
103 let workbook = Workbook::new()
104 .with_named_cell_style(NamedCellStyle::new(
105 "Emphasis",
106 CellFormat::new()
107 .with_bold(true)
108 .with_font_color("FF4472C4"),
109 ))
110 .with_sheet(borders_sheet)
111 .with_sheet(fills_sheet)
112 .with_sheet(fonts_and_alignment_sheet)
113 .with_sheet(number_formats_sheet)
114 .with_sheet(named_styles_sheet);
115
116 workbook.save_to_file(&path)?;
117 println!("Wrote {}", path.display());
118 Ok(())
119}Trait Implementations§
Source§impl Clone for PatternFill
impl Clone for PatternFill
Source§fn clone(&self) -> PatternFill
fn clone(&self) -> PatternFill
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PatternFill
impl Debug for PatternFill
Source§impl PartialEq for PatternFill
impl PartialEq for PatternFill
impl StructuralPartialEq for PatternFill
Auto Trait Implementations§
impl Freeze for PatternFill
impl RefUnwindSafe for PatternFill
impl Send for PatternFill
impl Sync for PatternFill
impl Unpin for PatternFill
impl UnsafeUnpin for PatternFill
impl UnwindSafe for PatternFill
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more