pub struct ColumnSetting {
pub column: usize,
pub width: Option<f64>,
pub hidden: bool,
pub outline_level: u8,
pub collapsed: bool,
pub style: Option<CellFormat>,
}Expand description
A single column’s width/visibility/outline setting (<col>, CT_Col) — extended for
collapsed.
Fields§
§column: usizeThe 0-based column index this setting applies to (e.g. 0 for column A) — written as min == max == column + 1 (see Sheet.column_settings’s doc comment for why this crate doesn’t
bother collapsing adjacent columns into a single ranged <col>).
width: Option<f64>The column’s width, in Excel’s own character-width units. None leaves the column at
Excel’s default width.
Whether this column is hidden.
outline_level: u8This column’s outline (grouping) level (0-7).
collapsed: boolWhether this column’s outline group is shown collapsed (the “-” summary-only state of the
little outline button). Distinct from outline_level itself (which columns belong to the
group) — this is only the group’s current expanded/collapsed display state.
style: Option<CellFormat>This column’s default cell format (<col style="n">, an index into xl/styles.xml’s
cellXfs). Applied by real Excel to any cell in this column that doesn’t carry its own
explicit <c s=".."> — e.g. a brand-new cell typed into an empty row of this column picks
up this format automatically. Distinct from Cell::format: a cell’s own format always
wins over its column’s default when both are set (same precedence as real Excel’s own
column-formatting feature); this crate does not enforce or resolve that precedence itself,
it only stores and writes each side’s format independently, same “storage, not resolution”
posture as elsewhere in this crate. Deduplicated into shared cellXfs entries by the writer
exactly like Cell::format — see writer.rs::collect_cell_formats.
Implementations§
Source§impl ColumnSetting
impl ColumnSetting
Sourcepub fn new(column: usize) -> ColumnSetting
pub fn new(column: usize) -> ColumnSetting
Creates a column setting with no width/hidden/outline/style override yet (only useful as a
starting point for the with_* builders).
Examples found in repository?
13fn main() -> office_toolkit::Result<()> {
14 let path = output_path("xlsx_structure_and_layout.xlsx");
15
16 let merged_sheet = Sheet::new("Merged cells")
17 .with_row(Row::new().with_text("This title spans three columns"))
18 .with_merged_range("A1:C1");
19
20 let columns_sheet = Sheet::new("Columns")
21 .with_row(
22 Row::new()
23 .with_cell(Cell::text("Wide"))
24 .with_cell(Cell::text("Hidden"))
25 .with_cell(Cell::text("Grouped")),
26 )
27 .with_column_setting(ColumnSetting::new(0).with_width(30.0))
28 .with_column_setting(ColumnSetting::new(1).with_hidden(true))
29 .with_column_setting(
30 ColumnSetting::new(2)
31 .with_outline_level(1)
32 .with_collapsed(false),
33 );
34
35 let rows_sheet = Sheet::new("Rows")
36 .with_row(Row::new().with_text("Normal row"))
37 .with_row(Row::new().with_text("Taller row").with_height(30.0))
38 .with_row(Row::new().with_text("Hidden row").with_hidden(true))
39 .with_row(
40 Row::new()
41 .with_text("Grouped detail row")
42 .with_outline_level(1),
43 );
44
45 let frozen_panes_sheet = Sheet::new("Frozen panes")
46 .with_row(
47 Row::new()
48 .with_cell(Cell::text("Frozen header"))
49 .with_cell(Cell::text("Frozen header")),
50 )
51 .with_row(
52 Row::new()
53 .with_cell(Cell::text("Scrolling data"))
54 .with_cell(Cell::number(1.0)),
55 )
56 .with_freeze_panes(FreezePane::new(1, 1));
57
58 let page_breaks_sheet = Sheet::new("Page breaks")
59 .with_row(Row::new().with_text("Above this row: page break"))
60 .with_row(Row::new().with_text("Below the break"))
61 .with_row_break(1)
62 .with_column_break(0)
63 .with_outline_summary_below(false)
64 .with_outline_summary_right(false);
65
66 let workbook = Workbook::new()
67 .with_sheet(merged_sheet)
68 .with_sheet(columns_sheet)
69 .with_sheet(rows_sheet)
70 .with_sheet(frozen_panes_sheet)
71 .with_sheet(page_breaks_sheet);
72
73 workbook.save_to_file(&path)?;
74 println!("Wrote {}", path.display());
75 Ok(())
76}Sourcepub fn with_width(self, width: f64) -> ColumnSetting
pub fn with_width(self, width: f64) -> ColumnSetting
Sets the column’s width and returns it for chaining.
Examples found in repository?
13fn main() -> office_toolkit::Result<()> {
14 let path = output_path("xlsx_structure_and_layout.xlsx");
15
16 let merged_sheet = Sheet::new("Merged cells")
17 .with_row(Row::new().with_text("This title spans three columns"))
18 .with_merged_range("A1:C1");
19
20 let columns_sheet = Sheet::new("Columns")
21 .with_row(
22 Row::new()
23 .with_cell(Cell::text("Wide"))
24 .with_cell(Cell::text("Hidden"))
25 .with_cell(Cell::text("Grouped")),
26 )
27 .with_column_setting(ColumnSetting::new(0).with_width(30.0))
28 .with_column_setting(ColumnSetting::new(1).with_hidden(true))
29 .with_column_setting(
30 ColumnSetting::new(2)
31 .with_outline_level(1)
32 .with_collapsed(false),
33 );
34
35 let rows_sheet = Sheet::new("Rows")
36 .with_row(Row::new().with_text("Normal row"))
37 .with_row(Row::new().with_text("Taller row").with_height(30.0))
38 .with_row(Row::new().with_text("Hidden row").with_hidden(true))
39 .with_row(
40 Row::new()
41 .with_text("Grouped detail row")
42 .with_outline_level(1),
43 );
44
45 let frozen_panes_sheet = Sheet::new("Frozen panes")
46 .with_row(
47 Row::new()
48 .with_cell(Cell::text("Frozen header"))
49 .with_cell(Cell::text("Frozen header")),
50 )
51 .with_row(
52 Row::new()
53 .with_cell(Cell::text("Scrolling data"))
54 .with_cell(Cell::number(1.0)),
55 )
56 .with_freeze_panes(FreezePane::new(1, 1));
57
58 let page_breaks_sheet = Sheet::new("Page breaks")
59 .with_row(Row::new().with_text("Above this row: page break"))
60 .with_row(Row::new().with_text("Below the break"))
61 .with_row_break(1)
62 .with_column_break(0)
63 .with_outline_summary_below(false)
64 .with_outline_summary_right(false);
65
66 let workbook = Workbook::new()
67 .with_sheet(merged_sheet)
68 .with_sheet(columns_sheet)
69 .with_sheet(rows_sheet)
70 .with_sheet(frozen_panes_sheet)
71 .with_sheet(page_breaks_sheet);
72
73 workbook.save_to_file(&path)?;
74 println!("Wrote {}", path.display());
75 Ok(())
76}Sourcepub fn with_style(self, style: CellFormat) -> ColumnSetting
pub fn with_style(self, style: CellFormat) -> ColumnSetting
Sets the column’s default cell format and returns it for chaining.
Sets whether the column is hidden and returns it for chaining.
Examples found in repository?
13fn main() -> office_toolkit::Result<()> {
14 let path = output_path("xlsx_structure_and_layout.xlsx");
15
16 let merged_sheet = Sheet::new("Merged cells")
17 .with_row(Row::new().with_text("This title spans three columns"))
18 .with_merged_range("A1:C1");
19
20 let columns_sheet = Sheet::new("Columns")
21 .with_row(
22 Row::new()
23 .with_cell(Cell::text("Wide"))
24 .with_cell(Cell::text("Hidden"))
25 .with_cell(Cell::text("Grouped")),
26 )
27 .with_column_setting(ColumnSetting::new(0).with_width(30.0))
28 .with_column_setting(ColumnSetting::new(1).with_hidden(true))
29 .with_column_setting(
30 ColumnSetting::new(2)
31 .with_outline_level(1)
32 .with_collapsed(false),
33 );
34
35 let rows_sheet = Sheet::new("Rows")
36 .with_row(Row::new().with_text("Normal row"))
37 .with_row(Row::new().with_text("Taller row").with_height(30.0))
38 .with_row(Row::new().with_text("Hidden row").with_hidden(true))
39 .with_row(
40 Row::new()
41 .with_text("Grouped detail row")
42 .with_outline_level(1),
43 );
44
45 let frozen_panes_sheet = Sheet::new("Frozen panes")
46 .with_row(
47 Row::new()
48 .with_cell(Cell::text("Frozen header"))
49 .with_cell(Cell::text("Frozen header")),
50 )
51 .with_row(
52 Row::new()
53 .with_cell(Cell::text("Scrolling data"))
54 .with_cell(Cell::number(1.0)),
55 )
56 .with_freeze_panes(FreezePane::new(1, 1));
57
58 let page_breaks_sheet = Sheet::new("Page breaks")
59 .with_row(Row::new().with_text("Above this row: page break"))
60 .with_row(Row::new().with_text("Below the break"))
61 .with_row_break(1)
62 .with_column_break(0)
63 .with_outline_summary_below(false)
64 .with_outline_summary_right(false);
65
66 let workbook = Workbook::new()
67 .with_sheet(merged_sheet)
68 .with_sheet(columns_sheet)
69 .with_sheet(rows_sheet)
70 .with_sheet(frozen_panes_sheet)
71 .with_sheet(page_breaks_sheet);
72
73 workbook.save_to_file(&path)?;
74 println!("Wrote {}", path.display());
75 Ok(())
76}Sourcepub fn with_collapsed(self, collapsed: bool) -> ColumnSetting
pub fn with_collapsed(self, collapsed: bool) -> ColumnSetting
Sets whether this column’s outline group is shown collapsed and returns it for chaining.
Examples found in repository?
13fn main() -> office_toolkit::Result<()> {
14 let path = output_path("xlsx_structure_and_layout.xlsx");
15
16 let merged_sheet = Sheet::new("Merged cells")
17 .with_row(Row::new().with_text("This title spans three columns"))
18 .with_merged_range("A1:C1");
19
20 let columns_sheet = Sheet::new("Columns")
21 .with_row(
22 Row::new()
23 .with_cell(Cell::text("Wide"))
24 .with_cell(Cell::text("Hidden"))
25 .with_cell(Cell::text("Grouped")),
26 )
27 .with_column_setting(ColumnSetting::new(0).with_width(30.0))
28 .with_column_setting(ColumnSetting::new(1).with_hidden(true))
29 .with_column_setting(
30 ColumnSetting::new(2)
31 .with_outline_level(1)
32 .with_collapsed(false),
33 );
34
35 let rows_sheet = Sheet::new("Rows")
36 .with_row(Row::new().with_text("Normal row"))
37 .with_row(Row::new().with_text("Taller row").with_height(30.0))
38 .with_row(Row::new().with_text("Hidden row").with_hidden(true))
39 .with_row(
40 Row::new()
41 .with_text("Grouped detail row")
42 .with_outline_level(1),
43 );
44
45 let frozen_panes_sheet = Sheet::new("Frozen panes")
46 .with_row(
47 Row::new()
48 .with_cell(Cell::text("Frozen header"))
49 .with_cell(Cell::text("Frozen header")),
50 )
51 .with_row(
52 Row::new()
53 .with_cell(Cell::text("Scrolling data"))
54 .with_cell(Cell::number(1.0)),
55 )
56 .with_freeze_panes(FreezePane::new(1, 1));
57
58 let page_breaks_sheet = Sheet::new("Page breaks")
59 .with_row(Row::new().with_text("Above this row: page break"))
60 .with_row(Row::new().with_text("Below the break"))
61 .with_row_break(1)
62 .with_column_break(0)
63 .with_outline_summary_below(false)
64 .with_outline_summary_right(false);
65
66 let workbook = Workbook::new()
67 .with_sheet(merged_sheet)
68 .with_sheet(columns_sheet)
69 .with_sheet(rows_sheet)
70 .with_sheet(frozen_panes_sheet)
71 .with_sheet(page_breaks_sheet);
72
73 workbook.save_to_file(&path)?;
74 println!("Wrote {}", path.display());
75 Ok(())
76}Sourcepub fn with_outline_level(self, level: u8) -> ColumnSetting
pub fn with_outline_level(self, level: u8) -> ColumnSetting
Sets the column’s outline (grouping) level and returns it for chaining.
Examples found in repository?
13fn main() -> office_toolkit::Result<()> {
14 let path = output_path("xlsx_structure_and_layout.xlsx");
15
16 let merged_sheet = Sheet::new("Merged cells")
17 .with_row(Row::new().with_text("This title spans three columns"))
18 .with_merged_range("A1:C1");
19
20 let columns_sheet = Sheet::new("Columns")
21 .with_row(
22 Row::new()
23 .with_cell(Cell::text("Wide"))
24 .with_cell(Cell::text("Hidden"))
25 .with_cell(Cell::text("Grouped")),
26 )
27 .with_column_setting(ColumnSetting::new(0).with_width(30.0))
28 .with_column_setting(ColumnSetting::new(1).with_hidden(true))
29 .with_column_setting(
30 ColumnSetting::new(2)
31 .with_outline_level(1)
32 .with_collapsed(false),
33 );
34
35 let rows_sheet = Sheet::new("Rows")
36 .with_row(Row::new().with_text("Normal row"))
37 .with_row(Row::new().with_text("Taller row").with_height(30.0))
38 .with_row(Row::new().with_text("Hidden row").with_hidden(true))
39 .with_row(
40 Row::new()
41 .with_text("Grouped detail row")
42 .with_outline_level(1),
43 );
44
45 let frozen_panes_sheet = Sheet::new("Frozen panes")
46 .with_row(
47 Row::new()
48 .with_cell(Cell::text("Frozen header"))
49 .with_cell(Cell::text("Frozen header")),
50 )
51 .with_row(
52 Row::new()
53 .with_cell(Cell::text("Scrolling data"))
54 .with_cell(Cell::number(1.0)),
55 )
56 .with_freeze_panes(FreezePane::new(1, 1));
57
58 let page_breaks_sheet = Sheet::new("Page breaks")
59 .with_row(Row::new().with_text("Above this row: page break"))
60 .with_row(Row::new().with_text("Below the break"))
61 .with_row_break(1)
62 .with_column_break(0)
63 .with_outline_summary_below(false)
64 .with_outline_summary_right(false);
65
66 let workbook = Workbook::new()
67 .with_sheet(merged_sheet)
68 .with_sheet(columns_sheet)
69 .with_sheet(rows_sheet)
70 .with_sheet(frozen_panes_sheet)
71 .with_sheet(page_breaks_sheet);
72
73 workbook.save_to_file(&path)?;
74 println!("Wrote {}", path.display());
75 Ok(())
76}Trait Implementations§
Source§impl Clone for ColumnSetting
impl Clone for ColumnSetting
Source§fn clone(&self) -> ColumnSetting
fn clone(&self) -> ColumnSetting
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more