Skip to main content

Module xlsx

Module xlsx 

Source
Expand description

GridCraft file formats: XLSX (transitional and strict) and CSV import/export, plus XLSB and ODS data import and legacy Excel 97-2003 .xls (BIFF8) import, and password-encrypted workbooks (Agile and Standard encryption).

Clean-room implementation from ECMA-376 / ISO/IEC 29500 and observed behaviour. All entry points work on byte slices (no file system access), so the crate builds for WebAssembly.

Reading is lenient: unsupported or broken optional parts are skipped and reported in ReadReport::warnings; only a missing/invalid package or workbook part is an error. Hostile input is bounded: decompressed parts are capped at 512 MB (1 GB per package), cells outside Excel’s grid are dropped and XML nesting is limited.

Structs§

CsvOptions
CSV import options.
ReadReport
What a lenient read skipped or repaired.

Enums§

DecryptError
Why an encrypted workbook couldn’t be decrypted.
Format
A file format guessed from content.
IoError
Errors from reading or writing files.
XlsxKind
Which member of the SpreadsheetML family a package is saved as. Only the content type of the workbook part differs (ECMA-376 Part 1 Workbook part; MS-OI29500 adds the macro-enabled types).

Constants§

MAX_CSV_BYTES
The largest CSV or tab-separated file written (bytes).
MAX_PART
Largest decompressed part accepted.

Functions§

check_encryption
Whether the right password could decrypt this encrypted workbook, checked without one. An error names a scheme no password opens (RC4, rights management…) or damage, so callers can say so instead of asking for a password first.
decode_text
Decodes CSV bytes with BOM-aware UTF-8 and UTF-16 handling. Without a BOM, valid UTF-8 is kept. Other bytes decode as Windows-1256 when they read as Arabic (see [Cp1256Evidence]), else as Windows-1252.
decrypt
The plain OOXML package (a zip) inside an encrypted workbook.
oversized_part
The part of a zip package that declares more than MAX_PART unpacked bytes, with that size: what an IoError::TooLarge from reading the package is about when one part is too large.
read_csv
read_csv_with_report
read_csv, with the warnings an open shows: a column whose date order had to be guessed, or whose dates stayed text because it holds both orders.
read_ods
Imports ODS sheets, typed values, displayed text and merges. Cached formula results are imported as constants, so editing their inputs does not recalculate the original formula. Always inspect the returned warnings. Saving to ODS is not supported.
read_xls
Reads an Excel 97-2003 workbook. Inspect the report’s warnings for what was skipped.
read_xlsb
Imports worksheet scalar values and saved formula results. Number formats are omitted; dates remain serial numbers with the workbook’s original date system. Inspect warnings.
read_xlsx
Reads an .xlsx / .xlsm / .xltx / .xltm package (the workbook part is found through the package relationships, so every main-part content type is accepted).
read_xlsx_with
read_xlsx, and opens formulas from Google Sheets’ XLSX export as the formulas written in Google Sheets (#2871).
rebase_links
wb as it is saved into the folder to (absolute): the relative paths of its linked workbooks, relative to the folder it was read from, are rewritten relative to to, as Excel does on Save As, or made absolute when no relative path exists (another drive). None when nothing changes.
sniff
Guesses the format from content: ODS mimetype, XLSB package content types, other ZIP packages as XLSX, text as CSV.
write_csv
Writes the sheet as CSV from A1 to the end of its used range, so leading empty columns and rows stay as empty fields and every cell keeps its position (CRLF line ends, UTF-8 without BOM). cell_text gives each cell’s field text: the caller decides how values look (Save As CSV writes them as displayed, number formats applied); quoting is done here.
write_csv_limited
write_csv with the output cap limit (bytes) given.
write_xlsx
Writes a workbook as an .xlsx package, or as an .xlsm one when it holds a VBA project.
write_xlsx_as
Writes a workbook as the given member of the .xlsx family.
write_xlsx_named
Writes a workbook as the given member of the .xlsx family for the file book_name (a bare file name, used for the workbook in a PivotChart’s link to its PivotTable).