hello_world_xlsx/
hello_world_xlsx.rs1use std::path::{Path, PathBuf};
8
9use office_toolkit::excel::{CellValue, Sheet};
10use office_toolkit::prelude::*;
11use office_toolkit::{OpenFile, SaveToFile};
12
13fn main() -> office_toolkit::Result<()> {
14 let path = output_path("hello_world.xlsx");
15
16 let workbook = Workbook::new()
19 .with_sheet(Sheet::new("Sheet1").with_row(Row::new().with_text("Hello, world!")));
20 workbook.save_to_file(&path)?;
21 println!("Wrote {}", path.display());
22
23 let reopened = Workbook::open_file(&path)?;
25 let cell_a1 = &reopened.sheets[0].rows[0].cells[0].value;
26 println!("Read back A1: {cell_a1:?}");
27 assert!(matches!(cell_a1, CellValue::Text(text) if text == "Hello, world!"));
28
29 Ok(())
30}
31
32fn output_path(filename: &str) -> PathBuf {
36 Path::new(env!("CARGO_MANIFEST_DIR"))
37 .join("../../tests-data/output")
38 .join(filename)
39}