Skip to main content

Crate xlsxparser

Crate xlsxparser 

Source
Expand description

xlsxparser — a lightweight, high-performance .xlsx (OOXML) parser library, purpose-built for the kind of files common in Japanese business systems: sheets with an extreme number of rows/columns (“grid-paper Excel”) and heavy use of merged cells.

let workbook = xlsxparser::parse_workbook("book.xlsx")?;
let json = xlsxparser::to_json_string(&workbook)?;

§Security: CSV / formula injection

Cell string values (including formula-computed result strings, t="str") pass through into CellValue::Text and the JSON output unchanged, with no sanitization at any stage — this is safe as JSON output (serde_json escapes correctly) but not necessarily as CSV or another spreadsheet format. Callers who re-export parsed values into CSV or .xlsx are responsible for their own formula-injection mitigations (e.g. escaping a value that starts with =, +, -, or @), since a .xlsx input is untrusted and this library performs no rewriting of cell content.

Structs§

Cell
A single entry in the sparse matrix. Only cells that hold data or formatting exist in Sheet (blank cells are not instantiated).
CellRef
Cell coordinates. 1-based, matching Excel (A1 = row:1, col:1).
DateTimeValue
Placeholder type for a resolved date/time value. The concrete type is undecided (docs/design/model/cell.en.md Open Question 4); this stand-in carries no data yet.
MergedRegion
A merged range. Holds the top-left (origin cell) and bottom-right coordinates.
ResolvedStyle
Format information once a style ID has been resolved.
Sheet
Sparse matrix data for a single sheet.
SizeLimits
Public configuration type callers use to set the Zip Bomb size caps. lib.rs re-exports this at the crate root and uses it as the argument to parse_workbook_with_limits/parse_workbook_reader_with_limits. Default reuses DEFAULT_MAX_UNCOMPRESSED_SIZE / DEFAULT_MAX_TOTAL_UNCOMPRESSED_SIZE as-is, so the default-cap public functions (parse_workbook/parse_workbook_reader) need only pass SizeLimits::default() rather than duplicating the values.
Workbook
The final resolved output model. The return value of lib.rs::parse_workbook.

Enums§

CellValue
A cell’s value. Has a variant corresponding to each OOXML t attribute (cell type).
Error
The common error type used throughout the library. Every module’s failure modes, including parse_workbook’s Result::Err, are consolidated into this type. Marked #[non_exhaustive] so future variants can be added without a breaking change.
SheetVisibility
A sheet’s visibility (workbook.xml’s <sheet state="...">).

Functions§

parse_workbook
Parses .xlsx from a file path — the most common public entry point. Uses the default Zip Bomb size cap (SizeLimits::default()). To specify the cap explicitly, use parse_workbook_with_limits.
parse_workbook_reader
Parses .xlsx from any Read + Seek input (an in-memory buffer, a fully-read HTTP response body, etc.) — a general-purpose entry point for callers that don’t go through the filesystem. Requiring a seekable input to read the ZIP central directory simply carries forward ZipContainer::open_reader’s constraint (a purely streaming Read-only input cannot be opened this way). Uses the default Zip Bomb size cap (SizeLimits::default()). To specify the cap explicitly, use parse_workbook_reader_with_limits.
parse_workbook_reader_with_limits
parse_workbook_reader, plus letting the caller specify the Zip Bomb size cap explicitly. parse_workbook_reader is a thin wrapper that simply delegates here with SizeLimits::default().
parse_workbook_with_limits
parse_workbook, plus letting the caller specify the Zip Bomb size cap explicitly. parse_workbook is a thin wrapper that simply delegates here with SizeLimits::default(); the actual logic — opening a std::fs::File and delegating to the internal pipeline — lives only in this function. Beyond a failure of File::open itself, any I/O error arising during ZIP extraction or XML streaming with path left unset (None) is backfilled with the file path this function already knows before being returned.
to_json_string
A convenience version of to_json_writer that targets an in-memory Vec<u8>. Since the entire output must be held as one String, additional memory usage is O(n) in the output size (unlike to_json_writer’s O(1) — prefer to_json_writer whenever the caller can write directly to a file, HTTP response, etc.).
to_json_writer
Streams workbook out as JSON to writer. Each element of the cells array is converted from Sheet::iter_cells and written out one at a time, without buffering a whole sheet’s Vec<JsonCell> in memory. If writer is, say, a BufWriter<File>, additional memory usage stays at O(1) — one cell’s worth at a time.

Type Aliases§

Result
Crate-wide Result alias.
StyleId
The cellXfs index (style ID). Kept type-consistent with Error::InvalidStyleId(u32).