Trait edit_xlsx::Write

source ·
pub trait Write: _Write {
Show 26 methods // Provided methods fn write<L: Location, T: CellDisplay + CellValue>( &mut self, loc: L, data: T ) -> WorkSheetResult<()> { ... } fn write_string<L: Location>( &mut self, loc: L, data: String ) -> WorkSheetResult<()> { ... } fn write_number<L: Location>( &mut self, loc: L, data: i32 ) -> WorkSheetResult<()> { ... } fn write_double<L: Location>( &mut self, loc: L, data: f64 ) -> WorkSheetResult<()> { ... } fn write_boolean<L: Location>( &mut self, loc: L, data: bool ) -> WorkSheetResult<()> { ... } fn write_row<L: Location, T: CellDisplay + CellValue>( &mut self, loc: L, data: Iter<'_, T> ) -> WorkSheetResult<()> { ... } fn write_column<L: Location, T: CellDisplay + CellValue>( &mut self, loc: L, data: Iter<'_, T> ) -> WorkSheetResult<()> { ... } fn write_url<L: Location>( &mut self, loc: L, url: &str ) -> WorkSheetResult<()> { ... } fn write_url_text<L: Location>( &mut self, loc: L, url: &str, data: &str ) -> WorkSheetResult<()> { ... } fn merge_range<L: LocationRange, T: CellDisplay + CellValue>( &mut self, loc: L, data: T ) -> WorkSheetResult<()> { ... } fn write_formula<L: Location>( &mut self, loc: L, data: &str ) -> WorkSheetResult<()> { ... } fn write_array_formula<L: Location>( &mut self, loc: L, data: &str ) -> WorkSheetResult<()> { ... } fn write_dynamic_array_formula<L: Location>( &mut self, loc: L, data: &str ) -> WorkSheetResult<()> { ... } fn write_with_format<L: Location, T: CellDisplay + CellValue>( &mut self, loc: L, data: T, format: &Format<'_> ) -> WorkSheetResult<()> { ... } fn write_string_with_format<L: Location>( &mut self, loc: L, data: String, format: &Format<'_> ) -> WorkSheetResult<()> { ... } fn write_number_with_format<L: Location>( &mut self, loc: L, data: i32, format: &Format<'_> ) -> WorkSheetResult<()> { ... } fn write_double_with_format<L: Location>( &mut self, loc: L, data: f64, format: &Format<'_> ) -> WorkSheetResult<()> { ... } fn write_boolean_with_format<L: Location>( &mut self, loc: L, data: bool, format: &Format<'_> ) -> WorkSheetResult<()> { ... } fn write_row_with_format<L: Location, T: CellDisplay + CellValue>( &mut self, loc: L, data: Iter<'_, T>, format: &Format<'_> ) -> WorkSheetResult<()> { ... } fn write_column_with_format<L: Location, T: CellDisplay + CellValue>( &mut self, loc: L, data: Iter<'_, T>, format: &Format<'_> ) -> WorkSheetResult<()> { ... } fn write_url_with_format<L: Location>( &mut self, loc: L, url: &str, format: &Format<'_> ) -> WorkSheetResult<()> { ... } fn write_url_data_with_format<L: Location>( &mut self, loc: L, url: &str, data: &str, format: &Format<'_> ) -> WorkSheetResult<()> { ... } fn write_formula_with_format<L: Location>( &mut self, loc: L, data: &str, format: &Format<'_> ) -> WorkSheetResult<()> { ... } fn write_array_formula_with_format<L: Location>( &mut self, loc: L, data: &str, format: &Format<'_> ) -> WorkSheetResult<()> { ... } fn write_dynamic_array_formula_with_format<L: LocationRange>( &mut self, loc_range: L, data: &str, format: &Format<'_> ) -> WorkSheetResult<()> { ... } fn merge_range_with_format<L: LocationRange, T: CellDisplay + CellValue>( &mut self, loc: L, data: T, format: &Format<'_> ) -> WorkSheetResult<()> { ... }
}

Provided Methods§

source

fn write<L: Location, T: CellDisplay + CellValue>( &mut self, loc: L, data: T ) -> WorkSheetResult<()>

Examples found in repository?
examples/hide_row_col.rs (line 10)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();

    let worksheet = workbook.get_worksheet(1)?;

    // Write some data.
    worksheet.write("D1", "Some hidden columns.")?;
    worksheet.write("A8", "Some hidden rows.")?;

    // Hide all rows without data.
    worksheet.hide_unused_rows(true);

    // Set the height of empty rows that we do want to display even if it is
    // the default height.
    for row in 2..=7 {
        worksheet.set_row(row, 15.0)?;
    }

    // Columns can be hidden explicitly. This doesn't increase the file size..
    worksheet.hide_column("G:XFD")?;

    workbook.save_as("examples/hide_row_col.xlsx")?;
    Ok(())
}
More examples
Hide additional examples
examples/doc_properties.rs (line 20)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();
    let mut properties = Properties::default();
    properties.set_title("This is an example spreadsheet")
        .set_subject("With document properties")
        .set_author("pt")
        .set_manager("example manager")
        .set_company("example company")
        .set_category("Example spreadsheets")
        .set_keywords("Sample, Example, Properties")
        .set_comments("Created with Rust")
        .set_status("example status");
    workbook.set_properties(&properties)?;
    // Use the default worksheet
    let worksheet = workbook.get_worksheet(1)?;
    worksheet.set_column("A:A", 70.0)?;
    worksheet.write("A1", "Select 'Workbook Properties' to see properties.")?;
    workbook.save_as("examples/doc_properties.xlsx")?;
    Ok(())
}
examples/array_formula.rs (line 9)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();
    // Use the default worksheet
    let worksheet = workbook.get_worksheet(1)?;
    // Write some test data.
    worksheet.write("B1", 500)?;
    worksheet.write("B2", 10)?;
    worksheet.write("B5", 1)?;
    worksheet.write("B6", 2)?;
    worksheet.write("B7", 3)?;
    worksheet.write("C1", 300)?;
    worksheet.write("C2", 15)?;
    worksheet.write("C5", 20234)?;
    worksheet.write("C6", 21003)?;
    worksheet.write("C7", 10000)?;
    // Write an array formula that returns a single value
    worksheet.write_formula("A1", "_xlfn.SUM(B1:C1*B2:C2)")?;
    // Same as above but more verbose.
    worksheet.write_array_formula("A2", "_xlfn.SUM(B1:C1*B2:C2)")?;
    // Write an array formula that returns a range of values
    worksheet.write_array_formula("A5", "_xlfn.TREND(C5:C7,B5:B7)")?;

    workbook.save_as("examples/array_formula.xlsx")?;
    Ok(())
}
examples/hide_sheet.rs (line 9)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();
    let worksheet1 = workbook.get_worksheet(1)?;

    worksheet1.set_column("A:A", 30.0)?;
    worksheet1.write("A1", "Sheet2 is hidden")?;

    // Hide Sheet2. It won't be visible until it is unhidden in Excel.
    let worksheet2 = workbook.add_worksheet()?;
    worksheet2.set_column("A:A", 30.0)?;
    // worksheet2.activate();
    worksheet2.hide();
    worksheet2.write("A1", "Now it's my turn to find you!")?;
    // Note, you can't hide the "active" worksheet, which generally is the
    // first worksheet, since this would cause an Excel error. So, in order to hide
    // the first sheet you will need to activate another worksheet:
    //
    //    worksheet2.activate();
    //    worksheet1.hide();

    let worksheet3 = workbook.add_worksheet()?;
    worksheet3.set_column("A:A", 30.0)?;
    worksheet3.write("A1", "Sheet2 is hidden")?;

    workbook.save_as("examples/hide_sheet.xlsx")?;
    Ok(())
}
examples/ignore_errors.rs (line 24)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn main() -> WorkbookResult<()> {
    let mut workbook = Workbook::new();
    let worksheet = workbook.get_worksheet(1)?;

    // Write strings that looks like numbers. This will cause an Excel warning.
    worksheet.write_string("C2", "123".to_string())?;
    worksheet.write_string("C3", "123".to_string())?;

    // Write a divide by zero formula. This will also cause an Excel warning.
    worksheet.write_formula("C5", "=1/0")?;
    worksheet.write_formula("C6", "=1/0")?;

    // Turn off some of the warnings:
    let mut error_map = HashMap::new();
    error_map.insert("number_stored_as_text", "C3");
    error_map.insert("eval_error", "C6");
    worksheet.ignore_errors(error_map);

    // Write some descriptions for the cells and make the column wider for clarity.
    worksheet.set_column("B:B", 16.0)?;
    worksheet.write("B2", "Warning:")?;
    worksheet.write("B3", "Warning turned off:")?;
    worksheet.write("B5", "Warning:")?;
    worksheet.write("B6", "Warning turned off:")?;

    workbook.save_as("examples/ignore_errors.xlsx")?;
    Ok(())
}
examples/outline_collapsed.rs (line 181)
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
fn create_sub_totals(worksheet: &mut WorkSheet) -> WorkbookResult<()> {
    // Add a general format
    let bold = Format::default().set_bold();

    // Add the data, labels and formulas
    worksheet.write_with_format("A1", "Region", &bold)?;
    worksheet.write("A2", "North")?;
    worksheet.write("A3", "North")?;
    worksheet.write("A4", "North")?;
    worksheet.write("A5", "North")?;
    worksheet.write_with_format("A6", "North Total", &bold)?;

    worksheet.write_with_format("B1", "Sales", &bold)?;
    worksheet.write("B2", 1000)?;
    worksheet.write("B3", 1200)?;
    worksheet.write("B4", 900)?;
    worksheet.write("B5", 1200)?;
    worksheet.write_formula_with_format("B6", "=SUBTOTAL(9,B2:B5)", &bold)?;
    worksheet.write("A7", "South")?;
    worksheet.write("A8", "South")?;
    worksheet.write("A9", "South")?;
    worksheet.write("A10", "South")?;
    worksheet.write_with_format("A11", "South Total", &bold)?;
    worksheet.write("B7", 400)?;
    worksheet.write("B8", 600)?;
    worksheet.write("B9", 500)?;
    worksheet.write("B10", 600)?;
    worksheet.write_formula_with_format("B11", "=SUBTOTAL(9,B7:B10)", &bold)?;
    worksheet.write_with_format("A12", "Grand Total", &bold)?;
    worksheet.write_formula_with_format("B12", "=SUBTOTAL(9,B2:B10)", &bold)?;
    Ok(())
}
source

fn write_string<L: Location>( &mut self, loc: L, data: String ) -> WorkSheetResult<()>

Examples found in repository?
examples/ignore_errors.rs (line 9)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn main() -> WorkbookResult<()> {
    let mut workbook = Workbook::new();
    let worksheet = workbook.get_worksheet(1)?;

    // Write strings that looks like numbers. This will cause an Excel warning.
    worksheet.write_string("C2", "123".to_string())?;
    worksheet.write_string("C3", "123".to_string())?;

    // Write a divide by zero formula. This will also cause an Excel warning.
    worksheet.write_formula("C5", "=1/0")?;
    worksheet.write_formula("C6", "=1/0")?;

    // Turn off some of the warnings:
    let mut error_map = HashMap::new();
    error_map.insert("number_stored_as_text", "C3");
    error_map.insert("eval_error", "C6");
    worksheet.ignore_errors(error_map);

    // Write some descriptions for the cells and make the column wider for clarity.
    worksheet.set_column("B:B", 16.0)?;
    worksheet.write("B2", "Warning:")?;
    worksheet.write("B3", "Warning turned off:")?;
    worksheet.write("B5", "Warning:")?;
    worksheet.write("B6", "Warning turned off:")?;

    workbook.save_as("examples/ignore_errors.xlsx")?;
    Ok(())
}
source

fn write_number<L: Location>( &mut self, loc: L, data: i32 ) -> WorkSheetResult<()>

source

fn write_double<L: Location>( &mut self, loc: L, data: f64 ) -> WorkSheetResult<()>

source

fn write_boolean<L: Location>( &mut self, loc: L, data: bool ) -> WorkSheetResult<()>

source

