Skip to main content

Row

Struct Row 

Source
pub struct Row {
    pub cells: Vec<Cell>,
    pub height: Option<f64>,
    pub hidden: bool,
    pub outline_level: u8,
    pub collapsed: bool,
    pub default_format: Option<CellFormat>,
}
Expand description

A single row of cells (<row>, CT_Row).

Fields§

§cells: Vec<Cell>

The cells that make up this row, in column order starting at column A. Like Sheet.rows, a cell’s column letter is derived from its position in this Vec, not stored separately — writing a row always produces a dense A, B, C. sequence with no gaps. Reading back a sparse row from a real .xlsx (Excel itself never writes a <c> element for a genuinely empty cell) still works: any skipped column is filled in as CellValue::Empty so a cell’s index in this Vec always matches its real column, see reader.rs.

§height: Option<f64>

This row’s explicit height, in points (<row ht=".." customHeight="1">) — None uses Excel’s own default row height.

§hidden: bool

Whether this row is hidden (<row hidden="1">).

§outline_level: u8

This row’s outline (grouping) level (<row outlineLevel="..">, 0-7).

§collapsed: bool

Whether this row’s outline group is shown collapsed (<row collapsed="1">, the “-” summary-only state of the little outline button). Distinct from outline_level itself (which rows belong to the group) — this is only the group’s current expanded/collapsed display state.

§default_format: Option<CellFormat>

This row’s default cell format (<row s="n" customFormat="1">, an index into xl/styles.xml’s cellXfs). Same “applies to any cell without its own explicit format, storage only, caller keeps things straight” posture as ColumnSetting::style — see its doc comment for the precedence note. CT_Row’s customFormat flag is always written together with s when this is Some (confirmed via sml.xsd: s alone with customFormat left at its false default means the row number’s own displayed style, not every cell in the row — real Excel always pairs the two when a row-level format is actually set through its UI).

Implementations§

Source§

impl Row

Source

pub fn new() -> Row

Creates an empty row (no cells).

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 with_cell(self, cell: Cell) -> Row

Appends a cell and returns the row for chaining.

Examples found in repository?
examples/xlsx_structure_and_layout.rs (line 23)
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}
More examples
Hide additional examples
examples/xlsx_workbook_metadata.rs (line 21)
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}
examples/xlsx_tables.rs (line 42)
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}
examples/xlsx_rich_data.rs (line 17)
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}
examples/xlsx_cell_formatting.rs (lines 21-23)
15fn main() -> office_toolkit::Result<()> {
16    let path = output_path("xlsx_cell_formatting.xlsx");
17
18    let borders_sheet =
19        Sheet::new("Borders").with_row(
20            Row::new()
21                .with_cell(Cell::text("Thin all around").with_format(
22                    CellFormat::new().with_border(Border::all(BorderStyle::Thin, "FF000000")),
23                ))
24                .with_cell(Cell::text("Thick bottom only").with_format(
25                    CellFormat::new().with_border(
26                        Border::new().with_bottom(
27                            BorderEdge::new(BorderStyle::Thick).with_color("FFC00000"),
28                        ),
29                    ),
30                )),
31        );
32
33    let fills_sheet = Sheet::new("Fills")
34        .with_row(Row::new().with_cell(
35            Cell::text("Solid fill").with_format(CellFormat::new().with_fill_color("FFFFF2CC")),
36        ))
37        .with_row(
38            Row::new().with_cell(
39                Cell::text("Pattern fill").with_format(
40                    CellFormat::new().with_pattern_fill(
41                        PatternFill::new(PatternType::LightGray)
42                            .with_fg_color("FF4472C4")
43                            .with_bg_color("FFFFFFFF"),
44                    ),
45                ),
46            ),
47        )
48        .with_row(
49            Row::new().with_cell(Cell::text("Gradient fill").with_format(
50                CellFormat::new().with_gradient_fill(GradientFill::new(
51                    90.0,
52                    vec![
53                        GradientStop::new(0.0, "FFFFFFFF"),
54                        GradientStop::new(1.0, "FF4472C4"),
55                    ],
56                )),
57            )),
58        );
59
60    let fonts_and_alignment_sheet =
61        Sheet::new("Fonts and alignment")
62            .with_row(
63                Row::new().with_cell(
64                    Cell::text("Bold, red, 14pt").with_format(
65                        CellFormat::new()
66                            .with_bold(true)
67                            .with_font_size(14.0)
68                            .with_font_color("FFC00000"),
69                    ),
70                ),
71            )
72            .with_row(
73                Row::new().with_cell(
74                    Cell::text("Centered both ways").with_format(
75                        CellFormat::new()
76                            .with_horizontal_alignment(HorizontalAlignment::Center)
77                            .with_vertical_alignment(VerticalAlignment::Center),
78                    ),
79                ),
80            )
81            .with_row(Row::new().with_cell(
82                Cell::text("Indented text").with_format(CellFormat::new().with_indent(2)),
83            ));
84
85    let number_formats_sheet = Sheet::new("Number formats")
86        .with_row(Row::new().with_cell(
87            Cell::number(1234.5).with_format(CellFormat::new().with_number_format("#,##0.00")),
88        ))
89        .with_row(Row::new().with_cell(
90            Cell::number(0.0825).with_format(CellFormat::new().with_number_format("0.00%")),
91        ))
92        .with_row(Row::new().with_cell(
93            Cell::number(1234.5).with_format(CellFormat::new().with_number_format("$#,##0.00")),
94        ));
95
96    let named_styles_sheet = Sheet::new("Named styles").with_row(
97        Row::new().with_cell(
98            Cell::text("Uses a named style")
99                .with_format(CellFormat::new().with_named_style("Emphasis")),
100        ),
101    );
102
103    let workbook = Workbook::new()
104        .with_named_cell_style(NamedCellStyle::new(
105            "Emphasis",
106            CellFormat::new()
107                .with_bold(true)
108                .with_font_color("FF4472C4"),
109        ))
110        .with_sheet(borders_sheet)
111        .with_sheet(fills_sheet)
112        .with_sheet(fonts_and_alignment_sheet)
113        .with_sheet(number_formats_sheet)
114        .with_sheet(named_styles_sheet);
115
116    workbook.save_to_file(&path)?;
117    println!("Wrote {}", path.display());
118    Ok(())
119}
Source

