Skip to main content

Sheet

Struct Sheet 

Source
pub struct Sheet {
Show 33 fields pub name: String, pub rows: Vec<Row>, pub conditional_formatting_rules: Vec<ConditionalFormattingRule>, pub data_validation_rules: Vec<DataValidationRule>, pub merged_ranges: Vec<String>, pub column_settings: Vec<ColumnSetting>, pub auto_filter_range: Option<String>, pub freeze_panes: Option<FreezePane>, pub print_settings: PrintSettings, pub protection: Option<SheetProtection>, pub hyperlinks: Vec<CellHyperlink>, pub comments: Vec<CellComment>, pub table: Option<ExcelTable>, pub visibility: SheetVisibility, pub zoom_scale: Option<u32>, pub tab_color: Option<String>, pub show_grid_lines: Option<bool>, pub show_row_col_headers: Option<bool>, pub show_zeros: Option<bool>, pub right_to_left: Option<bool>, pub active_cell: Option<String>, pub default_column_width: Option<f64>, pub default_row_height: Option<f64>, pub row_breaks: Vec<u32>, pub column_breaks: Vec<u32>, pub scenarios: Vec<Scenario>, pub auto_filter_columns: Vec<AutoFilterColumn>, pub ignored_errors: Vec<IgnoredError>, pub protected_ranges: Vec<ProtectedRange>, pub sort_state: Option<SortState>, pub outline_summary_below: Option<bool>, pub outline_summary_right: Option<bool>, pub drawing: Option<SheetDrawing>,
}
Expand description

A single worksheet (xl/worksheets/sheetN.xml, CT_Worksheet): a name (shown on Excel’s sheet tab) plus a sequence of rows.

Fields§

§name: String

This sheet’s name (<sheet name=".."> in xl/workbook.xml), shown on Excel’s own sheet tab. Excel itself limits this to 31 characters and disallows a handful of characters (: \ / ? * [ ]) — neither limit is enforced here, same “caller’s responsibility” posture as word-ooxml’s PageSetup.orientation not auto-swapping dimensions.

§rows: Vec<Row>

The rows that make up this sheet’s data, in order. A row’s own 1-based row number (<row r="..">) is simply this row’s position in this Vec plus one — not a separate field — so there is no way to represent a sparse sheet (e.g. data starting at row 5 with rows 1-4 genuinely absent) when writing; reading back a sparse sheet from a real .xlsx still works (missing rows are filled in as empty), see reader.rs.

§conditional_formatting_rules: Vec<ConditionalFormattingRule>

Conditional formatting rules applied to ranges of this sheet (<conditionalFormatting>/<cfRule>, CT_ConditionalFormatting/ CT_CfRule), in order. Each rule gets its own dedicated <conditionalFormatting> block when written (see writer.rs::write_conditional_formatting) — real Excel groups multiple rules sharing the same range under one block, but nothing in the schema requires it, so this crate doesn’t bother.

§data_validation_rules: Vec<DataValidationRule>

Data validation rules applied to ranges of this sheet (<dataValidations>/<dataValidation>, CT_DataValidations/ CT_DataValidation), in order.

§merged_ranges: Vec<String>

Merged cell ranges (<mergeCells>/<mergeCell>, CT_MergeCells), each written verbatim as a range reference (e.g. "A1:C1"). This crate does not validate that ranges don’t overlap or that only the top-left cell of a merged range carries a value (both are the caller’s responsibility, same posture as ConditionalFormattingRule::range/DataValidationRule::range).

§column_settings: Vec<ColumnSetting>

Per-column width/visibility/outline settings (<cols>/<col>, CT_Cols/CT_Col). Each entry covers exactly one column (min == max in the written XML) — this crate doesn’t bother collapsing adjacent identical entries into a single <col min="1" max="3"../> range the way real Excel does, same “less compact but schema-valid” posture as ConditionalFormattingRule’s one-block-per-rule choice.

§auto_filter_range: Option<String>

The autofilter range (<autoFilter ref="..">, CT_AutoFilter), if any. Only the dropdown-arrow range is modeled, not per-column filter criteria (CT_FilterColumn/CT_Filters) — out of scope.

§freeze_panes: Option<FreezePane>

Frozen (or split) panes (<sheetView><pane../></sheetView>, CT_Pane), if any. Only “frozen” panes are modeled (the common case, e.g. freezing a header row/column), not “split” panes (a draggable divider with no scroll-locking) — CT_Pane’s state="split" variant is out of scope.

§print_settings: PrintSettings

This sheet’s print/page-setup settings (print area, repeated rows/columns, page orientation, fit-to-page, header/footer text). PrintSettings::default() (everything None) writes no print-related XML at all.

§protection: Option<SheetProtection>

This sheet’s protection settings (<sheetProtection>, CT_SheetProtection), if protected.

§hyperlinks: Vec<CellHyperlink>

Per-cell hyperlinks (<hyperlinks>/<hyperlink>, CT_Hyperlinks/ CT_Hyperlink).

§comments: Vec<CellComment>

Per-cell comments (legacy xl/comments*.xml + VML drawing, CT_Comments/CT_Comment).

§table: Option<ExcelTable>

A structured (ListObject) table on this sheet (<tableParts>/<tablePart> + a dedicated xl/tables/tableN.xml part, CT_Table), if any. Only one table per sheet is modeled (this crate’s own scope choice, not an ECMA-376 limit — real Excel allows several) since a single example is enough to prove the feature out; a second table on the same sheet is simply never written.

§visibility: SheetVisibility

This sheet’s tab visibility (<sheet state="."> in xl/workbook.xml — a CT_Sheet attribute, not part of the worksheet part itself) — extended to a genuine three-state SheetVisibility (was a plain bool before this).

§zoom_scale: Option<u32>

This sheet’s own display zoom percentage (<sheetView zoomScale="..">, e.g. 100 for 100%). None leaves Excel’s own default (100%).

§tab_color: Option<String>

This sheet’s tab color (<sheetPr><tabColor rgb=".."/></sheetPr>), as an 8-hex-digit ARGB string. None leaves Excel’s own default (no color, the plain gray/white tab).

§show_grid_lines: Option<bool>

Whether this sheet’s view shows gridlines (<sheetView showGridLines="..">). None leaves Excel’s own default (shown).

§show_row_col_headers: Option<bool>

Whether this sheet’s view shows row/column headers (<sheetView showRowColHeaders="..">). None leaves Excel’s own default (shown).

§show_zeros: Option<bool>

Whether this sheet’s view shows zero values, or leaves those cells blank (<sheetView showZeros="..">). None leaves Excel’s own default (shown).

§right_to_left: Option<bool>

Whether this sheet’s view is laid out right-to-left (<sheetView rightToLeft="..">). None leaves Excel’s own default (left-to-right).

§active_cell: Option<String>

The cell selected/active when this sheet is shown (<selection activeCell=".." sqref="..">, both attributes written the same — this crate only models a single selected cell, not a multi-cell selection). Distinct from Workbook::active_tab: this is the cell selected within this sheet, not which sheet tab is shown. None leaves Excel’s own default (A1).

§default_column_width: Option<f64>

This sheet’s default column width, in Excel’s own character-width units (<sheetFormatPr defaultColWidth="..">). Distinct from ColumnSetting::width: this is the width used for every column without its own explicit ColumnSetting. None leaves Excel’s own default.

§default_row_height: Option<f64>