fn write_row<L: Location, T: CellDisplay + CellValue>( &mut self, loc: L, data: Iter<'_, T> ) -> WorkSheetResult<()>

Examples found in repository?
examples/dynamic_arrays.rs (line 236)
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
fn write_worksheet_data(worksheet: &mut WorkSheet, header: &Format) -> WorkSheetResult<()> {
    worksheet.write_with_format("A1", "Region", &header)?;
    worksheet.write_with_format("B1", "Sales Rep", &header)?;
    worksheet.write_with_format("C1", "Product", &header)?;
    worksheet.write_with_format("D1", "Units", &header)?;
    let data = [
        ["East", "Tom", "Apple"],
        ["West", "Fred", "Grape"],
        ["North", "Amy", "Pear"],
        ["South", "Sal", "Banana"],
        ["East", "Fritz", "Apple"],
        ["West", "Sravan", "Grape"],
        ["North", "Xi", "Pear"],
        ["South", "Hector", "Banana"],
        ["East", "Tom", "Banana"],
        ["West", "Fred", "Pear"],
        ["North", "Amy", "Grape"],
        ["South", "Sal", "Apple"],
        ["East", "Fritz", "Banana"],
        ["West", "Sravan", "Pear"],
        ["North", "Xi", "Grape"],
        ["South", "Hector", "Apple"],
    ];
    let mut row_num = 2;
    for data in data {
        worksheet.write_row((row_num, 1), data.iter())?;
        row_num += 1;
    }
    let units = [6380, 5619, 4565, 5323, 4394, 7195, 5231, 2427, 4213, 3239, 6520, 1310, 6274, 4894, 7580, 9814];
    worksheet.write_column("D2", units.iter())?;
    Ok(())
}
More examples
Hide additional examples
examples/outline_collapsed.rs (line 128)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();
    // Add a general format
    let bold = Format::default().set_bold();

    //
    // Example 1: A worksheet with outlined rows. It also includes SUBTOTAL()
    // functions so that it looks like the type of automatic outlines that are
    // generated when you use the Excel Data->SubTotals menu item.
    //
    let worksheet1 = workbook.add_worksheet_by_name("Outlined Rows")?;
    worksheet1.set_row_level(2, 2)?;
    worksheet1.set_row_level(3, 2)?;
    worksheet1.set_row_level(4, 2)?;
    worksheet1.set_row_level(5, 2)?;
    worksheet1.set_row_level(6, 1)?;
    worksheet1.set_row_level(7, 2)?;
    worksheet1.set_row_level(8, 2)?;
    worksheet1.set_row_level(9, 2)?;
    worksheet1.set_row_level(10, 2)?;
    worksheet1.set_row_level(11, 1)?;
    create_sub_totals(worksheet1)?;

    //
    // Example 2: Create a worksheet with collapsed outlined rows.
    // This is the same as the example 1  except that the all rows are collapsed.
    // Note: We need to indicate the rows that contains the collapsed symbol '+'
    // with the optional parameter, 'collapsed'.
    //
    let worksheet2 = workbook.add_worksheet_by_name("Collapsed Rows 1")?;
    worksheet2.set_row_level(2, 2)?;
    worksheet2.hide_row(2)?;
    worksheet2.set_row_level(3, 2)?;
    worksheet2.hide_row(3)?;
    worksheet2.set_row_level(4, 2)?;
    worksheet2.hide_row(4)?;
    worksheet2.set_row_level(5, 2)?;
    worksheet2.hide_row(5)?;
    worksheet2.set_row_level(6, 1)?;
    worksheet2.hide_row(6)?;
    worksheet2.set_row_level(7, 2)?;
    worksheet2.hide_row(7)?;
    worksheet2.set_row_level(8, 2)?;
    worksheet2.hide_row(8)?;
    worksheet2.set_row_level(9, 2)?;
    worksheet2.hide_row(9)?;
    worksheet2.set_row_level(10, 2)?;
    worksheet2.hide_row(10)?;
    worksheet2.set_row_level(11, 1)?;
    worksheet2.hide_row(11)?;

    worksheet2.collapse_row(12)?;

    // Write the sub-total data that is common to the row examples.
    create_sub_totals(worksheet2)?;


    //
    // Example 3: Create a worksheet with collapsed outlined rows.
    // Same as the example 1  except that the two sub-totals are collapsed.
    //
    let worksheet3 = workbook.add_worksheet_by_name("Collapsed Rows 2")?;
    worksheet3.set_row_level(2, 2)?;
    worksheet3.hide_row(2)?;
    worksheet3.set_row_level(3, 2)?;
    worksheet3.hide_row(3)?;
    worksheet3.set_row_level(4, 2)?;
    worksheet3.hide_row(4)?;
    worksheet3.set_row_level(5, 2)?;
    worksheet3.hide_row(5)?;
    worksheet3.set_row_level(6, 1)?;
    worksheet3.collapse_row(6)?;
    worksheet3.set_row_level(7, 2)?;
    worksheet3.hide_row(7)?;
    worksheet3.set_row_level(8, 2)?;
    worksheet3.hide_row(8)?;
    worksheet3.set_row_level(9, 2)?;
    worksheet3.hide_row(9)?;
    worksheet3.set_row_level(10, 2)?;
    worksheet3.hide_row(10)?;
    worksheet3.set_row_level(11, 1)?;
    worksheet3.collapse_row(11)?;
    // Write the sub-total data that is common to the row examples.
    create_sub_totals(worksheet3)?;


    //
    // Example 4: Create a worksheet with outlined rows.
    // Same as the example 1  except that the two sub-totals are collapsed.
    //
    let worksheet4 = workbook.add_worksheet_by_name("Collapsed Rows 3")?;
    worksheet4.set_row_level(2, 2)?;
    worksheet4.hide_row(2)?;
    worksheet4.set_row_level(3, 2)?;
    worksheet4.hide_row(3)?;
    worksheet4.set_row_level(4, 2)?;
    worksheet4.hide_row(4)?;
    worksheet4.set_row_level(5, 2)?;
    worksheet4.hide_row(5)?;
    worksheet4.set_row_level(6, 1)?;
    worksheet4.hide_row(6)?;
    worksheet4.collapse_row(6)?;
    worksheet4.set_row_level(7, 2)?;
    worksheet4.hide_row(7)?;
    worksheet4.set_row_level(8, 2)?;
    worksheet4.hide_row(8)?;
    worksheet4.set_row_level(9, 2)?;
    worksheet4.hide_row(9)?;
    worksheet4.set_row_level(10, 2)?;
    worksheet4.hide_row(10)?;
    worksheet4.set_row_level(11, 1)?;
    worksheet4.hide_row(11)?;
    worksheet4.collapse_row(11)?;
    worksheet4.collapse_row(12)?;
    // Write the sub-total data that is common to the row examples.
    create_sub_totals(worksheet4)?;



    //
    // Example 5: Create a worksheet with outlined columns.
    //
    let worksheet5 = workbook.add_worksheet_by_name("Outline Columns")?;
    worksheet5.set_row_with_format(1, 15.0, &bold)?;
    worksheet5.write_row("A1", ["Month", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Total"].iter())?;
    worksheet5.set_column_with_format("A:A", 10.0, &bold)?;
    worksheet5.set_column("B:G", 5.0)?;
    worksheet5.set_column_level("B:G", 1)?;
    worksheet5.set_column("H:H", 10.0)?;
    worksheet5.write_column("A2", ["North", "South", "East", "East"].iter())?;
    worksheet5.write_row("B2", [50, 20, 15, 25, 65, 80].iter())?;
    worksheet5.write_row("B3", [10, 20, 30, 50, 50, 50].iter())?;
    worksheet5.write_row("B4", [45, 75, 50, 15, 75, 100].iter())?;
    worksheet5.write_row("B5", [15, 15, 55, 35, 20, 50].iter())?;
    worksheet5.write_formula("H2", "=SUM(B2:G2)")?;
    worksheet5.write_formula("H3", "=SUM(B3:G3)")?;
    worksheet5.write_formula("H4", "=SUM(B4:G4)")?;
    worksheet5.write_formula("H5", "=SUM(B5:G5)")?;
    worksheet5.write_formula_with_format("H6", "=SUM(H2:H5)", &bold)?;



    //
    // Example 6: Create a worksheet with collapsed outlined columns.
    // This is the same as the previous example except with collapsed columns.
    //
    let worksheet6 = workbook.add_worksheet_by_name("Collapsed Columns")?;
    worksheet6.set_row_with_format(1, 15.0, &bold)?;
    worksheet6.write_row("A1", ["Month", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Total"].iter())?;
    worksheet6.set_column_with_format("A:H", 10.0, &bold)?;
    worksheet6.set_column_level("B:G", 1)?;
    worksheet6.set_column_level("C:F", 2)?;
    worksheet6.set_column_level("D:E", 3)?;
    worksheet6.hide_column("D:E")?;
    worksheet6.collapse_col("D:E")?;
    worksheet6.write_column("A2", ["North", "South", "East", "East"].iter())?;
    worksheet6.write_row("B2", [50, 20, 15, 25, 65, 80].iter())?;
    worksheet6.write_row("B3", [10, 20, 30, 50, 50, 50].iter())?;
    worksheet6.write_row("B4", [45, 75, 50, 15, 75, 100].iter())?;
    worksheet6.write_row("B5", [15, 15, 55, 35, 20, 50].iter())?;
    worksheet6.write_formula("H2", "=SUM(B2:G2)")?;
    worksheet6.write_formula("H3", "=SUM(B3:G3)")?;
    worksheet6.write_formula("H4", "=SUM(B4:G4)")?;
    worksheet6.write_formula("H5", "=SUM(B5:G5)")?;
    worksheet6.write_formula_with_format("H6", "=SUM(H2:H5)", &bold)?;


    workbook.save_as("examples/outline_collapsed.xlsx")?;
    Ok(())
}
examples/outline.rs (line 127)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();
    let worksheet1 = workbook.add_worksheet_by_name("Outlined Rows")?;
    // Add a general format
    let bold = Format::default().set_bold();

    //
    // Example 1: A worksheet with outlined rows. It also includes SUBTOTAL()?;    // functions so that it looks like the type of automatic outlines that are
    // generated when you use the Excel Data->SubTotals menu item.
    //
    // For outlines the important parameters are 'level' and 'hidden'. Rows with
    // the same 'level' are grouped together. The group will be collapsed if
    // 'hidden' is enabled. The parameters 'height' and 'cell_format' are assigned
    // default values if they are None.
    //
    worksheet1.set_row_level(2, 2)?;
    worksheet1.set_row_level(3, 2)?;
    worksheet1.set_row_level(4, 2)?;
    worksheet1.set_row_level(5, 2)?;
    worksheet1.set_row_level(6, 1)?;
    worksheet1.set_row_level(7, 2)?;
    worksheet1.set_row_level(8, 2)?;
    worksheet1.set_row_level(9, 2)?;
    worksheet1.set_row_level(10, 2)?;
    worksheet1.set_row_level(11, 1)?;

    // Adjust the column width for clarity
    worksheet1.set_column("A:A", 20.0)?;

    // Add the data, labels and formulas
    worksheet1.write_with_format("A1", "Region", &bold)?;
    worksheet1.write("A2", "North")?;
    worksheet1.write("A3", "North")?;
    worksheet1.write("A4", "North")?;
    worksheet1.write("A5", "North")?;
    worksheet1.write_with_format("A6", "North Total", &bold)?;

    worksheet1.write_with_format("B1", "Sales", &bold)?;
    worksheet1.write("B2", 1000)?;
    worksheet1.write("B3", 1200)?;
    worksheet1.write("B4", 900)?;
    worksheet1.write("B5", 1200)?;
    worksheet1.write_formula_with_format("B6", "=SUBTOTAL(9,B2:B5)", &bold)?;
    worksheet1.write("A7", "South")?;
    worksheet1.write("A8", "South")?;
    worksheet1.write("A9", "South")?;
    worksheet1.write("A10", "South")?;
    worksheet1.write_with_format("A11", "South Total", &bold)?;
    worksheet1.write("B7", 400)?;
    worksheet1.write("B8", 600)?;
    worksheet1.write("B9", 500)?;
    worksheet1.write("B10", 600)?;
    worksheet1.write_formula_with_format("B11", "=SUBTOTAL(9,B7:B10)", &bold)?;
    worksheet1.write_with_format("A12", "Grand Total", &bold)?;
    worksheet1.write_formula_with_format("B12", "=SUBTOTAL(9,B2:B10)", &bold)?;


    //
    // Example 2: A worksheet with outlined rows. This is the same as the
    // previous example except that the rows are collapsed.
    // Note: We need to indicate the rows that contains the collapsed symbol '+'
    // with the optional parameter, 'collapsed'. The group will be then be
    // collapsed if 'hidden' is True.
    //
    let worksheet2 = workbook.add_worksheet_by_name("Collapsed Rows")?;
    worksheet2.set_row_level(2, 2)?;
    worksheet2.hide_row(2)?;
    worksheet2.set_row_level(3, 2)?;
    worksheet2.hide_row(3)?;
    worksheet2.set_row_level(4, 2)?;
    worksheet2.hide_row(4)?;
    worksheet2.set_row_level(5, 2)?;
    worksheet2.hide_row(5)?;
    worksheet2.set_row_level(6, 1)?;
    worksheet2.hide_row(6)?;
    worksheet2.set_row_level(7, 2)?;
    worksheet2.hide_row(7)?;
    worksheet2.set_row_level(8, 2)?;
    worksheet2.hide_row(8)?;
    worksheet2.set_row_level(9, 2)?;
    worksheet2.hide_row(9)?;
    worksheet2.set_row_level(10, 2)?;
    worksheet2.hide_row(10)?;
    worksheet2.set_row_level(11, 1)?;
    worksheet2.hide_row(11)?;
    worksheet2.collapse_row(12)?;

    // Adjust the column width for clarity
    worksheet2.set_column("A:A", 20.0)?;

    // Add the data, labels and formulas
    worksheet2.write_with_format("A1", "Region", &bold)?;
    worksheet2.write("A2", "North")?;
    worksheet2.write("A3", "North")?;
    worksheet2.write("A4", "North")?;
    worksheet2.write("A5", "North")?;
    worksheet2.write_with_format("A6", "North Total", &bold)?;

    worksheet2.write_with_format("B1", "Sales", &bold)?;
    worksheet2.write("B2", 1000)?;
    worksheet2.write("B3", 1200)?;
    worksheet2.write("B4", 900)?;
    worksheet2.write("B5", 1200)?;
    worksheet2.write_formula_with_format("B6", "=SUBTOTAL(9,B2:B5)", &bold)?;
    worksheet2.write("A7", "South")?;
    worksheet2.write("A8", "South")?;
    worksheet2.write("A9", "South")?;
    worksheet2.write("A10", "South")?;
    worksheet2.write_with_format("A11", "South Total", &bold)?;
    worksheet2.write("B7", 400)?;
    worksheet2.write("B8", 600)?;
    worksheet2.write("B9", 500)?;
    worksheet2.write("B10", 600)?;
    worksheet2.write_formula_with_format("B11", "=SUBTOTAL(9,B7:B10)", &bold)?;
    worksheet2.write_with_format("A12", "Grand Total", &bold)?;
    worksheet2.write_formula_with_format("B12", "=SUBTOTAL(9,B2:B10)", &bold)?;

    //
    // Example 3: Create a worksheet with outlined columns.
    //
    let worksheet3 = workbook.add_worksheet_by_name("Outline Columns")?;
    // Add bold format to the first row.
    worksheet3.set_row_with_format(1, 15.0, &bold)?;
    worksheet3.write_row("A1", ["Month", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Total"].iter())?;
    worksheet3.set_column_with_format("A:A", 10.0, &bold)?;
    worksheet3.set_column("B:G", 10.0)?;
    worksheet3.set_column_level("B:G", 1)?;
    worksheet3.set_column("H:H", 10.0)?;
    worksheet3.write_column("A2", ["North", "South", "East", "East"].iter())?;
    worksheet3.write_row("B2", [50, 20, 15, 25, 65, 80].iter())?;
    worksheet3.write_row("B3", [10, 20, 30, 50, 50, 50].iter())?;
    worksheet3.write_row("B4", [45, 75, 50, 15, 75, 100].iter())?;
    worksheet3.write_row("B5", [15, 15, 55, 35, 20, 50].iter())?;
    worksheet3.write_formula("H2", "=SUM(B2:G2)")?;
    worksheet3.write_formula("H3", "=SUM(B3:G3)")?;
    worksheet3.write_formula("H4", "=SUM(B4:G4)")?;
    worksheet3.write_formula("H5", "=SUM(B5:G5)")?;
    worksheet3.write_formula_with_format("H6", "=SUM(H2:H5)", &bold)?;

    //
    // Example 4: Show all possible outline levels.
    //
    let levels = [
        "Level 1",
        "Level 2",
        "Level 3",
        "Level 4",
        "Level 5",
        "Level 6",
        "Level 7",
        "Level 6",
        "Level 5",
        "Level 4",
        "Level 3",
        "Level 2",
        "Level 1",
    ];
    let worksheet4 = workbook.add_worksheet_by_name("Outline levels")?;
    worksheet4.write_column("A1", levels.iter())?;

    worksheet4.set_row_level(1, 1)?;
    worksheet4.set_row_level(2, 2)?;
    worksheet4.set_row_level(3, 3)?;
    worksheet4.set_row_level(4, 4)?;
    worksheet4.set_row_level(5, 5)?;
    worksheet4.set_row_level(6, 6)?;
    worksheet4.set_row_level(7, 7)?;
    worksheet4.set_row_level(8, 6)?;
    worksheet4.set_row_level(9, 5)?;
    worksheet4.set_row_level(10, 4)?;
    worksheet4.set_row_level(11, 3)?;
    worksheet4.set_row_level(12, 2)?;
    worksheet4.set_row_level(13, 1)?;

    workbook.save_as("examples/outline.xlsx")?;
    Ok(())
}
examples/autofilter.rs (line 29)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
fn main() -> WorkbookResult<()> {
    // Prepare autofilter data
    let text = fs::read_to_string("examples/autofilter_data.txt").unwrap();
    let mut text = text.split("\n");
    let headers: Vec<&str> = text.next().unwrap().split_whitespace().collect();
    let mut data: Vec<Vec<&str>> = vec![];
    for text in text { data.push(text.split_whitespace().collect()) }

    // Create a new workbook
    let mut workbook = Workbook::new();
    // Add some worksheets
    workbook.add_worksheet()?;
    workbook.add_worksheet()?;
    workbook.add_worksheet()?;
    workbook.add_worksheet()?;
    workbook.add_worksheet()?;
    workbook.add_worksheet()?;

    // Set up several sheets with the same data.
    for worksheet in workbook.worksheets() {
        // Make the columns wider.
        worksheet.set_column("A:D", 12.0)?;
        // // Make the header row larger.
        worksheet.set_row_with_format(1, 20.0, &Format::default().set_bold())?;
        // Make the headers bold.
        worksheet.write_row("A1", headers.iter())?;
    }

    //
    // Example 1. Autofilter without conditions.
    //

    let worksheet1 = workbook.get_worksheet(1)?;
    // Set the autofilter.
    worksheet1.autofilter("A1:D51");
    let mut row = 2;
    for row_data in &data {
        let mut col = 1;
        for data in row_data {
            if let Ok(num) = data.parse::<i32>() {
                worksheet1.write((row, col), num)?;
            } else {
                worksheet1.write((row, col), *data)?;
            }
            col += 1;
        }
        // Move on to the next worksheet row.
        row += 1;
    }


    //
    // Example 2. Autofilter with a filter condition in the first column.
    //
    let worksheet2 = workbook.get_worksheet(2)?;
    // Set the autofilter.
    worksheet2.autofilter("A1:D51");
    // Add filter criteria.
    let mut filters = Filters::new();
    filters.and(Filter::eq("East"));
    worksheet2.filter_column("A", &filters);
    // Hide the rows that don't match the filter criteria.
    let mut row = 2;
    for row_data in &data {
        let mut col = 1;
        let data = row_data.get(0);
        // Check for rows that match the filter.
        if data != Some(&"East") {
            // We need to hide rows that don't match the filter.
            worksheet2.hide_row(row)?;
        }
        for data in row_data {
            if let Ok(num) = data.parse::<i32>() {
                worksheet2.write((row, col), num)?;
            } else {
                worksheet2.write((row, col), *data)?;
            }
            col += 1;
        }
        // Move on to the next worksheet row.
        row += 1;
    }

    //
    // Example 3. Autofilter with a filter condition in the first column.
    //
    let worksheet3 = workbook.get_worksheet(3)?;
    // Set the autofilter.
    worksheet3.autofilter("A1:D51");
    // Add filter criteria.
    let mut filters = Filters::new();
    filters.and(Filter::eq("East")).or(Filter::eq("South"));
    worksheet3.filter_column("A", &filters);
    // Hide the rows that don't match the filter criteria.
    let mut row = 2;
    for row_data in &data {
        let mut col = 1;
        let data = row_data.get(0);
        // Check for rows that match the filter.
        if data != Some(&"East") && data != Some(&"South") {
            // We need to hide rows that don't match the filter.
            worksheet3.hide_row(row)?;
        }
        for data in row_data {
            if let Ok(num) = data.parse::<i32>() {
                worksheet3.write((row, col), num)?;
            } else {
                worksheet3.write((row, col), *data)?;
            }
            col += 1;
        }
        // Move on to the next worksheet row.
        row += 1;
    }


    //
    // Example 4. Autofilter with filter conditions in two columns.
    //
    let worksheet4 = workbook.get_worksheet(4)?;
    // Set the autofilter.
    worksheet4.autofilter("A1:D51");
    // Add filter criteria.
    let mut filters_a = Filters::new();
    filters_a.and(Filter::eq("East"));
    worksheet4.filter_column("A", &filters_a);
    let mut filters_c = Filters::new();
    filters_c.and(Filter::gt("3000")).and(Filter::lt("8000"));
    worksheet4.filter_column("C", &filters_c);
    // Hide the rows that don't match the filter criteria.
    let mut row = 2;
    for row_data in &data {
        let mut col = 1;
        let data = row_data.get(0);
        // Check for rows that match the filter.
        if data != Some(&"East") {
            // We need to hide rows that don't match the filter.
            worksheet4.hide_row(row)?;
        }
        for data in row_data {
            if let Ok(num) = data.parse::<i32>() {
                if num <= 3000 || num >= 8000 {
                    worksheet4.hide_row(row)?;
                }
                worksheet4.write((row, col), num)?;
            } else {
                worksheet4.write((row, col), *data)?;
            }
            col += 1;
        }
        // Move on to the next worksheet row.
        row += 1;
    }


    //
    // Example 5. Autofilter with a filter list condition in one of the columns.
    //
    let worksheet5 = workbook.get_worksheet(5)?;
    // Set the autofilter.
    worksheet5.autofilter("A1:D51");
    // Add filter criteria.
    let filters_list = Filters::eq(vec!["East", "North", "South"]);
    worksheet5.filter_column("A", &filters_list);
    // Hide the rows that don't match the filter criteria.
    let mut row = 2;
    for row_data in &data {
        let mut col = 1;
        let data = row_data.get(0);
        // Check for rows that match the filter.
        if data != Some(&"East") && data != Some(&"North") && data != Some(&"South") {
            // We need to hide rows that don't match the filter.
            worksheet5.hide_row(row)?;
        }
        for data in row_data {
            if let Ok(num) = data.parse::<i32>() {
                worksheet5.write((row, col), num)?;
            } else {
                worksheet5.write((row, col), *data)?;
            }
            col += 1;
        }
        // Move on to the next worksheet row.
        row += 1;
    }

    //
    // Example 6. Autofilter with filter for blanks.
    //
    let worksheet6 = workbook.get_worksheet(6)?;
    // Set the autofilter.
    worksheet6.autofilter("A1:D51");
    // Add filter criteria.
    let filters = Filters::blank();
    worksheet6.filter_column("A", &filters);
    // Hide the rows that don't match the filter criteria.
    let mut row = 2;
    // Simulate a blank cell in the data.
    data[5][0] = "";

    for row_data in &data {
        let mut col = 1;
        let data = row_data.get(0);
        // Check for rows that match the filter.
        if data != Some(&"") {
            // We need to hide rows that don't match the filter.
            worksheet6.hide_row(row)?;
        }
        for data in row_data {
            if let Ok(num) = data.parse::<i32>() {
                worksheet6.write((row, col), num)?;
            } else {
                worksheet6.write((row, col), *data)?;
            }
            col += 1;
        }
        // Move on to the next worksheet row.
        row += 1;
    }

    //
    // Example 7. Autofilter with filter for non-blanks.
    //
    let worksheet7 = workbook.get_worksheet(7)?;
    // Set the autofilter.
    worksheet7.autofilter("A1:D51");
    // Add filter criteria.
    let filters = Filters::not_blank();
    worksheet7.filter_column("A", &filters);
    // Hide the rows that don't match the filter criteria.
    let mut row = 2;
    // Simulate a blank cell in the data.

    for row_data in &data {
        let mut col = 1;
        let data = row_data.get(0);
        // Check for rows that match the filter.
        if data == Some(&"") {
            // We need to hide rows that don't match the filter.
            worksheet7.hide_row(row)?;
        }
        for data in row_data {
            if let Ok(num) = data.parse::<i32>() {
                worksheet7.write((row, col), num)?;
            } else {
                worksheet7.write((row, col), *data)?;
            }
            col += 1;
        }
        // Move on to the next worksheet row.
        row += 1;
    }


    workbook.save_as("examples/autofilter.xlsx")?;

    Ok(())
}
source

fn write_column<L: Location, T: CellDisplay + CellValue>( &mut self, loc: L, data: Iter<'_, T> ) -> WorkSheetResult<()>

Examples found in repository?
examples/dynamic_arrays.rs (line 240)
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
fn write_worksheet_data(worksheet: &mut WorkSheet, header: &Format) -> WorkSheetResult<()> {
    worksheet.write_with_format("A1", "Region", &header)?;
    worksheet.write_with_format("B1", "Sales Rep", &header)?;
    worksheet.write_with_format("C1", "Product", &header)?;
    worksheet.write_with_format("D1", "Units", &header)?;
    let data = [
        ["East", "Tom", "Apple"],
        ["West", "Fred", "Grape"],
        ["North", "Amy", "Pear"],
        ["South", "Sal", "Banana"],
        ["East", "Fritz", "Apple"],
        ["West", "Sravan", "Grape"],
        ["North", "Xi", "Pear"],
        ["South", "Hector", "Banana"],
        ["East", "Tom", "Banana"],
        ["West", "Fred", "Pear"],
        ["North", "Amy", "Grape"],
        ["South", "Sal", "Apple"],
        ["East", "Fritz", "Banana"],
        ["West", "Sravan", "Pear"],
        ["North", "Xi", "Grape"],
        ["South", "Hector", "Apple"],
    ];
    let mut row_num = 2;
    for data in data {
        worksheet.write_row((row_num, 1), data.iter())?;
        row_num += 1;
    }
    let units = [6380, 5619, 4565, 5323, 4394, 7195, 5231, 2427, 4213, 3239, 6520, 1310, 6274, 4894, 7580, 9814];
    worksheet.write_column("D2", units.iter())?;
    Ok(())
}
More examples
Hide additional examples
examples/defined_name.rs (line 27)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();
    workbook.add_worksheet()?;

    // Define some global/workbook names.
    workbook.define_name("Exchange_rate", "0.96")?;
    workbook.define_name("Sales", "Sheet1!$G$1:$H$10")?;
    // Define a local/worksheet name. Over-rides the "Sales" name above.
    workbook.define_local_name("Sales", "Sheet2!$G$1:$G$10", 2)?;

    // Write some text in the file and one of the defined names in a formula.
    let sales = ["Apple", "Grape", "Pear", "Banana", "Apple", "Grape", "Pear", "Banana", "Banana", "Pear"];
    let units = [10, 12, 32, 16, 13, 50, 25, 8, 33, 95];
    for worksheet in workbook.worksheets() {
        worksheet.set_column("A:B", 40.0)?;
        worksheet.set_column("F:F", 40.0)?;
        worksheet.write("A1", "This worksheet contains some defined names.")?;
        worksheet.write("B1", "Show defined name Sales on the right->")?;
        worksheet.write_formula("C1", "=Sales")?;
        worksheet.write("A2", "See Formulas -> Name Manager above.")?;
        worksheet.write("A3", "Example formula in cell B3 ->")?;
        worksheet.write_formula("B3", "=Exchange_rate")?;
        worksheet.write("F1", "Fill in some arrays on the right->")?;
        worksheet.write_column("G1", sales.iter())?;
        worksheet.write_column("H1", units.iter())?;
    }

    workbook.save_as("examples/defined_name.xlsx")?;
    Ok(())
}
examples/outline_collapsed.rs (line 133)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();
    // Add a general format
    let bold = Format::default().set_bold();

    //
    // Example 1: A worksheet with outlined rows. It also includes SUBTOTAL()
    // functions so that it looks like the type of automatic outlines that are
    // generated when you use the Excel Data->SubTotals menu item.
    //
    let worksheet1 = workbook.add_worksheet_by_name("Outlined Rows")?;
    worksheet1.set_row_level(2, 2)?;
    worksheet1.set_row_level(3, 2)?;
    worksheet1.set_row_level(4, 2)?;
    worksheet1.set_row_level(5, 2)?;
    worksheet1.set_row_level(6, 1)?;
    worksheet1.set_row_level(7, 2)?;
    worksheet1.set_row_level(8, 2)?;
    worksheet1.set_row_level(9, 2)?;
    worksheet1.set_row_level(10, 2)?;
    worksheet1.set_row_level(11, 1)?;
    create_sub_totals(worksheet1)?;

    //
    // Example 2: Create a worksheet with collapsed outlined rows.
    // This is the same as the example 1  except that the all rows are collapsed.
    // Note: We need to indicate the rows that contains the collapsed symbol '+'
    // with the optional parameter, 'collapsed'.
    //
    let worksheet2 = workbook.add_worksheet_by_name("Collapsed Rows 1")?;
    worksheet2.set_row_level(2, 2)?;
    worksheet2.hide_row(2)?;
    worksheet2.set_row_level(3, 2)?;
    worksheet2.hide_row(3)?;
    worksheet2.set_row_level(4, 2)?;
    worksheet2.hide_row(4)?;
    worksheet2.set_row_level(5, 2)?;
    worksheet2.hide_row(5)?;
    worksheet2.set_row_level(6, 1)?;
    worksheet2.hide_row(6)?;
    worksheet2.set_row_level(7, 2)?;
    worksheet2.hide_row(7)?;
    worksheet2.set_row_level(8, 2)?;
    worksheet2.hide_row(8)?;
    worksheet2.set_row_level(9, 2)?;
    worksheet2.hide_row(9)?;
    worksheet2.set_row_level(10, 2)?;
    worksheet2.hide_row(10)?;
    worksheet2.set_row_level(11, 1)?;
    worksheet2.hide_row(11)?;

    worksheet2.collapse_row(12)?;

    // Write the sub-total data that is common to the row examples.
    create_sub_totals(worksheet2)?;


    //
    // Example 3: Create a worksheet with collapsed outlined rows.
    // Same as the example 1  except that the two sub-totals are collapsed.
    //
    let worksheet3 = workbook.add_worksheet_by_name("Collapsed Rows 2")?;
    worksheet3.set_row_level(2, 2)?;
    worksheet3.hide_row(2)?;
    worksheet3.set_row_level(3, 2)?;
    worksheet3.hide_row(3)?;
    worksheet3.set_row_level(4, 2)?;
    worksheet3.hide_row(4)?;
    worksheet3.set_row_level(5, 2)?;
    worksheet3.hide_row(5)?;
    worksheet3.set_row_level(6, 1)?;
    worksheet3.collapse_row(6)?;
    worksheet3.set_row_level(7, 2)?;
    worksheet3.hide_row(7)?;
    worksheet3.set_row_level(8, 2)?;
    worksheet3.hide_row(8)?;
    worksheet3.set_row_level(9, 2)?;
    worksheet3.hide_row(9)?;
    worksheet3.set_row_level(10, 2)?;
    worksheet3.hide_row(10)?;
    worksheet3.set_row_level(11, 1)?;
    worksheet3.collapse_row(11)?;
    // Write the sub-total data that is common to the row examples.
    create_sub_totals(worksheet3)?;


    //
    // Example 4: Create a worksheet with outlined rows.
    // Same as the example 1  except that the two sub-totals are collapsed.
    //
    let worksheet4 = workbook.add_worksheet_by_name("Collapsed Rows 3")?;
    worksheet4.set_row_level(2, 2)?;
    worksheet4.hide_row(2)?;
    worksheet4.set_row_level(3, 2)?;
    worksheet4.hide_row(3)?;
    worksheet4.set_row_level(4, 2)?;
    worksheet4.hide_row(4)?;
    worksheet4.set_row_level(5, 2)?;
    worksheet4.hide_row(5)?;
    worksheet4.set_row_level(6, 1)?;
    worksheet4.hide_row(6)?;
    worksheet4.collapse_row(6)?;
    worksheet4.set_row_level(7, 2)?;
    worksheet4.hide_row(7)?;
    worksheet4.set_row_level(8, 2)?;
    worksheet4.hide_row(8)?;
    worksheet4.set_row_level(9, 2)?;
    worksheet4.hide_row(9)?;
    worksheet4.set_row_level(10, 2)?;
    worksheet4.hide_row(10)?;
    worksheet4.set_row_level(11, 1)?;
    worksheet4.hide_row(11)?;
    worksheet4.collapse_row(11)?;
    worksheet4.collapse_row(12)?;
    // Write the sub-total data that is common to the row examples.
    create_sub_totals(worksheet4)?;



    //
    // Example 5: Create a worksheet with outlined columns.
    //
    let worksheet5 = workbook.add_worksheet_by_name("Outline Columns")?;
    worksheet5.set_row_with_format(1, 15.0, &bold)?;
    worksheet5.write_row("A1", ["Month", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Total"].iter())?;
    worksheet5.set_column_with_format("A:A", 10.0, &bold)?;
    worksheet5.set_column("B:G", 5.0)?;
    worksheet5.set_column_level("B:G", 1)?;
    worksheet5.set_column("H:H", 10.0)?;
    worksheet5.write_column("A2", ["North", "South", "East", "East"].iter())?;
    worksheet5.write_row("B2", [50, 20, 15, 25, 65, 80].iter())?;
    worksheet5.write_row("B3", [10, 20, 30, 50, 50, 50].iter())?;
    worksheet5.write_row("B4", [45, 75, 50, 15, 75, 100].iter())?;
    worksheet5.write_row("B5", [15, 15, 55, 35, 20, 50].iter())?;
    worksheet5.write_formula("H2", "=SUM(B2:G2)")?;
    worksheet5.write_formula("H3", "=SUM(B3:G3)")?;
    worksheet5.write_formula("H4", "=SUM(B4:G4)")?;
    worksheet5.write_formula("H5", "=SUM(B5:G5)")?;
    worksheet5.write_formula_with_format("H6", "=SUM(H2:H5)", &bold)?;



    //
    // Example 6: Create a worksheet with collapsed outlined columns.
    // This is the same as the previous example except with collapsed columns.
    //
    let worksheet6 = workbook.add_worksheet_by_name("Collapsed Columns")?;
    worksheet6.set_row_with_format(1, 15.0, &bold)?;
    worksheet6.write_row("A1", ["Month", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Total"].iter())?;
    worksheet6.set_column_with_format("A:H", 10.0, &bold)?;
    worksheet6.set_column_level("B:G", 1)?;
    worksheet6.set_column_level("C:F", 2)?;
    worksheet6.set_column_level("D:E", 3)?;
    worksheet6.hide_column("D:E")?;
    worksheet6.collapse_col("D:E")?;
    worksheet6.write_column("A2", ["North", "South", "East", "East"].iter())?;
    worksheet6.write_row("B2", [50, 20, 15, 25, 65, 80].iter())?;
    worksheet6.write_row("B3", [10, 20, 30, 50, 50, 50].iter())?;
    worksheet6.write_row("B4", [45, 75, 50, 15, 75, 100].iter())?;
    worksheet6.write_row("B5", [15, 15, 55, 35, 20, 50].iter())?;
    worksheet6.write_formula("H2", "=SUM(B2:G2)")?;
    worksheet6.write_formula("H3", "=SUM(B3:G3)")?;
    worksheet6.write_formula("H4", "=SUM(B4:G4)")?;
    worksheet6.write_formula("H5", "=SUM(B5:G5)")?;
    worksheet6.write_formula_with_format("H6", "=SUM(H2:H5)", &bold)?;


    workbook.save_as("examples/outline_collapsed.xlsx")?;
    Ok(())
}
examples/outline.rs (line 132)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();
    let worksheet1 = workbook.add_worksheet_by_name("Outlined Rows")?;
    // Add a general format
    let bold = Format::default().set_bold();

    //
    // Example 1: A worksheet with outlined rows. It also includes SUBTOTAL()?;    // functions so that it looks like the type of automatic outlines that are
    // generated when you use the Excel Data->SubTotals menu item.
    //
    // For outlines the important parameters are 'level' and 'hidden'. Rows with
    // the same 'level' are grouped together. The group will be collapsed if
    // 'hidden' is enabled. The parameters 'height' and 'cell_format' are assigned
    // default values if they are None.
    //
    worksheet1.set_row_level(2, 2)?;
    worksheet1.set_row_level(3, 2)?;
    worksheet1.set_row_level(4, 2)?;
    worksheet1.set_row_level(5, 2)?;
    worksheet1.set_row_level(6, 1)?;
    worksheet1.set_row_level(7, 2)?;
    worksheet1.set_row_level(8, 2)?;
    worksheet1.set_row_level(9, 2)?;
    worksheet1.set_row_level(10, 2)?;
    worksheet1.set_row_level(11, 1)?;

    // Adjust the column width for clarity
    worksheet1.set_column("A:A", 20.0)?;

    // Add the data, labels and formulas
    worksheet1.write_with_format("A1", "Region", &bold)?;
    worksheet1.write("A2", "North")?;
    worksheet1.write("A3", "North")?;
    worksheet1.write("A4", "North")?;
    worksheet1.write("A5", "North")?;
    worksheet1.write_with_format("A6", "North Total", &bold)?;

    worksheet1.write_with_format("B1", "Sales", &bold)?;
    worksheet1.write("B2", 1000)?;
    worksheet1.write("B3", 1200)?;
    worksheet1.write("B4", 900)?;
    worksheet1.write("B5", 1200)?;
    worksheet1.write_formula_with_format("B6", "=SUBTOTAL(9,B2:B5)", &bold)?;
    worksheet1.write("A7", "South")?;
    worksheet1.write("A8", "South")?;
    worksheet1.write("A9", "South")?;
    worksheet1.write("A10", "South")?;
    worksheet1.write_with_format("A11", "South Total", &bold)?;
    worksheet1.write("B7", 400)?;
    worksheet1.write("B8", 600)?;
    worksheet1.write("B9", 500)?;
    worksheet1.write("B10", 600)?;
    worksheet1.write_formula_with_format("B11", "=SUBTOTAL(9,B7:B10)", &bold)?;
    worksheet1.write_with_format("A12", "Grand Total", &bold)?;
    worksheet1.write_formula_with_format("B12", "=SUBTOTAL(9,B2:B10)", &bold)?;


    //
    // Example 2: A worksheet with outlined rows. This is the same as the
    // previous example except that the rows are collapsed.
    // Note: We need to indicate the rows that contains the collapsed symbol '+'
    // with the optional parameter, 'collapsed'. The group will be then be
    // collapsed if 'hidden' is True.
    //
    let worksheet2 = workbook.add_worksheet_by_name("Collapsed Rows")?;
    worksheet2.set_row_level(2, 2)?;
    worksheet2.hide_row(2)?;
    worksheet2.set_row_level(3, 2)?;
    worksheet2.hide_row(3)?;
    worksheet2.set_row_level(4, 2)?;
    worksheet2.hide_row(4)?;
    worksheet2.set_row_level(5, 2)?;
    worksheet2.hide_row(5)?;
    worksheet2.set_row_level(6, 1)?;
    worksheet2.hide_row(6)?;
    worksheet2.set_row_level(7, 2)?;
    worksheet2.hide_row(7)?;
    worksheet2.set_row_level(8, 2)?;
    worksheet2.hide_row(8)?;
    worksheet2.set_row_level(9, 2)?;
    worksheet2.hide_row(9)?;
    worksheet2.set_row_level(10, 2)?;
    worksheet2.hide_row(10)?;
    worksheet2.set_row_level(11, 1)?;
    worksheet2.hide_row(11)?;
    worksheet2.collapse_row(12)?;

    // Adjust the column width for clarity
    worksheet2.set_column("A:A", 20.0)?;

    // Add the data, labels and formulas
    worksheet2.write_with_format("A1", "Region", &bold)?;
    worksheet2.write("A2", "North")?;
    worksheet2.write("A3", "North")?;
    worksheet2.write("A4", "North")?;
    worksheet2.write("A5", "North")?;
    worksheet2.write_with_format("A6", "North Total", &bold)?;

    worksheet2.write_with_format("B1", "Sales", &bold)?;
    worksheet2.write("B2", 1000)?;
    worksheet2.write("B3", 1200)?;
    worksheet2.write("B4", 900)?;
    worksheet2.write("B5", 1200)?;
    worksheet2.write_formula_with_format("B6", "=SUBTOTAL(9,B2:B5)", &bold)?;
    worksheet2.write("A7", "South")?;
    worksheet2.write("A8", "South")?;
    worksheet2.write("A9", "South")?;
    worksheet2.write("A10", "South")?;
    worksheet2.write_with_format("A11", "South Total", &bold)?;
    worksheet2.write("B7", 400)?;
    worksheet2.write("B8", 600)?;
    worksheet2.write("B9", 500)?;
    worksheet2.write("B10", 600)?;
    worksheet2.write_formula_with_format("B11", "=SUBTOTAL(9,B7:B10)", &bold)?;
    worksheet2.write_with_format("A12", "Grand Total", &bold)?;
    worksheet2.write_formula_with_format("B12", "=SUBTOTAL(9,B2:B10)", &bold)?;

    //
    // Example 3: Create a worksheet with outlined columns.
    //
    let worksheet3 = workbook.add_worksheet_by_name("Outline Columns")?;
    // Add bold format to the first row.
    worksheet3.set_row_with_format(1, 15.0, &bold)?;
    worksheet3.write_row("A1", ["Month", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Total"].iter())?;
    worksheet3.set_column_with_format("A:A", 10.0, &bold)?;
    worksheet3.set_column("B:G", 10.0)?;
    worksheet3.set_column_level("B:G", 1)?;
    worksheet3.set_column("H:H", 10.0)?;
    worksheet3.write_column("A2", ["North", "South", "East", "East"].iter())?;
    worksheet3.write_row("B2", [50, 20, 15, 25, 65, 80].iter())?;
    worksheet3.write_row("B3", [10, 20, 30, 50, 50, 50].iter())?;
    worksheet3.write_row("B4", [45, 75, 50, 15, 75, 100].iter())?;
    worksheet3.write_row("B5", [15, 15, 55, 35, 20, 50].iter())?;
    worksheet3.write_formula("H2", "=SUM(B2:G2)")?;
    worksheet3.write_formula("H3", "=SUM(B3:G3)")?;
    worksheet3.write_formula("H4", "=SUM(B4:G4)")?;
    worksheet3.write_formula("H5", "=SUM(B5:G5)")?;
    worksheet3.write_formula_with_format("H6", "=SUM(H2:H5)", &bold)?;

    //
    // Example 4: Show all possible outline levels.
    //
    let levels = [
        "Level 1",
        "Level 2",
        "Level 3",
        "Level 4",
        "Level 5",
        "Level 6",
        "Level 7",
        "Level 6",
        "Level 5",
        "Level 4",
        "Level 3",
        "Level 2",
        "Level 1",
    ];
    let worksheet4 = workbook.add_worksheet_by_name("Outline levels")?;
    worksheet4.write_column("A1", levels.iter())?;

    worksheet4.set_row_level(1, 1)?;
    worksheet4.set_row_level(2, 2)?;
    worksheet4.set_row_level(3, 3)?;
    worksheet4.set_row_level(4, 4)?;
    worksheet4.set_row_level(5, 5)?;
    worksheet4.set_row_level(6, 6)?;
    worksheet4.set_row_level(7, 7)?;
    worksheet4.set_row_level(8, 6)?;
    worksheet4.set_row_level(9, 5)?;
    worksheet4.set_row_level(10, 4)?;
    worksheet4.set_row_level(11, 3)?;
    worksheet4.set_row_level(12, 2)?;
    worksheet4.set_row_level(13, 1)?;

    workbook.save_as("examples/outline.xlsx")?;
    Ok(())
}
source

fn write_url<L: Location>(&mut self, loc: L, url: &str) -> WorkSheetResult<()>

source

fn write_url_text<L: Location>( &mut self, loc: L, url: &str, data: &str ) -> WorkSheetResult<()>

source

fn merge_range<L: LocationRange, T: CellDisplay + CellValue>( &mut self, loc: L, data: T ) -> WorkSheetResult<()>

source

fn write_formula<L: Location>( &mut self, loc: L, data: &str ) -> WorkSheetResult<()>

Examples found in repository?
examples/array_formula.rs (line 20)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();
    // Use the default worksheet
    let worksheet = workbook.get_worksheet(1)?;
    // Write some test data.
    worksheet.write("B1", 500)?;
    worksheet.write("B2", 10)?;
    worksheet.write("B5", 1)?;
    worksheet.write("B6", 2)?;
    worksheet.write("B7", 3)?;
    worksheet.write("C1", 300)?;
    worksheet.write("C2", 15)?;
    worksheet.write("C5", 20234)?;
    worksheet.write("C6", 21003)?;
    worksheet.write("C7", 10000)?;
    // Write an array formula that returns a single value
    worksheet.write_formula("A1", "_xlfn.SUM(B1:C1*B2:C2)")?;
    // Same as above but more verbose.
    worksheet.write_array_formula("A2", "_xlfn.SUM(B1:C1*B2:C2)")?;
    // Write an array formula that returns a range of values
    worksheet.write_array_formula("A5", "_xlfn.TREND(C5:C7,B5:B7)")?;

    workbook.save_as("examples/array_formula.xlsx")?;
    Ok(())
}
More examples
Hide additional examples
examples/ignore_errors.rs (line 13)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn main() -> WorkbookResult<()> {
    let mut workbook = Workbook::new();
    let worksheet = workbook.get_worksheet(1)?;

    // Write strings that looks like numbers. This will cause an Excel warning.
    worksheet.write_string("C2", "123".to_string())?;
    worksheet.write_string("C3", "123".to_string())?;

    // Write a divide by zero formula. This will also cause an Excel warning.
    worksheet.write_formula("C5", "=1/0")?;
    worksheet.write_formula("C6", "=1/0")?;

    // Turn off some of the warnings:
    let mut error_map = HashMap::new();
    error_map.insert("number_stored_as_text", "C3");
    error_map.insert("eval_error", "C6");
    worksheet.ignore_errors(error_map);

    // Write some descriptions for the cells and make the column wider for clarity.
    worksheet.set_column("B:B", 16.0)?;
    worksheet.write("B2", "Warning:")?;
    worksheet.write("B3", "Warning turned off:")?;
    worksheet.write("B5", "Warning:")?;
    worksheet.write("B6", "Warning turned off:")?;

    workbook.save_as("examples/ignore_errors.xlsx")?;
    Ok(())
}
examples/lambda.rs (line 13)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();
    let worksheet = workbook.get_worksheet(1)?;


    // Write a Lambda function to convert Fahrenheit to Celsius to a cell.
    //
    // Note that the lambda function parameters must be prefixed with
    // "_xlpm.". These prefixes won't show up in Excel.
    worksheet.write_formula("A1", "_xlfn.LAMBDA(_xlpm.a, _xlpm.b, SQRT((_xlpm.a^2+_xlpm.b^2)))(3, 4)")?;


    // The user defined name needs to be written explicitly as a dynamic array
    // formula.
    let a = 6;
    let b = 8;
    worksheet.write_formula("A2", &format!("=HYPOTENUSE({a}, {b})"))?;

    // Create the same formula (without an argument) as a defined name and use that
    // to calculate a value.
    //
    // Note that the formula name is prefixed with "_xlfn." (this is normally
    // converted automatically by write_formula() but isn't for defined names)
    // and note that the lambda function parameters are prefixed with
    // "_xlpm.". These prefixes won't show up in Excel.
    workbook.define_name("HYPOTENUSE", "_xlfn.LAMBDA(_xlpm.a, _xlpm.b, SQRT((_xlpm.a^2+_xlpm.b^2)))")?;


    workbook.save_as("examples/lambda.xlsx")?;
    Ok(())
}
examples/defined_name.rs (line 22)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();
    workbook.add_worksheet()?;

    // Define some global/workbook names.
    workbook.define_name("Exchange_rate", "0.96")?;
    workbook.define_name("Sales", "Sheet1!$G$1:$H$10")?;
    // Define a local/worksheet name. Over-rides the "Sales" name above.
    workbook.define_local_name("Sales", "Sheet2!$G$1:$G$10", 2)?;

    // Write some text in the file and one of the defined names in a formula.
    let sales = ["Apple", "Grape", "Pear", "Banana", "Apple", "Grape", "Pear", "Banana", "Banana", "Pear"];
    let units = [10, 12, 32, 16, 13, 50, 25, 8, 33, 95];
    for worksheet in workbook.worksheets() {
        worksheet.set_column("A:B", 40.0)?;
        worksheet.set_column("F:F", 40.0)?;
        worksheet.write("A1", "This worksheet contains some defined names.")?;
        worksheet.write("B1", "Show defined name Sales on the right->")?;
        worksheet.write_formula("C1", "=Sales")?;
        worksheet.write("A2", "See Formulas -> Name Manager above.")?;
        worksheet.write("A3", "Example formula in cell B3 ->")?;
        worksheet.write_formula("B3", "=Exchange_rate")?;
        worksheet.write("F1", "Fill in some arrays on the right->")?;
        worksheet.write_column("G1", sales.iter())?;
        worksheet.write_column("H1", units.iter())?;
    }

    workbook.save_as("examples/defined_name.xlsx")?;
    Ok(())
}
examples/outline_collapsed.rs (line 138)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();
    // Add a general format
    let bold = Format::default().set_bold();

    //
    // Example 1: A worksheet with outlined rows. It also includes SUBTOTAL()
    // functions so that it looks like the type of automatic outlines that are
    // generated when you use the Excel Data->SubTotals menu item.
    //
    let worksheet1 = workbook.add_worksheet_by_name("Outlined Rows")?;
    worksheet1.set_row_level(2, 2)?;
    worksheet1.set_row_level(3, 2)?;
    worksheet1.set_row_level(4, 2)?;
    worksheet1.set_row_level(5, 2)?;
    worksheet1.set_row_level(6, 1)?;
    worksheet1.set_row_level(7, 2)?;
    worksheet1.set_row_level(8, 2)?;
    worksheet1.set_row_level(9, 2)?;
    worksheet1.set_row_level(10, 2)?;
    worksheet1.set_row_level(11, 1)?;
    create_sub_totals(worksheet1)?;

    //
    // Example 2: Create a worksheet with collapsed outlined rows.
    // This is the same as the example 1  except that the all rows are collapsed.
    // Note: We need to indicate the rows that contains the collapsed symbol '+'
    // with the optional parameter, 'collapsed'.
    //
    let worksheet2 = workbook.add_worksheet_by_name("Collapsed Rows 1")?;
    worksheet2.set_row_level(2, 2)?;
    worksheet2.hide_row(2)?;
    worksheet2.set_row_level(3, 2)?;
    worksheet2.hide_row(3)?;
    worksheet2.set_row_level(4, 2)?;
    worksheet2.hide_row(4)?;
    worksheet2.set_row_level(5, 2)?;
    worksheet2.hide_row(5)?;
    worksheet2.set_row_level(6, 1)?;
    worksheet2.hide_row(6)?;
    worksheet2.set_row_level(7, 2)?;
    worksheet2.hide_row(7)?;
    worksheet2.set_row_level(8, 2)?;
    worksheet2.hide_row(8)?;
    worksheet2.set_row_level(9, 2)?;
    worksheet2.hide_row(9)?;
    worksheet2.set_row_level(10, 2)?;
    worksheet2.hide_row(10)?;
    worksheet2.set_row_level(11, 1)?;
    worksheet2.hide_row(11)?;

    worksheet2.collapse_row(12)?;

    // Write the sub-total data that is common to the row examples.
    create_sub_totals(worksheet2)?;


    //
    // Example 3: Create a worksheet with collapsed outlined rows.
    // Same as the example 1  except that the two sub-totals are collapsed.
    //
    let worksheet3 = workbook.add_worksheet_by_name("Collapsed Rows 2")?;
    worksheet3.set_row_level(2, 2)?;
    worksheet3.hide_row(2)?;
    worksheet3.set_row_level(3, 2)?;
    worksheet3.hide_row(3)?;
    worksheet3.set_row_level(4, 2)?;
    worksheet3.hide_row(4)?;
    worksheet3.set_row_level(5, 2)?;
    worksheet3.hide_row(5)?;
    worksheet3.set_row_level(6, 1)?;
    worksheet3.collapse_row(6)?;
    worksheet3.set_row_level(7, 2)?;
    worksheet3.hide_row(7)?;
    worksheet3.set_row_level(8, 2)?;
    worksheet3.hide_row(8)?;
    worksheet3.set_row_level(9, 2)?;
    worksheet3.hide_row(9)?;
    worksheet3.set_row_level(10, 2)?;
    worksheet3.hide_row(10)?;
    worksheet3.set_row_level(11, 1)?;
    worksheet3.collapse_row(11)?;
    // Write the sub-total data that is common to the row examples.
    create_sub_totals(worksheet3)?;


    //
    // Example 4: Create a worksheet with outlined rows.
    // Same as the example 1  except that the two sub-totals are collapsed.
    //
    let worksheet4 = workbook.add_worksheet_by_name("Collapsed Rows 3")?;
    worksheet4.set_row_level(2, 2)?;
    worksheet4.hide_row(2)?;
    worksheet4.set_row_level(3, 2)?;
    worksheet4.hide_row(3)?;
    worksheet4.set_row_level(4, 2)?;
    worksheet4.hide_row(4)?;
    worksheet4.set_row_level(5, 2)?;
    worksheet4.hide_row(5)?;
    worksheet4.set_row_level(6, 1)?;
    worksheet4.hide_row(6)?;
    worksheet4.collapse_row(6)?;
    worksheet4.set_row_level(7, 2)?;
    worksheet4.hide_row(7)?;
    worksheet4.set_row_level(8, 2)?;
    worksheet4.hide_row(8)?;
    worksheet4.set_row_level(9, 2)?;
    worksheet4.hide_row(9)?;
    worksheet4.set_row_level(10, 2)?;
    worksheet4.hide_row(10)?;
    worksheet4.set_row_level(11, 1)?;
    worksheet4.hide_row(11)?;
    worksheet4.collapse_row(11)?;
    worksheet4.collapse_row(12)?;
    // Write the sub-total data that is common to the row examples.
    create_sub_totals(worksheet4)?;



    //
    // Example 5: Create a worksheet with outlined columns.
    //
    let worksheet5 = workbook.add_worksheet_by_name("Outline Columns")?;
    worksheet5.set_row_with_format(1, 15.0, &bold)?;
    worksheet5.write_row("A1", ["Month", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Total"].iter())?;
    worksheet5.set_column_with_format("A:A", 10.0, &bold)?;
    worksheet5.set_column("B:G", 5.0)?;
    worksheet5.set_column_level("B:G", 1)?;
    worksheet5.set_column("H:H", 10.0)?;
    worksheet5.write_column("A2", ["North", "South", "East", "East"].iter())?;
    worksheet5.write_row("B2", [50, 20, 15, 25, 65, 80].iter())?;
    worksheet5.write_row("B3", [10, 20, 30, 50, 50, 50].iter())?;
    worksheet5.write_row("B4", [45, 75, 50, 15, 75, 100].iter())?;
    worksheet5.write_row("B5", [15, 15, 55, 35, 20, 50].iter())?;
    worksheet5.write_formula("H2", "=SUM(B2:G2)")?;
    worksheet5.write_formula("H3", "=SUM(B3:G3)")?;
    worksheet5.write_formula("H4", "=SUM(B4:G4)")?;
    worksheet5.write_formula("H5", "=SUM(B5:G5)")?;
    worksheet5.write_formula_with_format("H6", "=SUM(H2:H5)", &bold)?;



    //
    // Example 6: Create a worksheet with collapsed outlined columns.
    // This is the same as the previous example except with collapsed columns.
    //
    let worksheet6 = workbook.add_worksheet_by_name("Collapsed Columns")?;
    worksheet6.set_row_with_format(1, 15.0, &bold)?;
    worksheet6.write_row("A1", ["Month", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Total"].iter())?;
    worksheet6.set_column_with_format("A:H", 10.0, &bold)?;
    worksheet6.set_column_level("B:G", 1)?;
    worksheet6.set_column_level("C:F", 2)?;
    worksheet6.set_column_level("D:E", 3)?;
    worksheet6.hide_column("D:E")?;
    worksheet6.collapse_col("D:E")?;
    worksheet6.write_column("A2", ["North", "South", "East", "East"].iter())?;
    worksheet6.write_row("B2", [50, 20, 15, 25, 65, 80].iter())?;
    worksheet6.write_row("B3", [10, 20, 30, 50, 50, 50].iter())?;
    worksheet6.write_row("B4", [45, 75, 50, 15, 75, 100].iter())?;
    worksheet6.write_row("B5", [15, 15, 55, 35, 20, 50].iter())?;
    worksheet6.write_formula("H2", "=SUM(B2:G2)")?;
    worksheet6.write_formula("H3", "=SUM(B3:G3)")?;
    worksheet6.write_formula("H4", "=SUM(B4:G4)")?;
    worksheet6.write_formula("H5", "=SUM(B5:G5)")?;
    worksheet6.write_formula_with_format("H6", "=SUM(H2:H5)", &bold)?;


    workbook.save_as("examples/outline_collapsed.xlsx")?;
    Ok(())
}
examples/outline.rs (line 137)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();
    let worksheet1 = workbook.add_worksheet_by_name("Outlined Rows")?;
    // Add a general format
    let bold = Format::default().set_bold();

    //
    // Example 1: A worksheet with outlined rows. It also includes SUBTOTAL()?;    // functions so that it looks like the type of automatic outlines that are
    // generated when you use the Excel Data->SubTotals menu item.
    //
    // For outlines the important parameters are 'level' and 'hidden'. Rows with
    // the same 'level' are grouped together. The group will be collapsed if
    // 'hidden' is enabled. The parameters 'height' and 'cell_format' are assigned
    // default values if they are None.
    //
    worksheet1.set_row_level(2, 2)?;
    worksheet1.set_row_level(3, 2)?;
    worksheet1.set_row_level(4, 2)?;
    worksheet1.set_row_level(5, 2)?;
    worksheet1.set_row_level(6, 1)?;
    worksheet1.set_row_level(7, 2)?;
    worksheet1.set_row_level(8, 2)?;
    worksheet1.set_row_level(9, 2)?;
    worksheet1.set_row_level(10, 2)?;
    worksheet1.set_row_level(11, 1)?;

    // Adjust the column width for clarity
    worksheet1.set_column("A:A", 20.0)?;

    // Add the data, labels and formulas
    worksheet1.write_with_format("A1", "Region", &bold)?;
    worksheet1.write("A2", "North")?;
    worksheet1.write("A3", "North")?;
    worksheet1.write("A4", "North")?;
    worksheet1.write("A5", "North")?;
    worksheet1.write_with_format("A6", "North Total", &bold)?;

    worksheet1.write_with_format("B1", "Sales", &bold)?;
    worksheet1.write("B2", 1000)?;
    worksheet1.write("B3", 1200)?;
    worksheet1.write("B4", 900)?;
    worksheet1.write("B5", 1200)?;
    worksheet1.write_formula_with_format("B6", "=SUBTOTAL(9,B2:B5)", &bold)?;
    worksheet1.write("A7", "South")?;
    worksheet1.write("A8", "South")?;
    worksheet1.write("A9", "South")?;
    worksheet1.write("A10", "South")?;
    worksheet1.write_with_format("A11", "South Total", &bold)?;
    worksheet1.write("B7", 400)?;
    worksheet1.write("B8", 600)?;
    worksheet1.write("B9", 500)?;
    worksheet1.write("B10", 600)?;
    worksheet1.write_formula_with_format("B11", "=SUBTOTAL(9,B7:B10)", &bold)?;
    worksheet1.write_with_format("A12", "Grand Total", &bold)?;
    worksheet1.write_formula_with_format("B12", "=SUBTOTAL(9,B2:B10)", &bold)?;


    //
    // Example 2: A worksheet with outlined rows. This is the same as the
    // previous example except that the rows are collapsed.
    // Note: We need to indicate the rows that contains the collapsed symbol '+'
    // with the optional parameter, 'collapsed'. The group will be then be
    // collapsed if 'hidden' is True.
    //
    let worksheet2 = workbook.add_worksheet_by_name("Collapsed Rows")?;
    worksheet2.set_row_level(2, 2)?;
    worksheet2.hide_row(2)?;
    worksheet2.set_row_level(3, 2)?;
    worksheet2.hide_row(3)?;
    worksheet2.set_row_level(4, 2)?;
    worksheet2.hide_row(4)?;
    worksheet2.set_row_level(5, 2)?;
    worksheet2.hide_row(5)?;
    worksheet2.set_row_level(6, 1)?;
    worksheet2.hide_row(6)?;
    worksheet2.set_row_level(7, 2)?;
    worksheet2.hide_row(7)?;
    worksheet2.set_row_level(8, 2)?;
    worksheet2.hide_row(8)?;
    worksheet2.set_row_level(9, 2)?;
    worksheet2.hide_row(9)?;
    worksheet2.set_row_level(10, 2)?;
    worksheet2.hide_row(10)?;
    worksheet2.set_row_level(11, 1)?;
    worksheet2.hide_row(11)?;
    worksheet2.collapse_row(12)?;

    // Adjust the column width for clarity
    worksheet2.set_column("A:A", 20.0)?;

    // Add the data, labels and formulas
    worksheet2.write_with_format("A1", "Region", &bold)?;
    worksheet2.write("A2", "North")?;
    worksheet2.write("A3", "North")?;
    worksheet2.write("A4", "North")?;
    worksheet2.write("A5", "North")?;
    worksheet2.write_with_format("A6", "North Total", &bold)?;

    worksheet2.write_with_format("B1", "Sales", &bold)?;
    worksheet2.write("B2", 1000)?;
    worksheet2.write("B3", 1200)?;
    worksheet2.write("B4", 900)?;
    worksheet2.write("B5", 1200)?;
    worksheet2.write_formula_with_format("B6", "=SUBTOTAL(9,B2:B5)", &bold)?;
    worksheet2.write("A7", "South")?;
    worksheet2.write("A8", "South")?;
    worksheet2.write("A9", "South")?;
    worksheet2.write("A10", "South")?;
    worksheet2.write_with_format("A11", "South Total", &bold)?;
    worksheet2.write("B7", 400)?;
    worksheet2.write("B8", 600)?;
    worksheet2.write("B9", 500)?;
    worksheet2.write("B10", 600)?;
    worksheet2.write_formula_with_format("B11", "=SUBTOTAL(9,B7:B10)", &bold)?;
    worksheet2.write_with_format("A12", "Grand Total", &bold)?;
    worksheet2.write_formula_with_format("B12", "=SUBTOTAL(9,B2:B10)", &bold)?;

    //
    // Example 3: Create a worksheet with outlined columns.
    //
    let worksheet3 = workbook.add_worksheet_by_name("Outline Columns")?;
    // Add bold format to the first row.
    worksheet3.set_row_with_format(1, 15.0, &bold)?;
    worksheet3.write_row("A1", ["Month", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Total"].iter())?;
    worksheet3.set_column_with_format("A:A", 10.0, &bold)?;
    worksheet3.set_column("B:G", 10.0)?;
    worksheet3.set_column_level("B:G", 1)?;
    worksheet3.set_column("H:H", 10.0)?;
    worksheet3.write_column("A2", ["North", "South", "East", "East"].iter())?;
    worksheet3.write_row("B2", [50, 20, 15, 25, 65, 80].iter())?;
    worksheet3.write_row("B3", [10, 20, 30, 50, 50, 50].iter())?;
    worksheet3.write_row("B4", [45, 75, 50, 15, 75, 100].iter())?;
    worksheet3.write_row("B5", [15, 15, 55, 35, 20, 50].iter())?;
    worksheet3.write_formula("H2", "=SUM(B2:G2)")?;
    worksheet3.write_formula("H3", "=SUM(B3:G3)")?;
    worksheet3.write_formula("H4", "=SUM(B4:G4)")?;
    worksheet3.write_formula("H5", "=SUM(B5:G5)")?;
    worksheet3.write_formula_with_format("H6", "=SUM(H2:H5)", &bold)?;

    //
    // Example 4: Show all possible outline levels.
    //
    let levels = [
        "Level 1",
        "Level 2",
        "Level 3",
        "Level 4",
        "Level 5",
        "Level 6",
        "Level 7",
        "Level 6",
        "Level 5",
        "Level 4",
        "Level 3",
        "Level 2",
        "Level 1",
    ];
    let worksheet4 = workbook.add_worksheet_by_name("Outline levels")?;
    worksheet4.write_column("A1", levels.iter())?;

    worksheet4.set_row_level(1, 1)?;
    worksheet4.set_row_level(2, 2)?;
    worksheet4.set_row_level(3, 3)?;
    worksheet4.set_row_level(4, 4)?;
    worksheet4.set_row_level(5, 5)?;
    worksheet4.set_row_level(6, 6)?;
    worksheet4.set_row_level(7, 7)?;
    worksheet4.set_row_level(8, 6)?;
    worksheet4.set_row_level(9, 5)?;
    worksheet4.set_row_level(10, 4)?;
    worksheet4.set_row_level(11, 3)?;
    worksheet4.set_row_level(12, 2)?;
    worksheet4.set_row_level(13, 1)?;

    workbook.save_as("examples/outline.xlsx")?;
    Ok(())
}
source

fn write_array_formula<L: Location>( &mut self, loc: L, data: &str ) -> WorkSheetResult<()>

Examples found in repository?
examples/array_formula.rs (line 22)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();
    // Use the default worksheet
    let worksheet = workbook.get_worksheet(1)?;
    // Write some test data.
    worksheet.write("B1", 500)?;
    worksheet.write("B2", 10)?;
    worksheet.write("B5", 1)?;
    worksheet.write("B6", 2)?;
    worksheet.write("B7", 3)?;
    worksheet.write("C1", 300)?;
    worksheet.write("C2", 15)?;
    worksheet.write("C5", 20234)?;
    worksheet.write("C6", 21003)?;
    worksheet.write("C7", 10000)?;
    // Write an array formula that returns a single value
    worksheet.write_formula("A1", "_xlfn.SUM(B1:C1*B2:C2)")?;
    // Same as above but more verbose.
    worksheet.write_array_formula("A2", "_xlfn.SUM(B1:C1*B2:C2)")?;
    // Write an array formula that returns a range of values
    worksheet.write_array_formula("A5", "_xlfn.TREND(C5:C7,B5:B7)")?;

    workbook.save_as("examples/array_formula.xlsx")?;
    Ok(())
}
source

fn write_dynamic_array_formula<L: Location>( &mut self, loc: L, data: &str ) -> WorkSheetResult<()>

Examples found in repository?
examples/dynamic_arrays.rs (line 168)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
fn main() -> WorkbookResult<()> {
    // Create a new workbook called simple.xls and add some worksheets.
    let mut workbook = Workbook::new();
    let header1 = Format::default()
        .set_color(FormatColor::RGB("00ffffff"))
        .set_background_color(FormatColor::RGB("0074AC4C"));
    let header2 = Format::default()
        .set_color(FormatColor::RGB("00ffffff"))
        .set_background_color(FormatColor::RGB("00528FD3"));

    //
    // Example of using the FILTER() function.
    //
    let worksheet1 = workbook.add_worksheet_by_name("Filter")?;
    worksheet1.write_formula("F2", "_xlfn.FILTER(A1:D17,C1:C17=K2)")?;

    // Write the data the function will work on.
    worksheet1.write_with_format("K1", "Product", &header2)?;
    worksheet1.write("K2", "Apple")?;
    worksheet1.write_with_format("F1", "Region", &header2)?;
    worksheet1.write_with_format("G1", "Sales Rep", &header2)?;
    worksheet1.write_with_format("H1", "Product", &header2)?;
    worksheet1.write_with_format("I1", "Units", &header2)?;

    write_worksheet_data(worksheet1, &header1)?;
    worksheet1.set_column_pixels("E:E", 10.0)?;
    worksheet1.set_column_pixels("J:J", 10.0)?;

    //
    // Example of using the UNIQUE() function.
    //
    let worksheet2 = workbook.add_worksheet_by_name("Unique")?;
    worksheet2.write_formula("F2", "_xlfn.UNIQUE(B2:B17)")?;

    // A more complex example combining SORT and UNIQUE.
    worksheet2.write_formula("H2", "_xlfn.SORT(_xlfn.UNIQUE(B2:B17))")?;

    // Write the data the function will work on.
    worksheet2.write_with_format("F1", "Sales Rep", &header2)?;
    worksheet2.write_with_format("H1", "Sales Rep", &header2)?;

    write_worksheet_data(worksheet2, &header1)?;
    worksheet2.set_column_pixels("E:E", 10.0)?;
    worksheet2.set_column_pixels("G:G", 10.0)?;

    //
    // Example of using the SORT() function.
    //
    let worksheet3 = workbook.add_worksheet_by_name("Sort")?;
    worksheet3.write_formula("F2", "_xlfn.SORT(B2:B17)")?;

    // A more complex example combining SORT and FILTER.
    worksheet3.write_formula("H2", "_xlfn.SORT(_xlfn.FILTER(C2: D17, D2: D17 > 5000, \"\"), 2, 1)")?;

    // Write the data the function will work on.
    worksheet3.write_with_format("F1", "Sales Rep", &header2)?;
    worksheet3.write_with_format("H1", "Product", &header2)?;
    worksheet3.write_with_format("I1", "Units", &header2)?;

    write_worksheet_data(worksheet3, &header1)?;
    worksheet3.set_column_pixels("E:E", 10.0)?;
    worksheet3.set_column_pixels("G:G", 10.0)?;


    //
    // Example of using the SORTBY() function.
    //
    let worksheet4 = workbook.add_worksheet_by_name("Sortby")?;
    worksheet4.write_formula("D2", "_xlfn.SORTBY(A2:B9,B2:B9)")?;

    // Write the data the function will work on.
    worksheet4.write_with_format("A1", "Name", &header1)?;
    worksheet4.write_with_format("B1", "Age", &header1)?;

    worksheet4.write("A2", "Tom")?;
    worksheet4.write("A3", "Fred")?;
    worksheet4.write("A4", "Amy")?;
    worksheet4.write("A5", "Sal")?;
    worksheet4.write("A6", "Fritz")?;
    worksheet4.write("A7", "Srivan")?;
    worksheet4.write("A8", "Xi")?;
    worksheet4.write("A9", "Hector")?;

    worksheet4.write("B2", 52)?;
    worksheet4.write("B3", 65)?;
    worksheet4.write("B4", 22)?;
    worksheet4.write("B5", 73)?;
    worksheet4.write("B6", 19)?;
    worksheet4.write("B7", 39)?;
    worksheet4.write("B8", 19)?;
    worksheet4.write("B9", 66)?;

    worksheet4.write_with_format("D1", "Name", &header2)?;
    worksheet4.write_with_format("E1", "Age", &header2)?;

    worksheet4.set_column_pixels("C:C", 10.0)?;

    //
    // Example of using the XLOOKUP() function.
    //
    let worksheet5 = workbook.add_worksheet_by_name("Xlookup")?;
    worksheet5.write_formula("F1", "_xlfn.XLOOKUP(E1,A2:A9,C2:C9)")?;

    // Write the data the function will work on.
    worksheet5.write_with_format("A1", "Country", &header1)?;
    worksheet5.write_with_format("B1", "Abr", &header1)?;
    worksheet5.write_with_format("C1", "Prefix", &header1)?;

    worksheet5.write("A2", "China")?;
    worksheet5.write("A3", "India")?;
    worksheet5.write("A4", "United States")?;
    worksheet5.write("A5", "Indonesia")?;
    worksheet5.write("A6", "Brazil")?;
    worksheet5.write("A7", "Pakistan")?;
    worksheet5.write("A8", "Nigeria")?;
    worksheet5.write("A9", "Bangladesh")?;

    worksheet5.write("B2", "CN")?;
    worksheet5.write("B3", "IN")?;
    worksheet5.write("B4", "US")?;
    worksheet5.write("B5", "ID")?;
    worksheet5.write("B6", "BR")?;
    worksheet5.write("B7", "PK")?;
    worksheet5.write("B8", "NG")?;
    worksheet5.write("B9", "BD")?;

    worksheet5.write("C2", 86)?;
    worksheet5.write("C3", 91)?;
    worksheet5.write("C4", 1)?;
    worksheet5.write("C5", 62)?;
    worksheet5.write("C6", 55)?;
    worksheet5.write("C7", 92)?;
    worksheet5.write("C8", 234)?;
    worksheet5.write("C9", 880)?;

    worksheet5.write_with_format("E1", "Brazil", &header2)?;

    worksheet5.set_column_pixels("A:A", 100.0)?;
    worksheet5.set_column_pixels("D:D", 10.0)?;

    //
    // Example of using the XMATCH() function.
    //
    let worksheet6 = workbook.add_worksheet_by_name("Xmatch")?;
    worksheet6.write_formula("D2", "_xlfn.XMATCH(C2,A2:A6)")?;

    // Write the data the function will work on.
    worksheet6.write_with_format("A1", "Product", &header1)?;

    worksheet6.write("A2", "Apple")?;
    worksheet6.write("A3", "Grape")?;
    worksheet6.write("A4", "Pear")?;
    worksheet6.write("A5", "Banana")?;
    worksheet6.write("A6", "Cherry")?;

    worksheet6.write_with_format("C1", "Product", &header2)?;
    worksheet6.write_with_format("D1", "Position", &header2)?;
    worksheet6.write("C2", "Grape")?;

    worksheet6.set_column_pixels("B:B", 10.0)?;

    //
    // Example of using the RANDARRAY() function.
    //
    let worksheet7 = workbook.add_worksheet_by_name("Randarray")?;
    worksheet7.write_dynamic_array_formula("A1", "_xlfn.RANDARRAY(5,3,1,100, TRUE)")?;

    //
    // Example of using the SEQUENCE() function.
    //
    let worksheet8 = workbook.add_worksheet_by_name("Sequence")?;
    worksheet8.write_dynamic_array_formula("A1", "_xlfn.SEQUENCE(4,5)")?;

    //
    // Example of using the Spill range operator.
    //
    let worksheet9 = workbook.add_worksheet_by_name("Spill ranges")?;
    worksheet9.write_dynamic_array_formula("H2", "_xlfn.ANCHORARRAY(F2)")?;

    worksheet9.write_dynamic_array_formula("J2", "_xlfn.COUNTA(_xlfn.ANCHORARRAY(F2))")?;

    // Write the data the to work on.
    worksheet9.write_dynamic_array_formula("F2", "_xlfn.UNIQUE(B2:B17)")?;
    worksheet9.write_with_format("F1", "Unique", &header2)?;
    worksheet9.write_with_format("H1", "Spill", &header2)?;
    worksheet9.write_with_format("J1", "Spill", &header2)?;

    write_worksheet_data(worksheet9, &header1)?;
    worksheet9.set_column_pixels("E:E", 10.0)?;
    worksheet9.set_column_pixels("G:G", 10.0)?;
    worksheet9.set_column_pixels("I:I", 10.0)?;

    //
    // Example of using dynamic ranges with older Excel functions.
    //
    let worksheet10 = workbook.add_worksheet_by_name("Older functions")?;
    worksheet10.write_dynamic_array_formula("B1", "=LEN(A1:A3)")?;

    // Write the data the to work on.
    worksheet10.write("A1", "Foo")?;
    worksheet10.write("A2", "Food")?;
    worksheet10.write("A3", "Frood")?;


    workbook.save_as("examples/dynamic_arrays.xlsx")?;
    Ok(())
}
source

fn write_with_format<L: Location, T: CellDisplay + CellValue>( &mut self, loc: L, data: T, format: &Format<'_> ) -> WorkSheetResult<()>

Examples found in repository?
examples/text_indent.rs (line 13)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();
    let worksheet = workbook.get_worksheet(1)?;

    let indent1 = Format::default().set_indent(1);
    let indent2 = Format::default().set_indent(2);

    worksheet.set_column("A:A", 40.0)?;

    worksheet.write_with_format("A1", "This text is indented 1 level", &indent1)?;
    worksheet.write_with_format("A2", "This text is indented 2 levels", &indent2)?;

    // Note: Alignment is not applied correctly when changing the reading order, this bug will be fixed in the future!
    // let indent = Format::default().set_reading_order(2).set_align(FormatAlignType::Right).set_indent(2);
    // worksheet.right_to_left();

    workbook.save_as("examples/text_indent.xlsx")?;
    Ok(())
}
More examples
Hide additional examples
examples/outline_collapsed.rs (line 180)
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
fn create_sub_totals(worksheet: &mut WorkSheet) -> WorkbookResult<()> {
    // Add a general format
    let bold = Format::default().set_bold();

    // Add the data, labels and formulas
    worksheet.write_with_format("A1", "Region", &bold)?;
    worksheet.write("A2", "North")?;
    worksheet.write("A3", "North")?;
    worksheet.write("A4", "North")?;
    worksheet.write("A5", "North")?;
    worksheet.write_with_format("A6", "North Total", &bold)?;

    worksheet.write_with_format("B1", "Sales", &bold)?;
    worksheet.write("B2", 1000)?;
    worksheet.write("B3", 1200)?;
    worksheet.write("B4", 900)?;
    worksheet.write("B5", 1200)?;
    worksheet.write_formula_with_format("B6", "=SUBTOTAL(9,B2:B5)", &bold)?;
    worksheet.write("A7", "South")?;
    worksheet.write("A8", "South")?;
    worksheet.write("A9", "South")?;
    worksheet.write("A10", "South")?;
    worksheet.write_with_format("A11", "South Total", &bold)?;
    worksheet.write("B7", 400)?;
    worksheet.write("B8", 600)?;
    worksheet.write("B9", 500)?;
    worksheet.write("B10", 600)?;
    worksheet.write_formula_with_format("B11", "=SUBTOTAL(9,B7:B10)", &bold)?;
    worksheet.write_with_format("A12", "Grand Total", &bold)?;
    worksheet.write_formula_with_format("B12", "=SUBTOTAL(9,B2:B10)", &bold)?;
    Ok(())
}
examples/right_to_left.rs (line 20)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
fn main() -> WorkbookResult<()> {
    // Add the cell formats.
    let format_left_to_right = Format::default()
        .set_reading_order(1);
    let format_right_to_left = Format::default()
        .set_reading_order(2);

    // Create a new workbook
    let mut workbook = Workbook::new();
    // Set up some worksheets and set tab colors
    let worksheet1 = workbook.get_worksheet(1)?;

    // Make the columns wider for clarity.
    worksheet1.set_column("A:A", 25.0)?;

    // Standard direction:         | A1 | B1 | C1 | ...
    worksheet1.write("A1", "نص عربي / English text")?;  // Default direction.
    worksheet1.write_with_format("A2", "نص عربي / English text", &format_left_to_right)?;
    worksheet1.write_with_format("A3", "نص عربي / English text", &format_right_to_left)?;

    let worksheet2 = workbook.add_worksheet()?;
    worksheet2.set_column("A:A", 25.0)?;
    worksheet2.right_to_left();

    // Right to left direction:    ... | C1 | B1 | A1 |
    worksheet2.write("A1", "نص عربي / English text")?;  // Default direction.
    worksheet2.write_with_format("A2", "نص عربي / English text", &format_left_to_right)?;
    worksheet2.write_with_format("A3", "نص عربي / English text", &format_right_to_left)?;

    workbook.save_as("examples/right_to_left.xlsx")?;

    Ok(())
}
examples/hello_world.rs (line 13)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();
    let worksheet = workbook.get_worksheet(1)?;
    // write some text
    WorkSheet::write(worksheet, "A1", "Hello")?;
    worksheet.write("B1", "World")?;
    worksheet.write("C1", "Rust")?;
    // Adjust font size
    let big = Format::default().set_size(32);
    worksheet.write_with_format("B1", "big text", &big)?;
    // Change font color
    let red = Format::default().set_color(FormatColor::RGB("00FF7777"));
    worksheet.write_with_format("C1", "red text", &red)?;
    // Change the font style
    let bold = red.set_bold();
    worksheet.write_with_format("D1", "red bold text", &bold)?;
    // adjust the text align
    let left_top = Format::default().set_align(FormatAlignType::Left).set_align(FormatAlignType::Top);
    worksheet.write_with_format("A2", "left top", &left_top)?;
    // add borders
    let thin_border = Format::default().set_border(FormatBorderType::Thin);
    worksheet.write_with_format("B2", "bordered text", &thin_border)?;
    // add background
    let red_background = Format::default().set_background_color(FormatColor::RGB("00FF7777"));
    worksheet.write_with_format("C2", "red", &red_background)?;
    // add a number
    worksheet.write("D2", std::f64::consts::PI)?;
    // add a new worksheet and set a tab color
    let worksheet = workbook.add_worksheet_by_name("Other examples")?;
    worksheet.set_tab_color(&FormatColor::RGB("00FF9900")); // Orange
    // Set a background.
    worksheet.set_background("examples/pics/ferris.png")?;
    // Create a format to use in the merged range.
    let merge_format = Format::default()
        .set_bold()
        .set_border(FormatBorderType::Double)
        .set_align(FormatAlignType::Center)
        .set_align(FormatAlignType::VerticalCenter)
        .set_background_color(FormatColor::RGB("00ffff00"));
    // Merge cells.
    worksheet.merge_range_with_format("A1:C3", "Merged Range", &merge_format)?;
    // Add an image
    worksheet.insert_image("A4:C10", &"./examples/pics/rust.png");
    workbook.save_as("examples/hello_world.xlsx")?;
    Ok(())
}
examples/panes.rs (line 27)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
fn main() -> WorkbookResult<()> {
    let header_format = Format::default()
        .set_bold()
        .set_align(FormatAlignType::Center)
        .set_align(FormatAlignType::VerticalCenter)
        .set_border(FormatBorderType::Medium)
        .set_background_color(FormatColor::RGB("00D7E4BC"));
    let center_format = Format::default().set_align(FormatAlignType::Center);

    // Create a new workbook
    let mut workbook = Workbook::new();

    //
    // Example 1. Freeze pane on the top row.
    //
    let worksheet1 = workbook.add_worksheet_by_name("Panes 1")?;
    worksheet1.freeze_panes("A2")?;
    // Other sheet formatting.
    worksheet1.set_column("A:I", 16.0)?;
    worksheet1.set_row(0, 20.0)?;
    worksheet1.set_selection("C3:C3")?;

    // Some text to demonstrate scrolling.
    for col in 1..=9 {
        worksheet1.write_with_format((1, col), "Scroll down", &header_format)?;
    }

    for row in 2..100 {
        for col in 1..=9 {
            worksheet1.write_with_format((row, col), row, &center_format)?;
        }
    }

    //
    // Example 2. Freeze pane on the left column.
    //
    let worksheet2 = workbook.add_worksheet_by_name("Panes 2")?;
    worksheet2.freeze_panes("B1")?;

    // Other sheet formatting.
    worksheet2.set_column("A:A", 16.0)?;
    worksheet2.set_selection("C3:C3")?;

    // Some text to demonstrate scrolling.
    for row in 1..=50 {
        worksheet2.write_with_format((row, 1), "Scroll right", &header_format)?;
        for col in 2..=26 {
            worksheet2.write_with_format((row, col), col, &center_format)?;
        }
    }

    //
    // Example 3. Freeze pane on the top row and left column.
    //
    let worksheet3 = workbook.add_worksheet_by_name("Panes 3")?;
    worksheet3.freeze_panes((2, 2))?;

    // Other sheet formatting.
    worksheet3.set_column("A:Z", 16.0)?;
    worksheet3.set_row(1, 20.0)?;
    worksheet3.set_selection("C3:C3")?;
    worksheet3.write_with_format((1, 1), "", &header_format)?;

    // Some text to demonstrate scrolling.
    for col in 2..=26 {
        worksheet3.write_with_format((1, col), "Scroll down", &header_format)?;
    }

    for row in 2..=50 {
        worksheet3.write_with_format((row, 1), "Scroll right", &header_format)?;
        for col in 2..=26 {
            worksheet3.write_with_format((row, col), col, &center_format)?;
        }
    }

    //
    // Example 4. Split pane on the top row and left column.
    //
    // The divisions must be specified in terms of row and column dimensions.
    //
    let worksheet4 = workbook.add_worksheet_by_name("Panes 4")?;
    // Set the default row height is 17 and set the column width is 13
    worksheet4.set_column("A:Z", 13.0)?;
    worksheet4.set_default_row(17.0);
    worksheet4.split_panes(2.0 * 13.0, 2.0 * 17.0)?;
    worksheet4.set_selection("C3:C3")?;

    // Some text to demonstrate scrolling.
    for col in 1..=26 {
        worksheet4.write_with_format((1, col), "Scroll", &center_format)?;
    }
    for row in 1..=50 {
        worksheet4.write_with_format((row, 1), "Scroll", &center_format)?;
        for col in 1..=26 {
            worksheet4.write_with_format((row, col), col, &center_format)?;
        }
    }

    workbook.save_as("examples/panes.xlsx")?;
    Ok(())
}
examples/outline.rs (line 34)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();
    let worksheet1 = workbook.add_worksheet_by_name("Outlined Rows")?;
    // Add a general format
    let bold = Format::default().set_bold();

    //
    // Example 1: A worksheet with outlined rows. It also includes SUBTOTAL()?;    // functions so that it looks like the type of automatic outlines that are
    // generated when you use the Excel Data->SubTotals menu item.
    //
    // For outlines the important parameters are 'level' and 'hidden'. Rows with
    // the same 'level' are grouped together. The group will be collapsed if
    // 'hidden' is enabled. The parameters 'height' and 'cell_format' are assigned
    // default values if they are None.
    //
    worksheet1.set_row_level(2, 2)?;
    worksheet1.set_row_level(3, 2)?;
    worksheet1.set_row_level(4, 2)?;
    worksheet1.set_row_level(5, 2)?;
    worksheet1.set_row_level(6, 1)?;
    worksheet1.set_row_level(7, 2)?;
    worksheet1.set_row_level(8, 2)?;
    worksheet1.set_row_level(9, 2)?;
    worksheet1.set_row_level(10, 2)?;
    worksheet1.set_row_level(11, 1)?;

    // Adjust the column width for clarity
    worksheet1.set_column("A:A", 20.0)?;

    // Add the data, labels and formulas
    worksheet1.write_with_format("A1", "Region", &bold)?;
    worksheet1.write("A2", "North")?;
    worksheet1.write("A3", "North")?;
    worksheet1.write("A4", "North")?;
    worksheet1.write("A5", "North")?;
    worksheet1.write_with_format("A6", "North Total", &bold)?;

    worksheet1.write_with_format("B1", "Sales", &bold)?;
    worksheet1.write("B2", 1000)?;
    worksheet1.write("B3", 1200)?;
    worksheet1.write("B4", 900)?;
    worksheet1.write("B5", 1200)?;
    worksheet1.write_formula_with_format("B6", "=SUBTOTAL(9,B2:B5)", &bold)?;
    worksheet1.write("A7", "South")?;
    worksheet1.write("A8", "South")?;
    worksheet1.write("A9", "South")?;
    worksheet1.write("A10", "South")?;
    worksheet1.write_with_format("A11", "South Total", &bold)?;
    worksheet1.write("B7", 400)?;
    worksheet1.write("B8", 600)?;
    worksheet1.write("B9", 500)?;
    worksheet1.write("B10", 600)?;
    worksheet1.write_formula_with_format("B11", "=SUBTOTAL(9,B7:B10)", &bold)?;
    worksheet1.write_with_format("A12", "Grand Total", &bold)?;
    worksheet1.write_formula_with_format("B12", "=SUBTOTAL(9,B2:B10)", &bold)?;


    //
    // Example 2: A worksheet with outlined rows. This is the same as the
    // previous example except that the rows are collapsed.
    // Note: We need to indicate the rows that contains the collapsed symbol '+'
    // with the optional parameter, 'collapsed'. The group will be then be
    // collapsed if 'hidden' is True.
    //
    let worksheet2 = workbook.add_worksheet_by_name("Collapsed Rows")?;
    worksheet2.set_row_level(2, 2)?;
    worksheet2.hide_row(2)?;
    worksheet2.set_row_level(3, 2)?;
    worksheet2.hide_row(3)?;
    worksheet2.set_row_level(4, 2)?;
    worksheet2.hide_row(4)?;
    worksheet2.set_row_level(5, 2)?;
    worksheet2.hide_row(5)?;
    worksheet2.set_row_level(6, 1)?;
    worksheet2.hide_row(6)?;
    worksheet2.set_row_level(7, 2)?;
    worksheet2.hide_row(7)?;
    worksheet2.set_row_level(8, 2)?;
    worksheet2.hide_row(8)?;
    worksheet2.set_row_level(9, 2)?;
    worksheet2.hide_row(9)?;
    worksheet2.set_row_level(10, 2)?;
    worksheet2.hide_row(10)?;
    worksheet2.set_row_level(11, 1)?;
    worksheet2.hide_row(11)?;
    worksheet2.collapse_row(12)?;

    // Adjust the column width for clarity
    worksheet2.set_column("A:A", 20.0)?;

    // Add the data, labels and formulas
    worksheet2.write_with_format("A1", "Region", &bold)?;
    worksheet2.write("A2", "North")?;
    worksheet2.write("A3", "North")?;
    worksheet2.write("A4", "North")?;
    worksheet2.write("A5", "North")?;
    worksheet2.write_with_format("A6", "North Total", &bold)?;

    worksheet2.write_with_format("B1", "Sales", &bold)?;
    worksheet2.write("B2", 1000)?;
    worksheet2.write("B3", 1200)?;
    worksheet2.write("B4", 900)?;
    worksheet2.write("B5", 1200)?;
    worksheet2.write_formula_with_format("B6", "=SUBTOTAL(9,B2:B5)", &bold)?;
    worksheet2.write("A7", "South")?;
    worksheet2.write("A8", "South")?;
    worksheet2.write("A9", "South")?;
    worksheet2.write("A10", "South")?;
    worksheet2.write_with_format("A11", "South Total", &bold)?;
    worksheet2.write("B7", 400)?;
    worksheet2.write("B8", 600)?;
    worksheet2.write("B9", 500)?;
    worksheet2.write("B10", 600)?;
    worksheet2.write_formula_with_format("B11", "=SUBTOTAL(9,B7:B10)", &bold)?;
    worksheet2.write_with_format("A12", "Grand Total", &bold)?;
    worksheet2.write_formula_with_format("B12", "=SUBTOTAL(9,B2:B10)", &bold)?;

    //
    // Example 3: Create a worksheet with outlined columns.
    //
    let worksheet3 = workbook.add_worksheet_by_name("Outline Columns")?;
    // Add bold format to the first row.
    worksheet3.set_row_with_format(1, 15.0, &bold)?;
    worksheet3.write_row("A1", ["Month", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Total"].iter())?;
    worksheet3.set_column_with_format("A:A", 10.0, &bold)?;
    worksheet3.set_column("B:G", 10.0)?;
    worksheet3.set_column_level("B:G", 1)?;
    worksheet3.set_column("H:H", 10.0)?;
    worksheet3.write_column("A2", ["North", "South", "East", "East"].iter())?;
    worksheet3.write_row("B2", [50, 20, 15, 25, 65, 80].iter())?;
    worksheet3.write_row("B3", [10, 20, 30, 50, 50, 50].iter())?;
    worksheet3.write_row("B4", [45, 75, 50, 15, 75, 100].iter())?;
    worksheet3.write_row("B5", [15, 15, 55, 35, 20, 50].iter())?;
    worksheet3.write_formula("H2", "=SUM(B2:G2)")?;
    worksheet3.write_formula("H3", "=SUM(B3:G3)")?;
    worksheet3.write_formula("H4", "=SUM(B4:G4)")?;
    worksheet3.write_formula("H5", "=SUM(B5:G5)")?;
    worksheet3.write_formula_with_format("H6", "=SUM(H2:H5)", &bold)?;

    //
    // Example 4: Show all possible outline levels.
    //
    let levels = [
        "Level 1",
        "Level 2",
        "Level 3",
        "Level 4",
        "Level 5",
        "Level 6",
        "Level 7",
        "Level 6",
        "Level 5",
        "Level 4",
        "Level 3",
        "Level 2",
        "Level 1",
    ];
    let worksheet4 = workbook.add_worksheet_by_name("Outline levels")?;
    worksheet4.write_column("A1", levels.iter())?;

    worksheet4.set_row_level(1, 1)?;
    worksheet4.set_row_level(2, 2)?;
    worksheet4.set_row_level(3, 3)?;
    worksheet4.set_row_level(4, 4)?;
    worksheet4.set_row_level(5, 5)?;
    worksheet4.set_row_level(6, 6)?;
    worksheet4.set_row_level(7, 7)?;
    worksheet4.set_row_level(8, 6)?;
    worksheet4.set_row_level(9, 5)?;
    worksheet4.set_row_level(10, 4)?;
    worksheet4.set_row_level(11, 3)?;
    worksheet4.set_row_level(12, 2)?;
    worksheet4.set_row_level(13, 1)?;

    workbook.save_as("examples/outline.xlsx")?;
    Ok(())
}
source

fn write_string_with_format<L: Location>( &mut self, loc: L, data: String, format: &Format<'_> ) -> WorkSheetResult<()>

source

fn write_number_with_format<L: Location>( &mut self, loc: L, data: i32, format: &Format<'_> ) -> WorkSheetResult<()>

source

fn write_double_with_format<L: Location>( &mut self, loc: L, data: f64, format: &Format<'_> ) -> WorkSheetResult<()>

source

fn write_boolean_with_format<L: Location>( &mut self, loc: L, data: bool, format: &Format<'_> ) -> WorkSheetResult<()>

source

fn write_row_with_format<L: Location, T: CellDisplay + CellValue>( &mut self, loc: L, data: Iter<'_, T>, format: &Format<'_> ) -> WorkSheetResult<()>

source

fn write_column_with_format<L: Location, T: CellDisplay + CellValue>( &mut self, loc: L, data: Iter<'_, T>, format: &Format<'_> ) -> WorkSheetResult<()>

source

fn write_url_with_format<L: Location>( &mut self, loc: L, url: &str, format: &Format<'_> ) -> WorkSheetResult<()>

source

fn write_url_data_with_format<L: Location>( &mut self, loc: L, url: &str, data: &str, format: &Format<'_> ) -> WorkSheetResult<()>

source

fn write_formula_with_format<L: Location>( &mut self, loc: L, data: &str, format: &Format<'_> ) -> WorkSheetResult<()>

Examples found in repository?
examples/outline_collapsed.rs (line 142)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();
    // Add a general format
    let bold = Format::default().set_bold();

    //
    // Example 1: A worksheet with outlined rows. It also includes SUBTOTAL()
    // functions so that it looks like the type of automatic outlines that are
    // generated when you use the Excel Data->SubTotals menu item.
    //
    let worksheet1 = workbook.add_worksheet_by_name("Outlined Rows")?;
    worksheet1.set_row_level(2, 2)?;
    worksheet1.set_row_level(3, 2)?;
    worksheet1.set_row_level(4, 2)?;
    worksheet1.set_row_level(5, 2)?;
    worksheet1.set_row_level(6, 1)?;
    worksheet1.set_row_level(7, 2)?;
    worksheet1.set_row_level(8, 2)?;
    worksheet1.set_row_level(9, 2)?;
    worksheet1.set_row_level(10, 2)?;
    worksheet1.set_row_level(11, 1)?;
    create_sub_totals(worksheet1)?;

    //
    // Example 2: Create a worksheet with collapsed outlined rows.
    // This is the same as the example 1  except that the all rows are collapsed.
    // Note: We need to indicate the rows that contains the collapsed symbol '+'
    // with the optional parameter, 'collapsed'.
    //
    let worksheet2 = workbook.add_worksheet_by_name("Collapsed Rows 1")?;
    worksheet2.set_row_level(2, 2)?;
    worksheet2.hide_row(2)?;
    worksheet2.set_row_level(3, 2)?;
    worksheet2.hide_row(3)?;
    worksheet2.set_row_level(4, 2)?;
    worksheet2.hide_row(4)?;
    worksheet2.set_row_level(5, 2)?;
    worksheet2.hide_row(5)?;
    worksheet2.set_row_level(6, 1)?;
    worksheet2.hide_row(6)?;
    worksheet2.set_row_level(7, 2)?;
    worksheet2.hide_row(7)?;
    worksheet2.set_row_level(8, 2)?;
    worksheet2.hide_row(8)?;
    worksheet2.set_row_level(9, 2)?;
    worksheet2.hide_row(9)?;
    worksheet2.set_row_level(10, 2)?;
    worksheet2.hide_row(10)?;
    worksheet2.set_row_level(11, 1)?;
    worksheet2.hide_row(11)?;

    worksheet2.collapse_row(12)?;

    // Write the sub-total data that is common to the row examples.
    create_sub_totals(worksheet2)?;


    //
    // Example 3: Create a worksheet with collapsed outlined rows.
    // Same as the example 1  except that the two sub-totals are collapsed.
    //
    let worksheet3 = workbook.add_worksheet_by_name("Collapsed Rows 2")?;
    worksheet3.set_row_level(2, 2)?;
    worksheet3.hide_row(2)?;
    worksheet3.set_row_level(3, 2)?;
    worksheet3.hide_row(3)?;
    worksheet3.set_row_level(4, 2)?;
    worksheet3.hide_row(4)?;
    worksheet3.set_row_level(5, 2)?;
    worksheet3.hide_row(5)?;
    worksheet3.set_row_level(6, 1)?;
    worksheet3.collapse_row(6)?;
    worksheet3.set_row_level(7, 2)?;
    worksheet3.hide_row(7)?;
    worksheet3.set_row_level(8, 2)?;
    worksheet3.hide_row(8)?;
    worksheet3.set_row_level(9, 2)?;
    worksheet3.hide_row(9)?;
    worksheet3.set_row_level(10, 2)?;
    worksheet3.hide_row(10)?;
    worksheet3.set_row_level(11, 1)?;
    worksheet3.collapse_row(11)?;
    // Write the sub-total data that is common to the row examples.
    create_sub_totals(worksheet3)?;


    //
    // Example 4: Create a worksheet with outlined rows.
    // Same as the example 1  except that the two sub-totals are collapsed.
    //
    let worksheet4 = workbook.add_worksheet_by_name("Collapsed Rows 3")?;
    worksheet4.set_row_level(2, 2)?;
    worksheet4.hide_row(2)?;
    worksheet4.set_row_level(3, 2)?;
    worksheet4.hide_row(3)?;
    worksheet4.set_row_level(4, 2)?;
    worksheet4.hide_row(4)?;
    worksheet4.set_row_level(5, 2)?;
    worksheet4.hide_row(5)?;
    worksheet4.set_row_level(6, 1)?;
    worksheet4.hide_row(6)?;
    worksheet4.collapse_row(6)?;
    worksheet4.set_row_level(7, 2)?;
    worksheet4.hide_row(7)?;
    worksheet4.set_row_level(8, 2)?;
    worksheet4.hide_row(8)?;
    worksheet4.set_row_level(9, 2)?;
    worksheet4.hide_row(9)?;
    worksheet4.set_row_level(10, 2)?;
    worksheet4.hide_row(10)?;
    worksheet4.set_row_level(11, 1)?;
    worksheet4.hide_row(11)?;
    worksheet4.collapse_row(11)?;
    worksheet4.collapse_row(12)?;
    // Write the sub-total data that is common to the row examples.
    create_sub_totals(worksheet4)?;



    //
    // Example 5: Create a worksheet with outlined columns.
    //
    let worksheet5 = workbook.add_worksheet_by_name("Outline Columns")?;
    worksheet5.set_row_with_format(1, 15.0, &bold)?;
    worksheet5.write_row("A1", ["Month", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Total"].iter())?;
    worksheet5.set_column_with_format("A:A", 10.0, &bold)?;
    worksheet5.set_column("B:G", 5.0)?;
    worksheet5.set_column_level("B:G", 1)?;
    worksheet5.set_column("H:H", 10.0)?;
    worksheet5.write_column("A2", ["North", "South", "East", "East"].iter())?;
    worksheet5.write_row("B2", [50, 20, 15, 25, 65, 80].iter())?;
    worksheet5.write_row("B3", [10, 20, 30, 50, 50, 50].iter())?;
    worksheet5.write_row("B4", [45, 75, 50, 15, 75, 100].iter())?;
    worksheet5.write_row("B5", [15, 15, 55, 35, 20, 50].iter())?;
    worksheet5.write_formula("H2", "=SUM(B2:G2)")?;
    worksheet5.write_formula("H3", "=SUM(B3:G3)")?;
    worksheet5.write_formula("H4", "=SUM(B4:G4)")?;
    worksheet5.write_formula("H5", "=SUM(B5:G5)")?;
    worksheet5.write_formula_with_format("H6", "=SUM(H2:H5)", &bold)?;



    //
    // Example 6: Create a worksheet with collapsed outlined columns.
    // This is the same as the previous example except with collapsed columns.
    //
    let worksheet6 = workbook.add_worksheet_by_name("Collapsed Columns")?;
    worksheet6.set_row_with_format(1, 15.0, &bold)?;
    worksheet6.write_row("A1", ["Month", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Total"].iter())?;
    worksheet6.set_column_with_format("A:H", 10.0, &bold)?;
    worksheet6.set_column_level("B:G", 1)?;
    worksheet6.set_column_level("C:F", 2)?;
    worksheet6.set_column_level("D:E", 3)?;
    worksheet6.hide_column("D:E")?;
    worksheet6.collapse_col("D:E")?;
    worksheet6.write_column("A2", ["North", "South", "East", "East"].iter())?;
    worksheet6.write_row("B2", [50, 20, 15, 25, 65, 80].iter())?;
    worksheet6.write_row("B3", [10, 20, 30, 50, 50, 50].iter())?;
    worksheet6.write_row("B4", [45, 75, 50, 15, 75, 100].iter())?;
    worksheet6.write_row("B5", [15, 15, 55, 35, 20, 50].iter())?;
    worksheet6.write_formula("H2", "=SUM(B2:G2)")?;
    worksheet6.write_formula("H3", "=SUM(B3:G3)")?;
    worksheet6.write_formula("H4", "=SUM(B4:G4)")?;
    worksheet6.write_formula("H5", "=SUM(B5:G5)")?;
    worksheet6.write_formula_with_format("H6", "=SUM(H2:H5)", &bold)?;


    workbook.save_as("examples/outline_collapsed.xlsx")?;
    Ok(())
}

fn create_sub_totals(worksheet: &mut WorkSheet) -> WorkbookResult<()> {
    // Add a general format
    let bold = Format::default().set_bold();

    // Add the data, labels and formulas
    worksheet.write_with_format("A1", "Region", &bold)?;
    worksheet.write("A2", "North")?;
    worksheet.write("A3", "North")?;
    worksheet.write("A4", "North")?;
    worksheet.write("A5", "North")?;
    worksheet.write_with_format("A6", "North Total", &bold)?;

    worksheet.write_with_format("B1", "Sales", &bold)?;
    worksheet.write("B2", 1000)?;
    worksheet.write("B3", 1200)?;
    worksheet.write("B4", 900)?;
    worksheet.write("B5", 1200)?;
    worksheet.write_formula_with_format("B6", "=SUBTOTAL(9,B2:B5)", &bold)?;
    worksheet.write("A7", "South")?;
    worksheet.write("A8", "South")?;
    worksheet.write("A9", "South")?;
    worksheet.write("A10", "South")?;
    worksheet.write_with_format("A11", "South Total", &bold)?;
    worksheet.write("B7", 400)?;
    worksheet.write("B8", 600)?;
    worksheet.write("B9", 500)?;
    worksheet.write("B10", 600)?;
    worksheet.write_formula_with_format("B11", "=SUBTOTAL(9,B7:B10)", &bold)?;
    worksheet.write_with_format("A12", "Grand Total", &bold)?;
    worksheet.write_formula_with_format("B12", "=SUBTOTAL(9,B2:B10)", &bold)?;
    Ok(())
}
More examples
Hide additional examples
examples/outline.rs (line 46)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();
    let worksheet1 = workbook.add_worksheet_by_name("Outlined Rows")?;
    // Add a general format
    let bold = Format::default().set_bold();

    //
    // Example 1: A worksheet with outlined rows. It also includes SUBTOTAL()?;    // functions so that it looks like the type of automatic outlines that are
    // generated when you use the Excel Data->SubTotals menu item.
    //
    // For outlines the important parameters are 'level' and 'hidden'. Rows with
    // the same 'level' are grouped together. The group will be collapsed if
    // 'hidden' is enabled. The parameters 'height' and 'cell_format' are assigned
    // default values if they are None.
    //
    worksheet1.set_row_level(2, 2)?;
    worksheet1.set_row_level(3, 2)?;
    worksheet1.set_row_level(4, 2)?;
    worksheet1.set_row_level(5, 2)?;
    worksheet1.set_row_level(6, 1)?;
    worksheet1.set_row_level(7, 2)?;
    worksheet1.set_row_level(8, 2)?;
    worksheet1.set_row_level(9, 2)?;
    worksheet1.set_row_level(10, 2)?;
    worksheet1.set_row_level(11, 1)?;

    // Adjust the column width for clarity
    worksheet1.set_column("A:A", 20.0)?;

    // Add the data, labels and formulas
    worksheet1.write_with_format("A1", "Region", &bold)?;
    worksheet1.write("A2", "North")?;
    worksheet1.write("A3", "North")?;
    worksheet1.write("A4", "North")?;
    worksheet1.write("A5", "North")?;
    worksheet1.write_with_format("A6", "North Total", &bold)?;

    worksheet1.write_with_format("B1", "Sales", &bold)?;
    worksheet1.write("B2", 1000)?;
    worksheet1.write("B3", 1200)?;
    worksheet1.write("B4", 900)?;
    worksheet1.write("B5", 1200)?;
    worksheet1.write_formula_with_format("B6", "=SUBTOTAL(9,B2:B5)", &bold)?;
    worksheet1.write("A7", "South")?;
    worksheet1.write("A8", "South")?;
    worksheet1.write("A9", "South")?;
    worksheet1.write("A10", "South")?;
    worksheet1.write_with_format("A11", "South Total", &bold)?;
    worksheet1.write("B7", 400)?;
    worksheet1.write("B8", 600)?;
    worksheet1.write("B9", 500)?;
    worksheet1.write("B10", 600)?;
    worksheet1.write_formula_with_format("B11", "=SUBTOTAL(9,B7:B10)", &bold)?;
    worksheet1.write_with_format("A12", "Grand Total", &bold)?;
    worksheet1.write_formula_with_format("B12", "=SUBTOTAL(9,B2:B10)", &bold)?;


    //
    // Example 2: A worksheet with outlined rows. This is the same as the
    // previous example except that the rows are collapsed.
    // Note: We need to indicate the rows that contains the collapsed symbol '+'
    // with the optional parameter, 'collapsed'. The group will be then be
    // collapsed if 'hidden' is True.
    //
    let worksheet2 = workbook.add_worksheet_by_name("Collapsed Rows")?;
    worksheet2.set_row_level(2, 2)?;
    worksheet2.hide_row(2)?;
    worksheet2.set_row_level(3, 2)?;
    worksheet2.hide_row(3)?;
    worksheet2.set_row_level(4, 2)?;
    worksheet2.hide_row(4)?;
    worksheet2.set_row_level(5, 2)?;
    worksheet2.hide_row(5)?;
    worksheet2.set_row_level(6, 1)?;
    worksheet2.hide_row(6)?;
    worksheet2.set_row_level(7, 2)?;
    worksheet2.hide_row(7)?;
    worksheet2.set_row_level(8, 2)?;
    worksheet2.hide_row(8)?;
    worksheet2.set_row_level(9, 2)?;
    worksheet2.hide_row(9)?;
    worksheet2.set_row_level(10, 2)?;
    worksheet2.hide_row(10)?;
    worksheet2.set_row_level(11, 1)?;
    worksheet2.hide_row(11)?;
    worksheet2.collapse_row(12)?;

    // Adjust the column width for clarity
    worksheet2.set_column("A:A", 20.0)?;

    // Add the data, labels and formulas
    worksheet2.write_with_format("A1", "Region", &bold)?;
    worksheet2.write("A2", "North")?;
    worksheet2.write("A3", "North")?;
    worksheet2.write("A4", "North")?;
    worksheet2.write("A5", "North")?;
    worksheet2.write_with_format("A6", "North Total", &bold)?;

    worksheet2.write_with_format("B1", "Sales", &bold)?;
    worksheet2.write("B2", 1000)?;
    worksheet2.write("B3", 1200)?;
    worksheet2.write("B4", 900)?;
    worksheet2.write("B5", 1200)?;
    worksheet2.write_formula_with_format("B6", "=SUBTOTAL(9,B2:B5)", &bold)?;
    worksheet2.write("A7", "South")?;
    worksheet2.write("A8", "South")?;
    worksheet2.write("A9", "South")?;
    worksheet2.write("A10", "South")?;
    worksheet2.write_with_format("A11", "South Total", &bold)?;
    worksheet2.write("B7", 400)?;
    worksheet2.write("B8", 600)?;
    worksheet2.write("B9", 500)?;
    worksheet2.write("B10", 600)?;
    worksheet2.write_formula_with_format("B11", "=SUBTOTAL(9,B7:B10)", &bold)?;
    worksheet2.write_with_format("A12", "Grand Total", &bold)?;
    worksheet2.write_formula_with_format("B12", "=SUBTOTAL(9,B2:B10)", &bold)?;

    //
    // Example 3: Create a worksheet with outlined columns.
    //
    let worksheet3 = workbook.add_worksheet_by_name("Outline Columns")?;
    // Add bold format to the first row.
    worksheet3.set_row_with_format(1, 15.0, &bold)?;
    worksheet3.write_row("A1", ["Month", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Total"].iter())?;
    worksheet3.set_column_with_format("A:A", 10.0, &bold)?;
    worksheet3.set_column("B:G", 10.0)?;
    worksheet3.set_column_level("B:G", 1)?;
    worksheet3.set_column("H:H", 10.0)?;
    worksheet3.write_column("A2", ["North", "South", "East", "East"].iter())?;
    worksheet3.write_row("B2", [50, 20, 15, 25, 65, 80].iter())?;
    worksheet3.write_row("B3", [10, 20, 30, 50, 50, 50].iter())?;
    worksheet3.write_row("B4", [45, 75, 50, 15, 75, 100].iter())?;
    worksheet3.write_row("B5", [15, 15, 55, 35, 20, 50].iter())?;
    worksheet3.write_formula("H2", "=SUM(B2:G2)")?;
    worksheet3.write_formula("H3", "=SUM(B3:G3)")?;
    worksheet3.write_formula("H4", "=SUM(B4:G4)")?;
    worksheet3.write_formula("H5", "=SUM(B5:G5)")?;
    worksheet3.write_formula_with_format("H6", "=SUM(H2:H5)", &bold)?;

    //
    // Example 4: Show all possible outline levels.
    //
    let levels = [
        "Level 1",
        "Level 2",
        "Level 3",
        "Level 4",
        "Level 5",
        "Level 6",
        "Level 7",
        "Level 6",
        "Level 5",
        "Level 4",
        "Level 3",
        "Level 2",
        "Level 1",
    ];
    let worksheet4 = workbook.add_worksheet_by_name("Outline levels")?;
    worksheet4.write_column("A1", levels.iter())?;

    worksheet4.set_row_level(1, 1)?;
    worksheet4.set_row_level(2, 2)?;
    worksheet4.set_row_level(3, 3)?;
    worksheet4.set_row_level(4, 4)?;
    worksheet4.set_row_level(5, 5)?;
    worksheet4.set_row_level(6, 6)?;
    worksheet4.set_row_level(7, 7)?;
    worksheet4.set_row_level(8, 6)?;
    worksheet4.set_row_level(9, 5)?;
    worksheet4.set_row_level(10, 4)?;
    worksheet4.set_row_level(11, 3)?;
    worksheet4.set_row_level(12, 2)?;
    worksheet4.set_row_level(13, 1)?;

    workbook.save_as("examples/outline.xlsx")?;
    Ok(())
}
source

fn write_array_formula_with_format<L: Location>( &mut self, loc: L, data: &str, format: &Format<'_> ) -> WorkSheetResult<()>

source

fn write_dynamic_array_formula_with_format<L: LocationRange>( &mut self, loc_range: L, data: &str, format: &Format<'_> ) -> WorkSheetResult<()>

source

fn merge_range_with_format<L: LocationRange, T: CellDisplay + CellValue>( &mut self, loc: L, data: T, format: &Format<'_> ) -> WorkSheetResult<()>

Examples found in repository?
examples/merge.rs (line 22)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
fn main() -> WorkbookResult<()> {
    let mut workbook = Workbook::new();
    let worksheet = workbook.get_worksheet(1)?;

    // Increase the cell size of the merged cells to highlight the formatting.
    worksheet.set_column("B:D", 18.0)?;
    worksheet.set_row(4, 40.0)?;
    worksheet.set_row(7, 30.0)?;
    worksheet.set_row(8, 30.0)?;

    // Create a format to use in the merged range.
    let merge_format = Format::default()
        .set_bold()
        .set_border(FormatBorderType::Double)
        .set_align(FormatAlignType::Center)
        .set_align(FormatAlignType::VerticalCenter)
        .set_background_color(FormatColor::RGB("00ffff00"));

    // Merge 3 cells.
    worksheet.merge_range_with_format("B4:D4", "Merged Range", &merge_format)?;
    // Merge 3 cells over two rows.
    worksheet.merge_range_with_format("B7:D8", "Merged Range", &merge_format)?;

    workbook.save_as("examples/merge.xlsx")?;
    Ok(())
}
More examples
Hide additional examples
examples/hello_world.rs (line 44)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
fn main() -> WorkbookResult<()> {
    // Create a new workbook
    let mut workbook = Workbook::new();
    let worksheet = workbook.get_worksheet(1)?;
    // write some text
    WorkSheet::write(worksheet, "A1", "Hello")?;
    worksheet.write("B1", "World")?;
    worksheet.write("C1", "Rust")?;
    // Adjust font size
    let big = Format::default().set_size(32);
    worksheet.write_with_format("B1", "big text", &big)?;
    // Change font color
    let red = Format::default().set_color(FormatColor::RGB("00FF7777"));
    worksheet.write_with_format("C1", "red text", &red)?;
    // Change the font style
    let bold = red.set_bold();
    worksheet.write_with_format("D1", "red bold text", &bold)?;
    // adjust the text align
    let left_top = Format::default().set_align(FormatAlignType::Left).set_align(FormatAlignType::Top);
    worksheet.write_with_format("A2", "left top", &left_top)?;
    // add borders
    let thin_border = Format::default().set_border(FormatBorderType::Thin);
    worksheet.write_with_format("B2", "bordered text", &thin_border)?;
    // add background
    let red_background = Format::default().set_background_color(FormatColor::RGB("00FF7777"));
    worksheet.write_with_format("C2", "red", &red_background)?;
    // add a number
    worksheet.write("D2", std::f64::consts::PI)?;
    // add a new worksheet and set a tab color
    let worksheet = workbook.add_worksheet_by_name("Other examples")?;
    worksheet.set_tab_color(&FormatColor::RGB("00FF9900")); // Orange
    // Set a background.
    worksheet.set_background("examples/pics/ferris.png")?;
    // Create a format to use in the merged range.
    let merge_format = Format::default()
        .set_bold()
        .set_border(FormatBorderType::Double)
        .set_align(FormatAlignType::Center)
        .set_align(FormatAlignType::VerticalCenter)
        .set_background_color(FormatColor::RGB("00ffff00"));
    // Merge cells.
    worksheet.merge_range_with_format("A1:C3", "Merged Range", &merge_format)?;
    // Add an image
    worksheet.insert_image("A4:C10", &"./examples/pics/rust.png");
    workbook.save_as("examples/hello_world.xlsx")?;
    Ok(())
}

Object Safety§

This trait is not object safe.

Implementors§