pub fn with_text(self, text: impl Into<String>) -> Row

Appends a text cell and returns the row for chaining — a convenience for the common case of not needing Cell directly.

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 with_number(self, number: f64) -> Row

Appends a numeric cell and returns the row for chaining.

Examples found in repository?
examples/xlsx_print_and_views.rs (line 19)
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}
More examples
Hide additional examples
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}
examples/xlsx_tables.rs (line 21)
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}
examples/xlsx_conditional_formatting_and_validation.rs (line 21)
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_formula(self, formula: impl Into<String>) -> Row

Appends a formula cell (no cached value) and returns the row for chaining.

Source

pub fn with_height(self, height: f64) -> Row

Sets this row’s explicit height, in points, and returns it for chaining.

Examples found in repository?
examples/xlsx_structure_and_layout.rs (line 37)
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_hidden(self, hidden: bool) -> Row

Sets whether this row is hidden and returns it for chaining.

Examples found in repository?
examples/xlsx_structure_and_layout.rs (line 38)
13fn main() -> office_toolkit::Result<()> {
14    let path = output_path("xlsx_structure_and_layout.xlsx");
15
16    let merged_sheet = Sheet::new("Merged cells")
17        .with_row(Row::new().with_text("This title spans three columns"))
18        .with_merged_range("A1:C1");
19
20    let columns_sheet = Sheet::new("Columns")
21        .with_row(
22            Row::new()
23                .with_cell(Cell::text("Wide"))
24                .with_cell(Cell::text("Hidden"))
25                .with_cell(Cell::text("Grouped")),
26        )
27        .with_column_setting(ColumnSetting::new(0).with_width(30.0))
28        .with_column_setting(ColumnSetting::new(1).with_hidden(true))
29        .with_column_setting(
30            ColumnSetting::new(2)
31                .with_outline_level(1)
32                .with_collapsed(false),
33        );
34
35    let rows_sheet = Sheet::new("Rows")
36        .with_row(Row::new().with_text("Normal row"))
37        .with_row(Row::new().with_text("Taller row").with_height(30.0))
38        .with_row(Row::new().with_text("Hidden row").with_hidden(true))
39        .with_row(
40            Row::new()
41                .with_text("Grouped detail row")
42                .with_outline_level(1),
43        );
44
45    let frozen_panes_sheet = Sheet::new("Frozen panes")
46        .with_row(
47            Row::new()
48                .with_cell(Cell::text("Frozen header"))
49                .with_cell(Cell::text("Frozen header")),
50        )
51        .with_row(
52            Row::new()
53                .with_cell(Cell::text("Scrolling data"))
54                .with_cell(Cell::number(1.0)),
55        )
56        .with_freeze_panes(FreezePane::new(1, 1));
57
58    let page_breaks_sheet = Sheet::new("Page breaks")
59        .with_row(Row::new().with_text("Above this row: page break"))
60        .with_row(Row::new().with_text("Below the break"))
61        .with_row_break(1)
62        .with_column_break(0)
63        .with_outline_summary_below(false)
64        .with_outline_summary_right(false);
65
66    let workbook = Workbook::new()
67        .with_sheet(merged_sheet)
68        .with_sheet(columns_sheet)
69        .with_sheet(rows_sheet)
70        .with_sheet(frozen_panes_sheet)
71        .with_sheet(page_breaks_sheet);
72
73    workbook.save_to_file(&path)?;
74    println!("Wrote {}", path.display());
75    Ok(())
76}
Source