This sheet’s default row height, in points (<sheetFormatPr defaultRowHeight="..">). Distinct from Row::height: this is the height used for every row without its own explicit height. None leaves Excel’s own default (15, i.e. defaultRowHeight is always written with a concrete value — CT_SheetFormatPr::defaultRowHeight is mandatory whenever <sheetFormatPr> is written at all, unlike every other field on this type).

§row_breaks: Vec<u32>

Manual page breaks after these 1-based row numbers (<rowBreaks>/<brk>, CT_PageBreak).

§column_breaks: Vec<u32>

Manual page breaks after these 1-based column numbers (<colBreaks>/<brk>).

§scenarios: Vec<Scenario>

“What-if” scenarios (<scenarios>/<scenario>, CT_Scenario).

§auto_filter_columns: Vec<AutoFilterColumn>

Per-column filter criteria for auto_filter_range (<filterColumn>/<filters>, CT_FilterColumn/CT_Filters). A no-op if auto_filter_range is None. Only the simplest form (a fixed list of checked/visible values) is modeled — CT_Filters’s custom criteria, top10, and date-grouping filter forms are not.

§ignored_errors: Vec<IgnoredError>

Suppressed error-checking indicators (the little green triangle in a cell’s corner and its “Ignore Error” right-click option), (<ignoredErrors>/<ignoredError>, CT_IgnoredErrors/ CT_IgnoredError). Each entry covers one range and one or more error categories; this crate writes one <ignoredError> element per IgnoredError entry, same “less compact but schema-valid” posture as ColumnSetting/ ConditionalFormattingRule not bothering to merge adjacent/ overlapping ranges the way real Excel’s UI sometimes does.

§protected_ranges: Vec<ProtectedRange>

Multiple named protected ranges (<protectedRanges>/ <protectedRange>, CT_ProtectedRanges/CT_ProtectedRange). Distinct from Sheet::protection (point 13, <sheetProtection>): that locks/unlocks editing for the whole sheet at once (based on each cell’s own locked CellFormat flag), while this is Excel’s older “Allow Users to Edit Ranges” feature — one or more named ranges, each optionally its own password, that stay editable while the rest of a protected sheet is locked. CT_Worksheet’s sequence puts protectedRanges right after sheetProtection, before scenarios (confirmed via sml.xsd).

§sort_state: Option<SortState>

A remembered sort order for auto_filter_range (<autoFilter><sortState>..</sortState></autoFilter>). A no-op if auto_filter_range is None (same posture as auto_filter_columns). CT_AutoFilter’s own sequence puts sortState after filterColumn*, nested inside <autoFilter> — distinct from ExcelTable::sort_state, which is a sibling of a table’s own <autoFilter>, not a child of it (see that field’s doc comment for the schema source).

§outline_summary_below: Option<bool>

Whether an outline/grouping’s summary rows sit below their detail rows, or above (<sheetPr><outlinePr summaryBelow="..">, CT_SheetPr/CT_OutlinePr). Relevant only when Row::outline_level/column grouping is used. None leaves Excel’s own default (true, summary below); Some(false) matches the “summary above” layout common in accounting templates. Confirmed via sml.xsd: outlinePr is CT_SheetPr’s second child, right after tabColor?.

§outline_summary_right: Option<bool>

Whether an outline/grouping’s summary columns sit to the right of their detail columns, or to the left (<outlinePr summaryRight="..">) — same point 55, the column-axis counterpart of outline_summary_below. None leaves Excel’s own default (true, summary to the right).

§drawing: Option<SheetDrawing>

This sheet’s DrawingML drawing — embedded pictures and/or charts, each anchored to a cell range (<drawing r:id=".."> referencing a dedicated xl/drawings/drawingN.xml part, CT_Drawing/xdr:wsDr). Only one drawing part per sheet is modeled (this crate’s own scope choice, not an ECMA-376 limit — real Excel only ever has one anyway), same posture as Sheet::table. None writes no <drawing> element and no drawing part at all.

Implementations§

Source§

impl Sheet

Source

pub fn new(name: impl Into<String>) -> Sheet

Creates an empty sheet (no rows) with the given name.

