Skip to main content

Module xlsx_tools

Module xlsx_tools 

Source
Expand description

Excel-specific helpers: xlsx:merge and xlsx:frag.

merge appends one sheet per input file to an existing or new .xlsx. Inputs may be any format the engine reads; each is decoded through the canonical hub before being written. Single-table inputs use their filename stem as the sheet name; multi-sheet inputs (XLSX, ODS, multi-table SQL) prefix the sheet name with the file stem to avoid collisions. Names are truncated to Excel’s 31-character limit, and collisions after truncation get _2, _3 suffixes. Existing sheets are preserved.

frag splits an .xlsx into one JSON file per sheet, written to the current directory (or --out DIR). Sheet names are normalized the same way the merge mode formats its prefixes: NFD-decomposed, accents stripped, lowercased, non-alphanumerics collapsed to single underscores, trimmed. Empty results fall back to sheet; collisions get _2, _3.

§Examples

use sheeter_engine::xlsx_tools;
use std::fs;

let dir = tempfile::tempdir().unwrap();
fs::write(dir.path().join("a.csv"), "x\n1\n").unwrap();
fs::write(dir.path().join("b.json"), r#"[{"y":2}]"#).unwrap();
let out = dir.path().join("ss.xlsx");
xlsx_tools::merge(
    &[
        dir.path().join("a.csv").to_str().unwrap().to_string(),
        dir.path().join("b.json").to_str().unwrap().to_string(),
    ],
    out.to_str().unwrap(),
)
.unwrap();
let sheets = sheeter_engine::CanonicalValue::from_xlsx_workbook(&fs::read(out).unwrap()).unwrap();
assert_eq!(sheets.len(), 2);
assert_eq!(sheets[0].0, "a");
assert_eq!(sheets[1].0, "b");

Functions§

frag
Splits every sheet of an .xlsx into its own JSON file.
merge
Appends one sheet per input file to output.