format_font/
format_font.rs

1//! Example of writing some data with font formatting.
2
3use karo::{col_range, index, Format, Workbook};
4
5fn main() -> karo::Result<()> {
6    // Create a new workbook.
7    let mut workbook = Workbook::new();
8
9    // Add some cell formats.
10    let mut myformat1 = Format::default();
11    let mut myformat2 = Format::default();
12    let mut myformat3 = Format::default();
13
14    // Set the bold property for format 1.
15    myformat1.font.bold = true;
16
17    // Set the italic property for format 2.
18    myformat2.font.italic = true;
19
20    // Set the bold and italic properties for format 3.
21    myformat3.font.bold = true;
22    myformat3.font.italic = true;
23
24    {
25        let worksheet = workbook.add_worksheet(None)?;
26
27        // Widen the first column to make the text clearer.
28        worksheet.set_column(col_range(0, 0)?, 20f64, None)?;
29
30        worksheet.write_string(
31            index(0, 0)?,
32            "This is bold",
33            Some(&myformat1),
34        )?;
35        worksheet.write_string(
36            index(1, 0)?,
37            "This is italic",
38            Some(&myformat2),
39        )?;
40        worksheet.write_string(
41            index(2, 0)?,
42            "Bold and italic",
43            Some(&myformat3),
44        )?;
45    }
46
47    workbook.write_file("format_font.xlsx")?;
48
49    Ok(())
50}