Examples found in repository?
examples/hello_world_xlsx.rs (line 19)
13fn main() -> office_toolkit::Result<()> {
14    let path = output_path("hello_world.xlsx");
15
16    // `Workbook` and `Row` both come from `office_toolkit::prelude`.
17    // `Row::with_text` puts a single text cell in column A.
18    let workbook = Workbook::new()
19        .with_sheet(Sheet::new("Sheet1").with_row(Row::new().with_text("Hello, world!")));
20    workbook.save_to_file(&path)?;
21    println!("Wrote {}", path.display());
22
23    // Read the file back to confirm it is a valid .xlsx.
24    let reopened = Workbook::open_file(&path)?;
25    let cell_a1 = &reopened.sheets[0].rows[0].cells[0].value;
26    println!("Read back A1: {cell_a1:?}");
27    assert!(matches!(cell_a1, CellValue::Text(text) if text == "Hello, world!"));
28
29    Ok(())
30}
More examples
Hide additional examples
examples/xlsx_images_and_charts.rs (line 26)
21fn main() -> office_toolkit::Result<()> {
22    let path = output_path("xlsx_images_and_charts.xlsx");
23    let image_bytes = std::fs::read(image_fixture_path())?;
24
25    let picture = SheetPicture::new(image_bytes, PictureFormat::Png).with_name("Test image");
26    let picture_sheet = Sheet::new("Picture")
27        .with_row(Row::new().with_text("The picture is anchored to cell A1:"))
28        .with_drawing(SheetDrawing::new().with_anchor(DrawingAnchor::new(
29            CellAnchorPoint::new(0, 1),
30            CellAnchorPoint::new(2, 6),
31            DrawingObject::Picture(Box::new(picture)),
32        )));
33
34    let chart = SheetChart::new(sample_chart_space()).with_name("Quarterly revenue");
35    let chart_sheet = Sheet::new("Chart")
36        .with_row(Row::new().with_text("A bar chart is anchored below:"))
37        .with_drawing(SheetDrawing::new().with_anchor(DrawingAnchor::new(
38            CellAnchorPoint::new(0, 1),
39            CellAnchorPoint::new(6, 16),
40            DrawingObject::Chart(Box::new(chart)),
41        )));
42
43    let workbook = Workbook::new()
44        .with_sheet(picture_sheet)
45        .with_sheet(chart_sheet);
46    workbook.save_to_file(&path)?;
47    println!("Wrote {}", path.display());
48    Ok(())
49}
examples/xlsx_protection.rs (line 19)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("xlsx_protection.xlsx");
18
19    let sheet_protection_sheet = Sheet::new("Sheet protection")
20        .with_row(Row::new().with_text("Locked: this sheet is protected with a password."))
21        .with_protection(SheetProtection::with_password("secret"));
22
23    let protected_range_sheet = Sheet::new("Protected range")
24        .with_row(
25            Row::new()
26                .with_text("A1 is protected; B1 stays editable via a named unprotected range."),
27        )
28        .with_protection(SheetProtection::locked())
29        .with_protected_range(ProtectedRange::new("EditableArea", "B1:B1").with_password("secret"));
30
31    let workbook = Workbook::new()
32        .with_write_protection(
33            WriteProtection::recommended()
34                .with_user_name("Author")
35                .with_password("secret"),
36        )
37        .with_sheet(sheet_protection_sheet)
38        .with_sheet(protected_range_sheet);
39
40    // `Workbook.protection` (structure protection: locking sheet
41    // add/rename/hide/reorder/delete) has no `with_*` builder — it's set
42    // directly, like any other public field.
43    let workbook = Workbook {
44        protection: Some(WorkbookProtection::locked().with_lock_windows(true)),
45        ..workbook
46    };
47
48    workbook.save_to_file(&path)?;
49    println!("Wrote {}", path.display());
50    Ok(())
51}
examples/xlsx_print_and_views.rs (line 17)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
examples/xlsx_structure_and_layout.rs (line 16)
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}
examples/xlsx_workbook_metadata.rs (line 19)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("xlsx_workbook_metadata.xlsx");
18
19    let named_ranges_sheet = Sheet::new("Named ranges")
20        .with_row(Row::new().with_text("Tax rate").with_number(0.0825))
21        .with_row(Row::new().with_cell(Cell::formula("TaxRate*100").with_cached_value(8.25)));
22
23    let calculation_sheet = Sheet::new("Calculation").with_row(
24        Row::new().with_text("Set to manual recalculation with iterative calculation enabled."),
25    );
26
27    let scenarios_sheet = Sheet::new("Scenarios")
28        .with_row(Row::new().with_text("Revenue").with_number(100_000.0))
29        .with_row(Row::new().with_text("Cost").with_number(60_000.0))
30        .with_scenario(
31            Scenario::new("Best case")
32                .with_input("B1", "150000")
33                .with_input("B2", "55000")
34                .with_comment("Optimistic projection"),
35        )
36        .with_scenario(
37            Scenario::new("Worst case")
38                .with_input("B1", "70000")
39                .with_input("B2", "65000"),
40        );
41
42    let auto_filter_sheet = Sheet::new("Autofilter criteria")
43        .with_row(Row::new().with_text("Region"))
44        .with_row(Row::new().with_text("North"))
45        .with_row(Row::new().with_text("South"))
46        .with_auto_filter_range("A1:A3")
47        .with_auto_filter_column(AutoFilterColumn::new(0, vec!["North".to_string()]));
48
49    let ignored_errors_sheet = Sheet::new("Ignored errors")
50        .with_row(Row::new().with_text("123")) // a number stored as text — normally flagged by Excel
51        .with_ignored_error(IgnoredError::new("A1:A1").with_number_stored_as_text(true));
52
53    let workbook = Workbook::new()
54        .with_defined_name(DefinedName::new("TaxRate", "'Named ranges'!$B$1"))
55        .with_calculation(
56            CalculationProperties::new()
57                .with_mode(CalculationMode::Manual)
58                .with_iterate(true),
59        )
60        .with_sheet(named_ranges_sheet)
61        .with_sheet(calculation_sheet)
62        .with_sheet(scenarios_sheet)
63        .with_sheet(auto_filter_sheet)
64        .with_sheet(ignored_errors_sheet);
65
66    // `Workbook.properties` has no `with_*` builder — it's set directly,
67    // like any other public field.
68    let properties = DocumentProperties::new()
69        .with_title("Metadata example")
70        .with_author("Example Author")
71        .with_subject("Workbook-level features")
72        .with_custom_property(
73            "ProjectCode",
74            CustomPropertyValue::Text("XLSX-META".to_string()),
75        );
76    let workbook = Workbook {
77        properties,
78        ..workbook
79    };
80
81    workbook.save_to_file(&path)?;
82    println!("Wrote {}", path.display());
83    Ok(())
84}
Source

pub fn with_row(self, row: Row) -> Sheet

Appends a row and returns the sheet for chaining.

Examples found in repository?
examples/hello_world_xlsx.rs (line 19)
13fn main() -> office_toolkit::Result<()> {
14    let path = output_path("hello_world.xlsx");
15
16    // `Workbook` and `Row` both come from `office_toolkit::prelude`.
17    // `Row::with_text` puts a single text cell in column A.
18    let workbook = Workbook::new()
19        .with_sheet(Sheet::new("Sheet1").with_row(Row::new().with_text("Hello, world!")));
20    workbook.save_to_file(&path)?;
21    println!("Wrote {}", path.display());
22
23    // Read the file back to confirm it is a valid .xlsx.
24    let reopened = Workbook::open_file(&path)?;
25    let cell_a1 = &reopened.sheets[0].rows[0].cells[0].value;
26    println!("Read back A1: {cell_a1:?}");
27    assert!(matches!(cell_a1, CellValue::Text(text) if text == "Hello, world!"));
28
29    Ok(())
30}
More examples
Hide additional examples
examples/xlsx_images_and_charts.rs (line 27)
21fn main() -> office_toolkit::Result<()> {
22    let path = output_path("xlsx_images_and_charts.xlsx");
23    let image_bytes = std::fs::read(image_fixture_path())?;
24
25    let picture = SheetPicture::new(image_bytes, PictureFormat::Png).with_name("Test image");
26    let picture_sheet = Sheet::new("Picture")
27        .with_row(Row::new().with_text("The picture is anchored to cell A1:"))
28        .with_drawing(SheetDrawing::new().with_anchor(DrawingAnchor::new(
29            CellAnchorPoint::new(0, 1),
30            CellAnchorPoint::new(2, 6),
31            DrawingObject::Picture(Box::new(picture)),
32        )));
33
34    let chart = SheetChart::new(sample_chart_space()).with_name("Quarterly revenue");
35    let chart_sheet = Sheet::new("Chart")
36        .with_row(Row::new().with_text("A bar chart is anchored below:"))
37        .with_drawing(SheetDrawing::new().with_anchor(DrawingAnchor::new(
38            CellAnchorPoint::new(0, 1),
39            CellAnchorPoint::new(6, 16),
40            DrawingObject::Chart(Box::new(chart)),
41        )));
42
43    let workbook = Workbook::new()
44        .with_sheet(picture_sheet)
45        .with_sheet(chart_sheet);
46    workbook.save_to_file(&path)?;
47    println!("Wrote {}", path.display());
48    Ok(())
49}
examples/xlsx_protection.rs (line 20)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("xlsx_protection.xlsx");
18
19    let sheet_protection_sheet = Sheet::new("Sheet protection")
20        .with_row(Row::new().with_text("Locked: this sheet is protected with a password."))
21        .with_protection(SheetProtection::with_password("secret"));
22
23    let protected_range_sheet = Sheet::new("Protected range")
24        .with_row(
25            Row::new()
26                .with_text("A1 is protected; B1 stays editable via a named unprotected range."),
27        )
28        .with_protection(SheetProtection::locked())
29        .with_protected_range(ProtectedRange::new("EditableArea", "B1:B1").with_password("secret"));
30
31    let workbook = Workbook::new()
32        .with_write_protection(
33            WriteProtection::recommended()
34                .with_user_name("Author")
35                .with_password("secret"),
36        )
37        .with_sheet(sheet_protection_sheet)
38        .with_sheet(protected_range_sheet);
39
40    // `Workbook.protection` (structure protection: locking sheet
41    // add/rename/hide/reorder/delete) has no `with_*` builder — it's set
42    // directly, like any other public field.
43    let workbook = Workbook {
44        protection: Some(WorkbookProtection::locked().with_lock_windows(true)),
45        ..workbook
46    };
47
48    workbook.save_to_file(&path)?;
49    println!("Wrote {}", path.display());
50    Ok(())
51}
examples/xlsx_print_and_views.rs (line 18)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
examples/xlsx_structure_and_layout.rs (line 17)
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}
examples/xlsx_workbook_metadata.rs (line 20)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("xlsx_workbook_metadata.xlsx");
18
19    let named_ranges_sheet = Sheet::new("Named ranges")
20        .with_row(Row::new().with_text("Tax rate").with_number(0.0825))
21        .with_row(Row::new().with_cell(Cell::formula("TaxRate*100").with_cached_value(8.25)));
22
23    let calculation_sheet = Sheet::new("Calculation").with_row(
24        Row::new().with_text("Set to manual recalculation with iterative calculation enabled."),
25    );
26
27    let scenarios_sheet = Sheet::new("Scenarios")
28        .with_row(Row::new().with_text("Revenue").with_number(100_000.0))
29        .with_row(Row::new().with_text("Cost").with_number(60_000.0))
30        .with_scenario(
31            Scenario::new("Best case")
32                .with_input("B1", "150000")
33                .with_input("B2", "55000")
34                .with_comment("Optimistic projection"),
35        )
36        .with_scenario(
37            Scenario::new("Worst case")
38                .with_input("B1", "70000")
39                .with_input("B2", "65000"),
40        );
41
42    let auto_filter_sheet = Sheet::new("Autofilter criteria")
43        .with_row(Row::new().with_text("Region"))
44        .with_row(Row::new().with_text("North"))
45        .with_row(Row::new().with_text("South"))
46        .with_auto_filter_range("A1:A3")
47        .with_auto_filter_column(AutoFilterColumn::new(0, vec!["North".to_string()]));
48
49    let ignored_errors_sheet = Sheet::new("Ignored errors")
50        .with_row(Row::new().with_text("123")) // a number stored as text — normally flagged by Excel
51        .with_ignored_error(IgnoredError::new("A1:A1").with_number_stored_as_text(true));
52
53    let workbook = Workbook::new()
54        .with_defined_name(DefinedName::new("TaxRate", "'Named ranges'!$B$1"))
55        .with_calculation(
56            CalculationProperties::new()
57                .with_mode(CalculationMode::Manual)
58                .with_iterate(true),
59        )
60        .with_sheet(named_ranges_sheet)
61        .with_sheet(calculation_sheet)
62        .with_sheet(scenarios_sheet)
63        .with_sheet(auto_filter_sheet)
64        .with_sheet(ignored_errors_sheet);
65
66    // `Workbook.properties` has no `with_*` builder — it's set directly,
67    // like any other public field.
68    let properties = DocumentProperties::new()
69        .with_title("Metadata example")
70        .with_author("Example Author")
71        .with_subject("Workbook-level features")
72        .with_custom_property(
73            "ProjectCode",
74            CustomPropertyValue::Text("XLSX-META".to_string()),
75        );
76    let workbook = Workbook {
77        properties,
78        ..workbook
79    };
80
81    workbook.save_to_file(&path)?;
82    println!("Wrote {}", path.display());
83    Ok(())
84}
Source

