Skip to main content

ColumnSetting

Struct ColumnSetting 

Source
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: usize

The 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.

§hidden: bool

Whether this column is hidden.

§outline_level: u8

This column’s outline (grouping) level (0-7).

§collapsed: bool

Whether 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

Source

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?
examples/xlsx_structure_and_layout.rs (line 27)
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}
Source

pub fn with_width(self, width: f64) -> ColumnSetting

Sets the column’s width and returns it for chaining.

Examples found in repository?
examples/xlsx_structure_and_layout.rs (line 27)
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}
Source

pub fn with_style(self, style: CellFormat) -> ColumnSetting

Sets the column’s default cell format and returns it for chaining.

Source

pub fn with_hidden(self, hidden: bool) -> ColumnSetting

Sets whether the column is hidden and returns it for chaining.

Examples found in repository?
examples/xlsx_structure_and_layout.rs (line 28)
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}
Source

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?
examples/xlsx_structure_and_layout.rs (line 32)
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}
Source

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?
examples/xlsx_structure_and_layout.rs (line 31)
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

Source§

fn clone(&self) -> ColumnSetting

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ColumnSetting

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for ColumnSetting

Source§

fn eq(&self, other: &ColumnSetting) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ColumnSetting

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.