|
1 |
| -use xlsxwriter::{FormatAlignment, FormatColor, FormatUnderline, Workbook}; |
| 1 | +use xlsxwriter::{ |
| 2 | + Format, FormatAlignment, FormatColor, FormatUnderline, FormatVerticalAlignment, Workbook, |
| 3 | +}; |
2 | 4 |
|
3 | 5 | fn main() -> Result<(), xlsxwriter::XlsxError> {
|
4 | 6 | let workbook = Workbook::new("target/simple1.xlsx")?;
|
5 |
| - let format1 = workbook.add_format().set_font_color(FormatColor::Red); |
6 |
| - |
7 |
| - let format2 = workbook |
8 |
| - .add_format() |
9 |
| - .set_font_color(FormatColor::Blue) |
10 |
| - .set_underline(FormatUnderline::Single); |
11 |
| - |
12 |
| - let format3 = workbook |
13 |
| - .add_format() |
14 |
| - .set_font_color(FormatColor::Green) |
15 |
| - .set_align(FormatAlignment::CenterAcross) |
16 |
| - .set_align(FormatAlignment::VerticalCenter); |
17 | 7 |
|
18 | 8 | let mut sheet1 = workbook.add_worksheet(None)?;
|
19 |
| - sheet1.write_string(0, 0, "Red text", Some(&format1))?; |
| 9 | + sheet1.write_string( |
| 10 | + 0, |
| 11 | + 0, |
| 12 | + "Red text", |
| 13 | + Some(&Format::new().set_font_color(FormatColor::Red)), |
| 14 | + )?; |
20 | 15 | sheet1.write_number(0, 1, 20., None)?;
|
21 | 16 | sheet1.write_formula_num(1, 0, "=10+B1", None, 30.)?;
|
22 | 17 | sheet1.write_url(
|
23 | 18 | 1,
|
24 | 19 | 1,
|
25 | 20 | "https://github.com/informationsea/xlsxwriter-rs",
|
26 |
| - Some(&format2), |
| 21 | + Some( |
| 22 | + &Format::new() |
| 23 | + .set_font_color(FormatColor::Blue) |
| 24 | + .set_underline(FormatUnderline::Single), |
| 25 | + ), |
| 26 | + )?; |
| 27 | + sheet1.merge_range( |
| 28 | + 2, |
| 29 | + 0, |
| 30 | + 3, |
| 31 | + 2, |
| 32 | + "Hello, world", |
| 33 | + Some( |
| 34 | + &Format::new() |
| 35 | + .set_font_color(FormatColor::Green) |
| 36 | + .set_align(FormatAlignment::CenterAcross) |
| 37 | + .set_vertical_align(FormatVerticalAlignment::VerticalCenter), |
| 38 | + ), |
27 | 39 | )?;
|
28 |
| - sheet1.merge_range(2, 0, 3, 2, "Hello, world", Some(&format3))?; |
29 | 40 |
|
30 | 41 | sheet1.set_selection(1, 0, 1, 2);
|
31 | 42 | sheet1.set_tab_color(FormatColor::Cyan);
|
|
0 commit comments