pub fn write_cell( &mut self, row: u32, col: u32, cell: impl Into<Cell>, ) -> &mut Cell

Writes cell at the given 1-based (row, col) position — (1, 1) is A1 — growing rows and the target row’s own cells with empty padding cells as needed to reach it, and returns a mutable reference to the cell just written. Direct coordinate addressing, for the common case of writing cells out of strict top-to-bottom, left-to-right order (or just one cell at a time in a loop) without assembling a full Row by hand first. 1-based, to match this crate’s own existing convention — a row’s or cell’s position in its Vec plus one (see Sheet::rows’s and Row::cells’s doc comments) — so a Sheet never mixes two different numbering schemes depending on which method touched it.

Padding cells are genuinely empty (Cell::new/Cell::default), not written out as <c> elements at all unless later given a format — same posture as a sparse Row built by hand.

Accepts anything convertible to a Cell — a Cell itself (built via Cell::text/Cell::formula/Cell::date/etc. for the cases below that need one made explicitly), or, for the three unambiguous cases, the raw value directly: &str/String (→ CellValue::Text), f64 (→ CellValue::Number), bool (→ CellValue::Boolean) — the common case a caller writing cells one at a time reaches for most often. Formulas, dates, rich text, and array formulas are deliberately not covered by an automatic conversion — there’s no unambiguous way to tell “this is a formula” from a plain string, or “this number is a date” from a plain number, so those still go through their own Cell::* constructor.

§Panics

Panics if row or col is 0 (1-based, so 0 is never a valid position).

Source

pub fn with_conditional_formatting_rule( self, rule: ConditionalFormattingRule, ) -> Sheet

Appends a conditional formatting rule and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_conditional_formatting_and_validation.rs (lines 24-31)
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}
Source

pub fn with_data_validation_rule(self, rule: DataValidationRule) -> Sheet

Appends a data validation rule and returns the sheet for chaining.

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

pub fn with_merged_range(self, range: impl Into<String>) -> Sheet

Appends a merged cell range (e.g. "A1:C1") and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_structure_and_layout.rs (line 18)
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_column_setting(self, setting: ColumnSetting) -> Sheet

Appends a column setting and returns the sheet 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_auto_filter_range(self, range: impl Into<String>) -> Sheet

Sets the autofilter range and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_workbook_metadata.rs (line 46)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("xlsx_workbook_metadata.xlsx");
18
19    let named_ranges_sheet = Sheet::new("Named ranges")
20        .with_row(Row::new().with_text("Tax rate").with_number(0.0825))
21        .with_row(Row::new().with_cell(Cell::formula("TaxRate*100").with_cached_value(8.25)));
22
23    let calculation_sheet = Sheet::new("Calculation").with_row(
24        Row::new().with_text("Set to manual recalculation with iterative calculation enabled."),
25    );
26
27    let scenarios_sheet = Sheet::new("Scenarios")
28        .with_row(Row::new().with_text("Revenue").with_number(100_000.0))
29        .with_row(Row::new().with_text("Cost").with_number(60_000.0))
30        .with_scenario(
31            Scenario::new("Best case")
32                .with_input("B1", "150000")
33                .with_input("B2", "55000")
34                .with_comment("Optimistic projection"),
35        )
36        .with_scenario(
37            Scenario::new("Worst case")
38                .with_input("B1", "70000")
39                .with_input("B2", "65000"),
40        );
41
42    let auto_filter_sheet = Sheet::new("Autofilter criteria")
43        .with_row(Row::new().with_text("Region"))
44        .with_row(Row::new().with_text("North"))
45        .with_row(Row::new().with_text("South"))
46        .with_auto_filter_range("A1:A3")
47        .with_auto_filter_column(AutoFilterColumn::new(0, vec!["North".to_string()]));
48
49    let ignored_errors_sheet = Sheet::new("Ignored errors")
50        .with_row(Row::new().with_text("123")) // a number stored as text — normally flagged by Excel
51        .with_ignored_error(IgnoredError::new("A1:A1").with_number_stored_as_text(true));
52
53    let workbook = Workbook::new()
54        .with_defined_name(DefinedName::new("TaxRate", "'Named ranges'!$B$1"))
55        .with_calculation(
56            CalculationProperties::new()
57                .with_mode(CalculationMode::Manual)
58                .with_iterate(true),
59        )
60        .with_sheet(named_ranges_sheet)
61        .with_sheet(calculation_sheet)
62        .with_sheet(scenarios_sheet)
63        .with_sheet(auto_filter_sheet)
64        .with_sheet(ignored_errors_sheet);
65
66    // `Workbook.properties` has no `with_*` builder — it's set directly,
67    // like any other public field.
68    let properties = DocumentProperties::new()
69        .with_title("Metadata example")
70        .with_author("Example Author")
71        .with_subject("Workbook-level features")
72        .with_custom_property(
73            "ProjectCode",
74            CustomPropertyValue::Text("XLSX-META".to_string()),
75        );
76    let workbook = Workbook {
77        properties,
78        ..workbook
79    };
80
81    workbook.save_to_file(&path)?;
82    println!("Wrote {}", path.display());
83    Ok(())
84}
Source

