write_phonetic_workbook/
write_phonetic_workbook.rs1use std::env;
2use std::error::Error;
3use std::path::PathBuf;
4
5use cellrune::{
6 CalculationOptions, CellAddress, FrozenPane, PhoneticAlignment, PhoneticProperties,
7 PhoneticRun, PhoneticTextRange, PhoneticType, PhoneticWriteOptions, RecalculationWriteOptions,
8 WorkbookDraft, calculate_workbook, write_xlsx_draft_path,
9};
10
11fn main() -> Result<(), Box<dyn Error>> {
12 let output = env::args_os()
13 .nth(1)
14 .map(PathBuf::from)
15 .ok_or("usage: write_phonetic_workbook <output.xlsx>")?;
16 let mut draft = WorkbookDraft::new();
17 let sheet_id = draft.workbook().sheets()[0].id();
18 let runs = vec![
19 PhoneticRun::new(PhoneticTextRange::new(0, 2)?, "あした")?,
20 PhoneticRun::new(PhoneticTextRange::new(3, 5)?, "がっこう")?,
21 ];
22 let options = PhoneticWriteOptions::show().with_properties(
23 PhoneticProperties::new(0)
24 .with_phonetic_type(PhoneticType::Hiragana)
25 .with_alignment(PhoneticAlignment::Center),
26 );
27 draft.set_annotated_text(
28 sheet_id,
29 CellAddress::from_a1("A1")?,
30 "明日は学校へ行く",
31 runs,
32 options,
33 )?;
34 draft.set_annotated_text(
35 sheet_id,
36 CellAddress::from_a1("A2")?,
37 "😀A",
38 vec![PhoneticRun::new(PhoneticTextRange::new(0, 2)?, "え")?],
39 PhoneticWriteOptions::show(),
40 )?;
41 draft.set_annotated_text(
42 sheet_id,
43 CellAddress::from_a1("A3")?,
44 "か\u{3099}",
45 vec![PhoneticRun::new(PhoneticTextRange::new(0, 2)?, "が")?],
46 PhoneticWriteOptions::show(),
47 )?;
48 draft.set_frozen_pane(sheet_id, FrozenPane::new(1, 1)?)?;
49
50 let calculation = calculate_workbook(draft.workbook(), CalculationOptions::default());
51 write_xlsx_draft_path(
52 &draft,
53 &calculation,
54 output,
55 RecalculationWriteOptions::default(),
56 )?;
57 Ok(())
58}