hello_world_docx/
hello_world_docx.rs1use std::path::{Path, PathBuf};
8
9use office_toolkit::prelude::*;
10use office_toolkit::{OpenFile, SaveToFile};
11
12fn main() -> office_toolkit::Result<()> {
13 let path = output_path("hello_world.docx");
14
15 let document = Document::new().with_paragraph(Paragraph::with_text("Hello, world!"));
17 document.save_to_file(&path)?;
18 println!("Wrote {}", path.display());
19
20 let reopened = Document::open_file(&path)?;
22 let text = reopened
23 .paragraphs()
24 .next()
25 .map(|paragraph| paragraph.text());
26 println!("Read back: {text:?}");
27
28 Ok(())
29}
30
31fn output_path(filename: &str) -> PathBuf {
35 Path::new(env!("CARGO_MANIFEST_DIR"))
36 .join("../../tests-data/output")
37 .join(filename)
38}