pub fn with_outline_level(self, level: u8) -> Row

Sets this row’s outline (grouping) level and returns it for chaining.

Examples found in repository?
examples/xlsx_structure_and_layout.rs (line 42)
13fn main() -> office_toolkit::Result<()> {
14    let path = output_path("xlsx_structure_and_layout.xlsx");
15
16    let merged_sheet = Sheet::new("Merged cells")
17        .with_row(Row::new().with_text("This title spans three columns"))
18        .with_merged_range("A1:C1");
19
20    let columns_sheet = Sheet::new("Columns")
21        .with_row(
22            Row::new()
23                .with_cell(Cell::text("Wide"))
24                .with_cell(Cell::text("Hidden"))
25                .with_cell(Cell::text("Grouped")),
26        )
27        .with_column_setting(ColumnSetting::new(0).with_width(30.0))
28        .with_column_setting(ColumnSetting::new(1).with_hidden(true))
29        .with_column_setting(
30            ColumnSetting::new(2)
31                .with_outline_level(1)
32                .with_collapsed(false),
33        );
34
35    let rows_sheet = Sheet::new("Rows")
36        .with_row(Row::new().with_text("Normal row"))
37        .with_row(Row::new().with_text("Taller row").with_height(30.0))
38        .with_row(Row::new().with_text("Hidden row").with_hidden(true))
39        .with_row(
40            Row::new()
41                .with_text("Grouped detail row")
42                .with_outline_level(1),
43        );
44
45    let frozen_panes_sheet = Sheet::new("Frozen panes")
46        .with_row(
47            Row::new()
48                .with_cell(Cell::text("Frozen header"))
49                .with_cell(Cell::text("Frozen header")),
50        )
51        .with_row(
52            Row::new()
53                .with_cell(Cell::text("Scrolling data"))
54                .with_cell(Cell::number(1.0)),
55        )
56        .with_freeze_panes(FreezePane::new(1, 1));
57
58    let page_breaks_sheet = Sheet::new("Page breaks")
59        .with_row(Row::new().with_text("Above this row: page break"))
60        .with_row(Row::new().with_text("Below the break"))
61        .with_row_break(1)
62        .with_column_break(0)
63        .with_outline_summary_below(false)
64        .with_outline_summary_right(false);
65
66    let workbook = Workbook::new()
67        .with_sheet(merged_sheet)
68        .with_sheet(columns_sheet)
69        .with_sheet(rows_sheet)
70        .with_sheet(frozen_panes_sheet)
71        .with_sheet(page_breaks_sheet);
72
73    workbook.save_to_file(&path)?;
74    println!("Wrote {}", path.display());
75    Ok(())
76}
Source

pub fn with_collapsed(self, collapsed: bool) -> Row

Sets whether this row’s outline group is shown collapsed and returns it for chaining.

Source

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

Sets this row’s default cell format and returns it for chaining.

Trait Implementations§

Source§

impl Clone for Row

Source§

fn clone(&self) -> Row

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 Row

Source§

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

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

impl Default for Row

Source§

fn default() -> Row

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

impl PartialEq for Row

Source§

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

Auto Trait Implementations§

§

impl Freeze for Row

§

impl RefUnwindSafe for Row

§

impl Send for Row

§

impl Sync for Row

§

impl Unpin for Row

§

impl UnsafeUnpin for Row

§

impl UnwindSafe for Row

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.