pub fn with_freeze_panes(self, freeze_panes: FreezePane) -> Sheet

Sets frozen panes and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_structure_and_layout.rs (line 56)
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_print_settings(self, print_settings: PrintSettings) -> Sheet

Sets this sheet’s print settings and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_print_and_views.rs (lines 20-30)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
Source

pub fn with_protection(self, protection: SheetProtection) -> Sheet

Sets this sheet’s protection and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_protection.rs (line 21)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("xlsx_protection.xlsx");
18
19    let sheet_protection_sheet = Sheet::new("Sheet protection")
20        .with_row(Row::new().with_text("Locked: this sheet is protected with a password."))
21        .with_protection(SheetProtection::with_password("secret"));
22
23    let protected_range_sheet = Sheet::new("Protected range")
24        .with_row(
25            Row::new()
26                .with_text("A1 is protected; B1 stays editable via a named unprotected range."),
27        )
28        .with_protection(SheetProtection::locked())
29        .with_protected_range(ProtectedRange::new("EditableArea", "B1:B1").with_password("secret"));
30
31    let workbook = Workbook::new()
32        .with_write_protection(
33            WriteProtection::recommended()
34                .with_user_name("Author")
35                .with_password("secret"),
36        )
37        .with_sheet(sheet_protection_sheet)
38        .with_sheet(protected_range_sheet);
39
40    // `Workbook.protection` (structure protection: locking sheet
41    // add/rename/hide/reorder/delete) has no `with_*` builder — it's set
42    // directly, like any other public field.
43    let workbook = Workbook {
44        protection: Some(WorkbookProtection::locked().with_lock_windows(true)),
45        ..workbook
46    };
47
48    workbook.save_to_file(&path)?;
49    println!("Wrote {}", path.display());
50    Ok(())
51}

Appends a cell hyperlink and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_rich_data.rs (lines 70-73)
13fn main() -> office_toolkit::Result<()> {
14    let path = output_path("xlsx_rich_data.xlsx");
15
16    let dates_and_booleans_sheet = Sheet::new("Dates and booleans")
17        .with_row(Row::new().with_cell(Cell::date(ExcelDateTime::date(2026, 7, 21))))
18        .with_row(Row::new().with_cell(Cell::date(
19            ExcelDateTime::date(2026, 7, 21).with_time(14, 30, 0),
20        )))
21        .with_row(
22            Row::new()
23                .with_cell(Cell::boolean(true))
24                .with_cell(Cell::boolean(false)),
25        );
26
27    // An array/shared formula's `ref` must be a range whose top-left cell
28    // is the cell the `<f t="array"|"shared">` element actually sits in —
29    // `with_cell` fills a row left-to-right starting at column A, so each
30    // formula cell below is positioned to land exactly on its own `ref`'s
31    // first cell, with plain cached-value cells (no `<f>`) filling out the
32    // rest of the declared range, matching how Excel itself writes a
33    // multi-cell array/shared formula. The previous version declared
34    // ranges like "D1:D3"/"E1:E3" while the formula cells actually landed
35    // in column A — a real cell/range mismatch Excel refuses to open
36    // without repairing.
37    let formulas_sheet = Sheet::new("Formulas")
38        .with_row(
39            Row::new()
40                .with_cell(Cell::number(10.0))
41                .with_cell(Cell::number(20.0))
42                .with_cell(Cell::formula("A1+B1").with_cached_value(30.0)),
43        )
44        .with_row(
45            Row::new()
46                .with_cell(Cell::array_formula("A1:A3*2", "A2:C2").with_cached_value(20.0))
47                .with_cell(Cell::number(40.0))
48                .with_cell(Cell::number(60.0)),
49        )
50        .with_row(
51            Row::new()
52                .with_cell(Cell::shared_formula("A1+1", 0, "A3:C3").with_cached_value(11.0))
53                .with_cell(Cell::shared_formula_follower(0).with_cached_value(21.0))
54                .with_cell(Cell::shared_formula_follower(0).with_cached_value(31.0)),
55        );
56
57    let rich_text_sheet =
58        Sheet::new("Rich text").with_row(Row::new().with_cell(Cell::rich_text(vec![
59        RichTextRun::new("Bold red, ").with_bold(true).with_font_color("FFC00000"),
60        RichTextRun::new("then italic blue.").with_italic(true).with_font_color("FF2E74B5"),
61    ])));
62
63    let hyperlinks_sheet = Sheet::new("Hyperlinks")
64        .with_row(
65            Row::new()
66                .with_text("Visit Rust")
67                .with_text("Jump to C1")
68                .with_text("You've arrived"),
69        )
70        .with_hyperlink(
71            CellHyperlink::external("A1", "https://www.rust-lang.org")
72                .with_tooltip("Opens in your browser"),
73        )
74        .with_hyperlink(CellHyperlink::internal("B1", "'Hyperlinks'!C1"));
75
76    let comments_sheet = Sheet::new("Comments")
77        .with_row(
78            Row::new()
79                .with_text("Hover B1 for a comment")
80                .with_text("Reviewed"),
81        )
82        .with_comment(CellComment::new(
83            "A1",
84            "Reviewer",
85            "Double-check this figure before publishing.",
86        ))
87        .with_comment(
88            CellComment::new("B1", "Reviewer", "Looks correct.")
89                .with_rich_text(vec![RichTextRun::new("Looks correct.").with_bold(true)]),
90        );
91
92    let workbook = Workbook::new()
93        .with_sheet(dates_and_booleans_sheet)
94        .with_sheet(formulas_sheet)
95        .with_sheet(rich_text_sheet)
96        .with_sheet(hyperlinks_sheet)
97        .with_sheet(comments_sheet);
98
99    workbook.save_to_file(&path)?;
100    println!("Wrote {}", path.display());
101    Ok(())
102}
Source

pub fn with_comment(self, comment: CellComment) -> Sheet

