pub struct Format<'a> { /* private fields */ }Implementations§
source§impl<'a> Format<'a>
impl<'a> Format<'a>
sourcepub fn set_bold(self) -> Self
pub fn set_bold(self) -> Self
Examples found in repository?
examples/merge.rs (line 15)
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
examples/hello_world.rs (line 18)
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 5)
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, ¢er_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, ¢er_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, ¢er_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", ¢er_format)?;
}
for row in 1..=50 {
worksheet4.write_with_format((row, 1), "Scroll", ¢er_format)?;
for col in 1..=26 {
worksheet4.write_with_format((row, col), col, ¢er_format)?;
}
}
workbook.save_as("examples/panes.xlsx")?;
Ok(())
}examples/outline_collapsed.rs (line 7)
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(())
}examples/outline.rs (line 8)
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 27)
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(())
}pub fn set_italic(self) -> Self
pub fn set_underline(self) -> Self
sourcepub fn set_size(self, size: u8) -> Self
pub fn set_size(self, size: u8) -> Self
Examples found in repository?
examples/hello_world.rs (line 12)
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(())
}sourcepub fn set_color<'b: 'a>(self, format_color: FormatColor<'b>) -> Self
pub fn set_color<'b: 'a>(self, format_color: FormatColor<'b>) -> Self
Examples found in repository?
examples/hello_world.rs (line 15)
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(())
}More examples
examples/dynamic_arrays.rs (line 7)
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(())
}sourcepub fn set_border<'b: 'a>(self, format_border_type: FormatBorderType) -> Self
pub fn set_border<'b: 'a>(self, format_border_type: FormatBorderType) -> Self
Examples found in repository?
examples/merge.rs (line 16)
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
examples/hello_world.rs (line 24)
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 8)
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, ¢er_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, ¢er_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, ¢er_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", ¢er_format)?;
}
for row in 1..=50 {
worksheet4.write_with_format((row, 1), "Scroll", ¢er_format)?;
for col in 1..=26 {
worksheet4.write_with_format((row, col), col, ¢er_format)?;
}
}
workbook.save_as("examples/panes.xlsx")?;
Ok(())
}pub fn set_border_left<'b: 'a>( self, format_border_type: FormatBorderType ) -> Self
pub fn set_border_right<'b: 'a>( self, format_border_type: FormatBorderType ) -> Self
pub fn set_border_top<'b: 'a>( self, format_border_type: FormatBorderType ) -> Self
pub fn set_border_bottom<'b: 'a>( self, format_border_type: FormatBorderType ) -> Self
sourcepub fn set_background_color<'b: 'a>(self, format_color: FormatColor<'b>) -> Self
pub fn set_background_color<'b: 'a>(self, format_color: FormatColor<'b>) -> Self
Examples found in repository?
examples/merge.rs (line 19)
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
examples/hello_world.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
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 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 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, ¢er_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, ¢er_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, ¢er_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", ¢er_format)?;
}
for row in 1..=50 {
worksheet4.write_with_format((row, 1), "Scroll", ¢er_format)?;
for col in 1..=26 {
worksheet4.write_with_format((row, col), col, ¢er_format)?;
}
}
workbook.save_as("examples/panes.xlsx")?;
Ok(())
}examples/dynamic_arrays.rs (line 8)
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(())
}sourcepub fn set_align<'b: 'a>(self, format_align_type: FormatAlignType) -> Self
pub fn set_align<'b: 'a>(self, format_align_type: FormatAlignType) -> Self
Examples found in repository?
examples/merge.rs (line 17)
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
examples/hello_world.rs (line 21)
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 6)
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, ¢er_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, ¢er_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, ¢er_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", ¢er_format)?;
}
for row in 1..=50 {
worksheet4.write_with_format((row, 1), "Scroll", ¢er_format)?;
for col in 1..=26 {
worksheet4.write_with_format((row, col), col, ¢er_format)?;
}
}
workbook.save_as("examples/panes.xlsx")?;
Ok(())
}sourcepub fn set_reading_order(self, reading_order: u8) -> Self
pub fn set_reading_order(self, reading_order: u8) -> Self
Examples found in repository?
examples/right_to_left.rs (line 6)
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(())
}sourcepub fn set_indent(self, indent: u8) -> Self
pub fn set_indent(self, indent: u8) -> Self
Examples found in repository?
examples/text_indent.rs (line 8)
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(())
}Trait Implementations§
Auto Trait Implementations§
impl<'a> RefUnwindSafe for Format<'a>
impl<'a> Send for Format<'a>
impl<'a> Sync for Format<'a>
impl<'a> Unpin for Format<'a>
impl<'a> UnwindSafe for Format<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more