pub enum NumFormat {
Builtin(Builtin),
Custom(String),
}
Variants§
Implementations§
Source§impl NumFormat
impl NumFormat
pub fn to_builtin_if_possible(self) -> Self
Sourcepub fn from_format_string(s: &str) -> Self
pub fn from_format_string(s: &str) -> Self
Examples found in repository?
examples/tutorial2.rs (line 43)
10fn main() -> karo::Result<()> {
11 let expenses = [
12 Expense {
13 item: "Rent",
14 cost: 1000f64,
15 },
16 Expense {
17 item: "Gas",
18 cost: 100f64,
19 },
20 Expense {
21 item: "Food",
22 cost: 300f64,
23 },
24 Expense {
25 item: "Gym",
26 cost: 50f64,
27 },
28 ];
29
30 // Create a new workbook.
31 let mut workbook = Workbook::new();
32
33 {
34 // Add a worksheet with a user defined name.
35 let worksheet = workbook.add_worksheet(None)?;
36
37 // Add a bold format to use to highlight cells.
38 let mut bold = Format::default();
39 bold.font.bold = true;
40
41 // Add a number format for cells with money.
42 let mut money = Format::default();
43 money.num_format = NumFormat::from_format_string("$#,##0");
44
45 let mut row = 0u32;
46
47 worksheet.write_string(index(row, 0)?, "Item", Some(&bold))?;
48 worksheet.write_string(index(row, 1)?, "Cost", Some(&bold))?;
49 row += 1;
50
51 for Expense { item, cost } in expenses.iter() {
52 worksheet.write_string(index(row, 0)?, item, None)?;
53 worksheet.write_number(index(row, 1)?, *cost, Some(&money))?;
54 row += 1;
55 }
56
57 worksheet.write_string(index(row, 0)?, "Total", Some(&bold))?;
58 worksheet.write_formula(
59 index(row, 1)?,
60 "=SUM(B2:B5)",
61 Some(&money),
62 )?;
63 }
64
65 workbook.write_file("tutorial02.xlsx")?;
66
67 Ok(())
68}
More examples
examples/tutorial3.rs (line 49)
12fn main() -> karo::Result<()> {
13 let expenses = [
14 Expense {
15 item: "Rent",
16 cost: 1000f64,
17 datetime: Utc.ymd(2013, 1, 13).and_hms(0, 0, 0),
18 },
19 Expense {
20 item: "Gas",
21 cost: 100f64,
22 datetime: Utc.ymd(2013, 1, 14).and_hms(0, 0, 0),
23 },
24 Expense {
25 item: "Food",
26 cost: 300f64,
27 datetime: Utc.ymd(2013, 1, 16).and_hms(0, 0, 0),
28 },
29 Expense {
30 item: "Gym",
31 cost: 50f64,
32 datetime: Utc.ymd(2013, 1, 20).and_hms(0, 0, 0),
33 },
34 ];
35
36 // Create a new workbook.
37 let mut workbook = Workbook::new();
38
39 {
40 // Add a worksheet with a user defined name.
41 let worksheet = workbook.add_worksheet(None)?;
42
43 // Add a bold format to use to highlight cells.
44 let mut bold = Format::default();
45 bold.font.bold = true;
46
47 // Add a number format for cells with money.
48 let mut money = Format::default();
49 money.num_format = NumFormat::from_format_string("$#,##0");
50
51 // Add a number format for cells with money.
52 let mut date = Format::default();
53 date.num_format = NumFormat::from_format_string("mmmm d yyyy");
54
55 let mut row = 0u32;
56
57 worksheet.write_string(index(row, 0)?, "Item", Some(&bold))?;
58 worksheet.write_string(index(row, 1)?, "Cost", Some(&bold))?;
59 row += 1;
60
61 for Expense {
62 item,
63 cost,
64 datetime,
65 } in expenses.iter()
66 {
67 worksheet.write_string(index(row, 0)?, item, None)?;
68 worksheet.write_datetime(
69 index(row, 1)?,
70 *datetime,
71 Some(&date),
72 )?;
73 worksheet.write_number(index(row, 2)?, *cost, Some(&money))?;
74 row += 1;
75 }
76
77 worksheet.write_string(index(row, 0)?, "Total", Some(&bold))?;
78 worksheet.write_formula(
79 index(row, 2)?,
80 "=SUM(C2:C5)",
81 Some(&money),
82 )?;
83 }
84
85 workbook.write_file("tutorial03.xlsx")?;
86
87 Ok(())
88}
examples/format_num_format.rs (line 22)
6fn main() -> karo::Result<()> {
7 // Create a new workbook.
8 let mut workbook = Workbook::new();
9
10 {
11 let worksheet = workbook.add_worksheet(None)?;
12
13 // Widen the first column to make the text clearer.
14 worksheet.set_column(col_range(0, 0)?, 30f64, None)?;
15
16 let mut f = Format::default();
17
18 // 3.1415926
19 worksheet.write_number(index(0, 0)?, 3.1415926, None)?;
20
21 // 3.142
22 f.num_format = NumFormat::from_format_string("0.000");
23 worksheet.write_number(index(1, 0)?, 3.1415926, Some(&f))?;
24
25 // 1,235
26 f.num_format = NumFormat::from_format_string("#,##0");
27 worksheet.write_number(index(2, 0)?, 1234.56, Some(&f))?;
28
29 // 1,234.56
30 f.num_format = NumFormat::from_format_string("#,##0.00");
31 worksheet.write_number(index(3, 0)?, 1234.56, Some(&f))?;
32
33 // 49.99
34 f.num_format = NumFormat::from_format_string("0.00");
35 worksheet.write_number(index(4, 0)?, 49.99, Some(&f))?;
36
37 // 01/01/01
38 f.num_format = NumFormat::from_format_string("mm/dd/yy");
39 worksheet.write_number(index(5, 0)?, 36892.521, Some(&f))?;
40
41 // Jan 1 2001
42 f.num_format = NumFormat::from_format_string("mmm d yyyy");
43 worksheet.write_number(index(6, 0)?, 36892.521, Some(&f))?;
44
45 // 1 January 2001
46 f.num_format = NumFormat::from_format_string("d mmmm yyyy");
47 worksheet.write_number(index(7, 0)?, 36892.521, Some(&f))?;
48
49 // 01/01/2001 12:30 AM
50 f.num_format =
51 NumFormat::from_format_string("dd/mm/yyyy hh:mm AM/PM");
52 worksheet.write_number(index(8, 0)?, 36892.521, Some(&f))?;
53
54 // 1 dollar and .87 cents
55 f.num_format = NumFormat::from_format_string(
56 "0 \"dollar and\" .00 \"cents\"",
57 );
58 worksheet.write_number(index(9, 0)?, 1.87, Some(&f))?;
59
60 // Show limited conditional number formats.
61 f.num_format = NumFormat::from_format_string(
62 "[Green]General;[Red]-General;General",
63 );
64 worksheet.write_number(index(10, 0)?, 123.0, Some(&f))?; // > 0 Green
65 worksheet.write_number(index(11, 0)?, -45.0, Some(&f))?; // < 0 Red
66 worksheet.write_number(index(12, 0)?, 0.0, Some(&f))?; // = 0 Default color
67
68 // Format a Zip code
69 f.num_format = NumFormat::from_format_string("00000");
70 worksheet.write_number(index(13, 0)?, 1209.0, Some(&f))?;
71 }
72
73 workbook.write_file("format_num_format.xlsx")?;
74
75 Ok(())
76}
Trait Implementations§
impl Eq for NumFormat
impl StructuralPartialEq for NumFormat
Auto Trait Implementations§
impl Freeze for NumFormat
impl RefUnwindSafe for NumFormat
impl Send for NumFormat
impl Sync for NumFormat
impl Unpin for NumFormat
impl UnwindSafe for NumFormat
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.