Appends a cell comment and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_rich_data.rs (lines 82-86)
13fn main() -> office_toolkit::Result<()> {
14    let path = output_path("xlsx_rich_data.xlsx");
15
16    let dates_and_booleans_sheet = Sheet::new("Dates and booleans")
17        .with_row(Row::new().with_cell(Cell::date(ExcelDateTime::date(2026, 7, 21))))
18        .with_row(Row::new().with_cell(Cell::date(
19            ExcelDateTime::date(2026, 7, 21).with_time(14, 30, 0),
20        )))
21        .with_row(
22            Row::new()
23                .with_cell(Cell::boolean(true))
24                .with_cell(Cell::boolean(false)),
25        );
26
27    // An array/shared formula's `ref` must be a range whose top-left cell
28    // is the cell the `<f t="array"|"shared">` element actually sits in —
29    // `with_cell` fills a row left-to-right starting at column A, so each
30    // formula cell below is positioned to land exactly on its own `ref`'s
31    // first cell, with plain cached-value cells (no `<f>`) filling out the
32    // rest of the declared range, matching how Excel itself writes a
33    // multi-cell array/shared formula. The previous version declared
34    // ranges like "D1:D3"/"E1:E3" while the formula cells actually landed
35    // in column A — a real cell/range mismatch Excel refuses to open
36    // without repairing.
37    let formulas_sheet = Sheet::new("Formulas")
38        .with_row(
39            Row::new()
40                .with_cell(Cell::number(10.0))
41                .with_cell(Cell::number(20.0))
42                .with_cell(Cell::formula("A1+B1").with_cached_value(30.0)),
43        )
44        .with_row(
45            Row::new()
46                .with_cell(Cell::array_formula("A1:A3*2", "A2:C2").with_cached_value(20.0))
47                .with_cell(Cell::number(40.0))
48                .with_cell(Cell::number(60.0)),
49        )
50        .with_row(
51            Row::new()
52                .with_cell(Cell::shared_formula("A1+1", 0, "A3:C3").with_cached_value(11.0))
53                .with_cell(Cell::shared_formula_follower(0).with_cached_value(21.0))
54                .with_cell(Cell::shared_formula_follower(0).with_cached_value(31.0)),
55        );
56
57    let rich_text_sheet =
58        Sheet::new("Rich text").with_row(Row::new().with_cell(Cell::rich_text(vec![
59        RichTextRun::new("Bold red, ").with_bold(true).with_font_color("FFC00000"),
60        RichTextRun::new("then italic blue.").with_italic(true).with_font_color("FF2E74B5"),
61    ])));
62
63    let hyperlinks_sheet = Sheet::new("Hyperlinks")
64        .with_row(
65            Row::new()
66                .with_text("Visit Rust")
67                .with_text("Jump to C1")
68                .with_text("You've arrived"),
69        )
70        .with_hyperlink(
71            CellHyperlink::external("A1", "https://www.rust-lang.org")
72                .with_tooltip("Opens in your browser"),
73        )
74        .with_hyperlink(CellHyperlink::internal("B1", "'Hyperlinks'!C1"));
75
76    let comments_sheet = Sheet::new("Comments")
77        .with_row(
78            Row::new()
79                .with_text("Hover B1 for a comment")
80                .with_text("Reviewed"),
81        )
82        .with_comment(CellComment::new(
83            "A1",
84            "Reviewer",
85            "Double-check this figure before publishing.",
86        ))
87        .with_comment(
88            CellComment::new("B1", "Reviewer", "Looks correct.")
89                .with_rich_text(vec![RichTextRun::new("Looks correct.").with_bold(true)]),
90        );
91
92    let workbook = Workbook::new()
93        .with_sheet(dates_and_booleans_sheet)
94        .with_sheet(formulas_sheet)
95        .with_sheet(rich_text_sheet)
96        .with_sheet(hyperlinks_sheet)
97        .with_sheet(comments_sheet);
98
99    workbook.save_to_file(&path)?;
100    println!("Wrote {}", path.display());
101    Ok(())
102}
Source

pub fn with_table(self, table: ExcelTable) -> Sheet

Sets this sheet’s structured table and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_tables.rs (lines 23-27)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("xlsx_tables.xlsx");
18
19    let plain_sheet = Sheet::new("Plain table")
20        .with_row(Row::new().with_text("Name").with_text("Score"))
21        .with_row(Row::new().with_text("Alice").with_number(92.0))
22        .with_row(Row::new().with_text("Bob").with_number(87.0))
23        .with_table(ExcelTable::new(
24            "ScoresTable",
25            "A1:B3",
26            vec!["Name", "Score"],
27        ));
28
29    let calculated_sheet = Sheet::new("Calculated and totals")
30        .with_row(
31            Row::new()
32                .with_text("Item")
33                .with_text("Qty")
34                .with_text("Unit price")
35                .with_text("Line total"),
36        )
37        .with_row(
38            Row::new()
39                .with_text("Widget")
40                .with_number(3.0)
41                .with_number(9.99)
42                .with_cell(Cell::formula("B2*C2").with_cached_value(29.97)),
43        )
44        .with_row(
45            Row::new()
46                .with_text("Gadget")
47                .with_number(2.0)
48                .with_number(19.99)
49                .with_cell(Cell::formula("B3*C3").with_cached_value(39.98)),
50        )
51        .with_row(Row::new().with_cell(Cell::text("Total")))
52        .with_table(
53            ExcelTable::with_columns(
54                "OrdersTable",
55                "A1:D4",
56                vec![
57                    TableColumn::new("Item"),
58                    TableColumn::new("Qty").with_totals_row_function(TotalsRowFunction::Sum),
59                    TableColumn::new("Unit price"),
60                    TableColumn::new("Line total")
61                        .with_calculated_formula(
62                            "OrdersTable[[#This Row],[Qty]]*OrdersTable[[#This Row],[Unit price]]",
63                        )
64                        .with_totals_row_function(TotalsRowFunction::Sum),
65                ],
66            )
67            .with_totals_row(true),
68        );
69
70    let styled_sheet = Sheet::new("Custom style and sort")
71        .with_row(Row::new().with_text("City").with_text("Population"))
72        .with_row(Row::new().with_text("Springfield").with_number(120_000.0))
73        .with_row(Row::new().with_text("Shelbyville").with_number(95_000.0))
74        .with_table(
75            ExcelTable::new("CitiesTable", "A1:B3", vec!["City", "Population"])
76                .with_table_style_name("CustomTableStyle")
77                .with_sort_state(
78                    SortState::new("A2:B3")
79                        .with_condition(SortCondition::new("B2:B3").with_descending(true)),
80                ),
81        );
82
83    let workbook = Workbook::new()
84        .with_table_style(
85            TableStyle::new("CustomTableStyle")
86                .with_element(TableStyleElement::new(
87                    TableStyleElementType::HeaderRow,
88                    CellFormat::new()
89                        .with_bold(true)
90                        .with_fill_color("FF2E74B5")
91                        .with_font_color("FFFFFFFF"),
92                ))
93                .with_element(TableStyleElement::new(
94                    TableStyleElementType::FirstRowStripe,
95                    CellFormat::new().with_fill_color("FFF2F2F2"),
96                )),
97        )
98        .with_sheet(plain_sheet)
99        .with_sheet(calculated_sheet)
100        .with_sheet(styled_sheet);
101
102    workbook.save_to_file(&path)?;
103    println!("Wrote {}", path.display());
104    Ok(())
105}
Source

pub fn with_drawing(self, drawing: SheetDrawing) -> Sheet

Sets this sheet’s drawing (embedded pictures/charts) and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_images_and_charts.rs (lines 28-32)
21fn main() -> office_toolkit::Result<()> {
22    let path = output_path("xlsx_images_and_charts.xlsx");
23    let image_bytes = std::fs::read(image_fixture_path())?;
24
25    let picture = SheetPicture::new(image_bytes, PictureFormat::Png).with_name("Test image");
26    let picture_sheet = Sheet::new("Picture")
27        .with_row(Row::new().with_text("The picture is anchored to cell A1:"))
28        .with_drawing(SheetDrawing::new().with_anchor(DrawingAnchor::new(
29            CellAnchorPoint::new(0, 1),
30            CellAnchorPoint::new(2, 6),
31            DrawingObject::Picture(Box::new(picture)),
32        )));
33
34    let chart = SheetChart::new(sample_chart_space()).with_name("Quarterly revenue");
35    let chart_sheet = Sheet::new("Chart")
36        .with_row(Row::new().with_text("A bar chart is anchored below:"))
37        .with_drawing(SheetDrawing::new().with_anchor(DrawingAnchor::new(
38            CellAnchorPoint::new(0, 1),
39            CellAnchorPoint::new(6, 16),
40            DrawingObject::Chart(Box::new(chart)),
41        )));
42
43    let workbook = Workbook::new()
44        .with_sheet(picture_sheet)
45        .with_sheet(chart_sheet);
46    workbook.save_to_file(&path)?;
47    println!("Wrote {}", path.display());
48    Ok(())
49}
Source

pub fn with_visibility(self, visibility: SheetVisibility) -> Sheet

Sets this sheet’s tab visibility and returns the sheet for chaining — replacing the old with_hidden(bool) (removed, pre-1.0 breaking change): use with_visibility(SheetVisibility::Hidden) for what used to be with_hidden(true).

Examples found in repository?
examples/xlsx_print_and_views.rs (line 46)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
Source

pub fn with_zoom_scale(self, zoom_scale: u32) -> Sheet

Sets this sheet’s display zoom percentage and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_print_and_views.rs (line 34)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
Source

pub fn with_tab_color(self, color: impl Into<String>) -> Sheet

Sets this sheet’s tab color (8-hex-digit ARGB) and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_print_and_views.rs (line 35)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
Source

pub fn with_show_grid_lines(self, show: bool) -> Sheet

Sets whether this sheet’s view shows gridlines and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_print_and_views.rs (line 36)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
Source

pub fn with_show_row_col_headers(self, show: bool) -> Sheet

Sets whether this sheet’s view shows row/column headers and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_print_and_views.rs (line 37)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
Source

pub fn with_show_zeros(self, show: bool) -> Sheet

Sets whether this sheet’s view shows zero values and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_print_and_views.rs (line 38)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
Source

pub fn with_right_to_left(self, right_to_left: bool) -> Sheet

Sets whether this sheet’s view is laid out right-to-left and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_print_and_views.rs (line 39)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
Source

pub fn with_active_cell(self, cell: impl Into<String>) -> Sheet

Sets the cell selected/active when this sheet is shown (e.g. "B3") and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_print_and_views.rs (line 40)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
Source

pub fn with_default_column_width(self, width: f64) -> Sheet

Sets this sheet’s default column width and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_print_and_views.rs (line 41)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
Source

pub fn with_default_row_height(self, height: f64) -> Sheet

Sets this sheet’s default row height and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_print_and_views.rs (line 42)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
Source

pub fn with_row_break(self, row: u32) -> Sheet

Adds a manual page break after the given 1-based row number and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_structure_and_layout.rs (line 61)
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_column_break(self, column: u32) -> Sheet

Adds a manual page break after the given 1-based column number and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_structure_and_layout.rs (line 62)
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_scenario(self, scenario: Scenario) -> Sheet

Appends a “what-if” scenario and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_workbook_metadata.rs (lines 30-35)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("xlsx_workbook_metadata.xlsx");
18
19    let named_ranges_sheet = Sheet::new("Named ranges")
20        .with_row(Row::new().with_text("Tax rate").with_number(0.0825))
21        .with_row(Row::new().with_cell(Cell::formula("TaxRate*100").with_cached_value(8.25)));
22
23    let calculation_sheet = Sheet::new("Calculation").with_row(
24        Row::new().with_text("Set to manual recalculation with iterative calculation enabled."),
25    );
26
27    let scenarios_sheet = Sheet::new("Scenarios")
28        .with_row(Row::new().with_text("Revenue").with_number(100_000.0))
29        .with_row(Row::new().with_text("Cost").with_number(60_000.0))
30        .with_scenario(
31            Scenario::new("Best case")
32                .with_input("B1", "150000")
33                .with_input("B2", "55000")
34                .with_comment("Optimistic projection"),
35        )
36        .with_scenario(
37            Scenario::new("Worst case")
38                .with_input("B1", "70000")
39                .with_input("B2", "65000"),
40        );
41
42    let auto_filter_sheet = Sheet::new("Autofilter criteria")
43        .with_row(Row::new().with_text("Region"))
44        .with_row(Row::new().with_text("North"))
45        .with_row(Row::new().with_text("South"))
46        .with_auto_filter_range("A1:A3")
47        .with_auto_filter_column(AutoFilterColumn::new(0, vec!["North".to_string()]));
48
49    let ignored_errors_sheet = Sheet::new("Ignored errors")
50        .with_row(Row::new().with_text("123")) // a number stored as text — normally flagged by Excel
51        .with_ignored_error(IgnoredError::new("A1:A1").with_number_stored_as_text(true));
52
53    let workbook = Workbook::new()
54        .with_defined_name(DefinedName::new("TaxRate", "'Named ranges'!$B$1"))
55        .with_calculation(
56            CalculationProperties::new()
57                .with_mode(CalculationMode::Manual)
58                .with_iterate(true),
59        )
60        .with_sheet(named_ranges_sheet)
61        .with_sheet(calculation_sheet)
62        .with_sheet(scenarios_sheet)
63        .with_sheet(auto_filter_sheet)
64        .with_sheet(ignored_errors_sheet);
65
66    // `Workbook.properties` has no `with_*` builder — it's set directly,
67    // like any other public field.
68    let properties = DocumentProperties::new()
69        .with_title("Metadata example")
70        .with_author("Example Author")
71        .with_subject("Workbook-level features")
72        .with_custom_property(
73            "ProjectCode",
74            CustomPropertyValue::Text("XLSX-META".to_string()),
75        );
76    let workbook = Workbook {
77        properties,
78        ..workbook
79    };
80
81    workbook.save_to_file(&path)?;
82    println!("Wrote {}", path.display());
83    Ok(())
84}
Source

pub fn with_auto_filter_column(self, column: AutoFilterColumn) -> Sheet

Appends an autofilter column’s criteria and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_workbook_metadata.rs (line 47)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("xlsx_workbook_metadata.xlsx");
18
19    let named_ranges_sheet = Sheet::new("Named ranges")
20        .with_row(Row::new().with_text("Tax rate").with_number(0.0825))
21        .with_row(Row::new().with_cell(Cell::formula("TaxRate*100").with_cached_value(8.25)));
22
23    let calculation_sheet = Sheet::new("Calculation").with_row(
24        Row::new().with_text("Set to manual recalculation with iterative calculation enabled."),
25    );
26
27    let scenarios_sheet = Sheet::new("Scenarios")
28        .with_row(Row::new().with_text("Revenue").with_number(100_000.0))
29        .with_row(Row::new().with_text("Cost").with_number(60_000.0))
30        .with_scenario(
31            Scenario::new("Best case")
32                .with_input("B1", "150000")
33                .with_input("B2", "55000")
34                .with_comment("Optimistic projection"),
35        )
36        .with_scenario(
37            Scenario::new("Worst case")
38                .with_input("B1", "70000")
39                .with_input("B2", "65000"),
40        );
41
42    let auto_filter_sheet = Sheet::new("Autofilter criteria")
43        .with_row(Row::new().with_text("Region"))
44        .with_row(Row::new().with_text("North"))
45        .with_row(Row::new().with_text("South"))
46        .with_auto_filter_range("A1:A3")
47        .with_auto_filter_column(AutoFilterColumn::new(0, vec!["North".to_string()]));
48
49    let ignored_errors_sheet = Sheet::new("Ignored errors")
50        .with_row(Row::new().with_text("123")) // a number stored as text — normally flagged by Excel
51        .with_ignored_error(IgnoredError::new("A1:A1").with_number_stored_as_text(true));
52
53    let workbook = Workbook::new()
54        .with_defined_name(DefinedName::new("TaxRate", "'Named ranges'!$B$1"))
55        .with_calculation(
56            CalculationProperties::new()
57                .with_mode(CalculationMode::Manual)
58                .with_iterate(true),
59        )
60        .with_sheet(named_ranges_sheet)
61        .with_sheet(calculation_sheet)
62        .with_sheet(scenarios_sheet)
63        .with_sheet(auto_filter_sheet)
64        .with_sheet(ignored_errors_sheet);
65
66    // `Workbook.properties` has no `with_*` builder — it's set directly,
67    // like any other public field.
68    let properties = DocumentProperties::new()
69        .with_title("Metadata example")
70        .with_author("Example Author")
71        .with_subject("Workbook-level features")
72        .with_custom_property(
73            "ProjectCode",
74            CustomPropertyValue::Text("XLSX-META".to_string()),
75        );
76    let workbook = Workbook {
77        properties,
78        ..workbook
79    };
80
81    workbook.save_to_file(&path)?;
82    println!("Wrote {}", path.display());
83    Ok(())
84}
Source

pub fn with_ignored_error(self, ignored_error: IgnoredError) -> Sheet

Appends a suppressed error-checking entry and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_workbook_metadata.rs (line 51)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("xlsx_workbook_metadata.xlsx");
18
19    let named_ranges_sheet = Sheet::new("Named ranges")
20        .with_row(Row::new().with_text("Tax rate").with_number(0.0825))
21        .with_row(Row::new().with_cell(Cell::formula("TaxRate*100").with_cached_value(8.25)));
22
23    let calculation_sheet = Sheet::new("Calculation").with_row(
24        Row::new().with_text("Set to manual recalculation with iterative calculation enabled."),
25    );
26
27    let scenarios_sheet = Sheet::new("Scenarios")
28        .with_row(Row::new().with_text("Revenue").with_number(100_000.0))
29        .with_row(Row::new().with_text("Cost").with_number(60_000.0))
30        .with_scenario(
31            Scenario::new("Best case")
32                .with_input("B1", "150000")
33                .with_input("B2", "55000")
34                .with_comment("Optimistic projection"),
35        )
36        .with_scenario(
37            Scenario::new("Worst case")
38                .with_input("B1", "70000")
39                .with_input("B2", "65000"),
40        );
41
42    let auto_filter_sheet = Sheet::new("Autofilter criteria")
43        .with_row(Row::new().with_text("Region"))
44        .with_row(Row::new().with_text("North"))
45        .with_row(Row::new().with_text("South"))
46        .with_auto_filter_range("A1:A3")
47        .with_auto_filter_column(AutoFilterColumn::new(0, vec!["North".to_string()]));
48
49    let ignored_errors_sheet = Sheet::new("Ignored errors")
50        .with_row(Row::new().with_text("123")) // a number stored as text — normally flagged by Excel
51        .with_ignored_error(IgnoredError::new("A1:A1").with_number_stored_as_text(true));
52
53    let workbook = Workbook::new()
54        .with_defined_name(DefinedName::new("TaxRate", "'Named ranges'!$B$1"))
55        .with_calculation(
56            CalculationProperties::new()
57                .with_mode(CalculationMode::Manual)
58                .with_iterate(true),
59        )
60        .with_sheet(named_ranges_sheet)
61        .with_sheet(calculation_sheet)
62        .with_sheet(scenarios_sheet)
63        .with_sheet(auto_filter_sheet)
64        .with_sheet(ignored_errors_sheet);
65
66    // `Workbook.properties` has no `with_*` builder — it's set directly,
67    // like any other public field.
68    let properties = DocumentProperties::new()
69        .with_title("Metadata example")
70        .with_author("Example Author")
71        .with_subject("Workbook-level features")
72        .with_custom_property(
73            "ProjectCode",
74            CustomPropertyValue::Text("XLSX-META".to_string()),
75        );
76    let workbook = Workbook {
77        properties,
78        ..workbook
79    };
80
81    workbook.save_to_file(&path)?;
82    println!("Wrote {}", path.display());
83    Ok(())
84}
Source

pub fn with_protected_range(self, protected_range: ProtectedRange) -> Sheet

Appends a named protected range and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_protection.rs (line 29)
16fn main() -> office_toolkit::Result<()> {
17    let path = output_path("xlsx_protection.xlsx");
18
19    let sheet_protection_sheet = Sheet::new("Sheet protection")
20        .with_row(Row::new().with_text("Locked: this sheet is protected with a password."))
21        .with_protection(SheetProtection::with_password("secret"));
22
23    let protected_range_sheet = Sheet::new("Protected range")
24        .with_row(
25            Row::new()
26                .with_text("A1 is protected; B1 stays editable via a named unprotected range."),
27        )
28        .with_protection(SheetProtection::locked())
29        .with_protected_range(ProtectedRange::new("EditableArea", "B1:B1").with_password("secret"));
30
31    let workbook = Workbook::new()
32        .with_write_protection(
33            WriteProtection::recommended()
34                .with_user_name("Author")
35                .with_password("secret"),
36        )
37        .with_sheet(sheet_protection_sheet)
38        .with_sheet(protected_range_sheet);
39
40    // `Workbook.protection` (structure protection: locking sheet
41    // add/rename/hide/reorder/delete) has no `with_*` builder — it's set
42    // directly, like any other public field.
43    let workbook = Workbook {
44        protection: Some(WorkbookProtection::locked().with_lock_windows(true)),
45        ..workbook
46    };
47
48    workbook.save_to_file(&path)?;
49    println!("Wrote {}", path.display());
50    Ok(())
51}
Source

pub fn with_sort_state(self, sort_state: SortState) -> Sheet

Sets this sheet’s (worksheet-level <autoFilter>) remembered sort order and returns the sheet for chaining. See Sheet::sort_state’s doc comment: a no-op unless with_auto_filter_range is also used.

Source

pub fn with_outline_summary_below(self, summary_below: bool) -> Sheet

Sets whether outline/grouping summary rows sit below (true) or above (false) their detail rows, and returns the sheet for chaining.

Examples found in repository?
examples/xlsx_structure_and_layout.rs (line 63)
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_summary_right(self, summary_right: bool) -> Sheet

Sets whether outline/grouping summary columns sit to the right (true) or left (false) of their detail columns, and returns the sheet for chaining — point 55, the column-axis counterpart of with_outline_summary_below.

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

Source§

fn clone(&self) -> Sheet

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 Sheet

Source§

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

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

impl Default for Sheet

Source§

fn default() -> Sheet

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Sheet

Source§

fn eq(&self, other: &Sheet) -> 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 Sheet

Auto Trait Implementations§

§

impl Freeze for Sheet

§

impl RefUnwindSafe for Sheet

§

impl Send for Sheet

§

impl Sync for Sheet

§

impl Unpin for Sheet

§

impl UnsafeUnpin for Sheet

§

impl UnwindSafe for Sheet

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.