Commit Graph
33 Commits
Author SHA1 Message Date
bdb9dae67d craft-xlsx: typed external links, and external references in binary formulas (#1347)
* craft-xlsx: typed external links, read from .xlsx and .xlsb; external references in binary formulas

ExternalLink (another workbook as ExternalBook: its target, sheet names,
defined names with refersTo and sheetId, and cached cells; a DDE or OLE link
as Other) reads from externalLinkN.xml and externalLinkN.bin alike.
Package::external_links gives one entry per Workbook::external_references,
which is now a typed field, read from externalReferences or the binary
workbook's BrtSupBookSrc records and written back from the field.

A binary formula's reference to another workbook decodes as .xlsx spells it:
[1]Data!$A$1, '[1]Other Sheet'!A1, '[1]A:C'!A1, [1]!ExtName, [1]Data!Local
for a sheet-scoped name, a DDE item [2]!'R1C1'. The link parts are read when
the workbook part is; one that can't be read, a deleted sheet of it or a name
it lacks keeps the cell's saved result.

Closes #1252.

* craft-xlsx: review fixes: external links keep their numbers, are read once, and deleted sheets keep values

- An externalReference without an r:id, or a BrtSupBookSrc whose id can't be
  read, keeps its place as an empty id, so the links after it keep their
  [n]; it is written back without r:id.
- A binary workbook's external link parts are read once, with its workbook
  part: the formulas' index and Package::external_links share that read, so
  cached cells are charged to binary_cells once.
- PtgNameX through a deleted sheet of another workbook (-1) keeps the cell's
  saved result instead of falling back to the name's own scope.

* craft-xlsx: deduplicate binary external links against budget and add cache-cap test

* craft-xlsx: avoid cloning ExternalLink on duplicate binary external references

---------

Co-authored-by: kiwi4boy <kiwi4boy@gmail.com>
Co-authored-by: FredApps <FredApps@users.noreply.github.com>
Co-authored-by: Dylan M. Taylor <dylan@dylanmtaylor.com>
2026-11-20 13:19:14 -05:00
FredApps fcf14d7d2d Merge main into XLSB tables (defined names, sizes and columns from #1330 and others) 2026-11-16 16:21:55 +01:00
FredApps 1c33c7cfc3 Merge shared XLSB sizes into defined-name integration 2026-11-16 12:19:59 +01:00
FredApps 3d75ce7e0b #1251: reconcile XLSB tables with current styles reader 2026-11-16 10:47:59 +01:00
FredApps 797e8c05b9 Merge main into XLSB names while retaining shared styles and tests 2026-11-16 10:24:13 +01:00
FredApps 6abb8cf77e Merge main into XLSB sizes, preserving shared styles and regression coverage 2026-11-16 10:20:21 +01:00
kiwi4boy 0f944f62d5 craft-xlsx: review fixes: names using a left-out name are left out; quoted sheet-scoped calls
- A name whose formula uses a name that is left out (another workbook, a
  skipped sheet, an unreadable formula) was still published, so a cell using
  it decoded and would calculate to #NAME?. Each name's formula now records
  the names it uses, and every name reached from a left-out one is left out
  too, whatever their order: once each, so a long chain costs no more than
  its uses. A cell using one keeps its saved result.
- A sheet-scoped name called as a function through PtgNameX prints its sheet
  quoted where needed ('My Sheet'!Fn(1)), as a sheet-qualified name does.
2026-11-14 12:45:29 -05:00
kiwi4boy 88287a6b46 craft-xlsx: review fixes: styles caps are too large, differential format strings are charged
- A styles table past 65,536 entries, or a gradient past 1,024 stops, is past
  a fixed cap: Error::TooLarge, as the error's contract and the other caps
  have it, not a damaged part that is skipped with a warning.
- A differential format's font name and number format are charged to
  binary_text, as the other string-bearing style records are.
2026-11-14 12:40:55 -05:00
kiwi4boy cba5007f1b Merge branch 'xlsb-formulas' into xlsb-tables
# Conflicts:
#	crates/xlsx/tests/xlsb.rs
2026-11-14 12:38:17 -05:00
kiwi4boy bf4a2897e7 Merge branch 'xlsb-formulas' into xlsb-names
# Conflicts:
#	crates/xlsx/tests/xlsb.rs
2026-11-14 12:37:51 -05:00
kiwi4boy 0d68e0c36d Merge branch 'xlsb-formulas' into xlsb-sizes
# Conflicts:
#	crates/xlsx/README.md
2026-11-14 12:37:26 -05:00
kiwi4boy 14e516edf4 Merge branch 'xlsb-formulas' into xlsb-styles 2026-11-14 12:36:13 -05:00
kiwi4boy fa5457bed6 craft-xlsx: review fixes: array constants bounded per formula, a spent allowance skips decoding
- A formula's array constants share one allowance of 65,536 values, each
  array charged before its rows are allocated. Before, the cap was per
  array, so a formula of many arrays could hold gigabytes before the formula
  text allowance was checked.
- Once binary_formula_text is spent, a formula is not decoded only to be
  dropped: it keeps its saved result straight away.
2026-11-14 12:35:54 -05:00
kiwi4boy b5eda42a33 craft-xlsx: VBA function names and macro descriptions in binary workbooks
An Excel probe with VBA enabled showed two things the names reader got
wrong:

- Excel writes a VBA function a cell calls as a BrtName with fFunc, fOB and
  fProc, no formula, and none of the four strings fProc names otherwise
  carry. The reader refused it, which dropped every name and left every
  formula as its saved result. Such a name now ends after its comment; it
  stays out of the names, as .xlsm lists none, and cells calling it spell it.
- The two middle strings of a macro's name are its description and help
  topic, as .xlsm writes them (description="Function A" help="!0"), not the
  custom menu and description the specification's labels say.
2026-11-14 12:21:06 -05:00
kiwi4boy 4a25088802 craft-xlsx: read the tables of a binary workbook
Package::tables reads a sheet's tableN.bin parts, through its BrtListParts,
into the Table the XML reader builds, as Excel writes the table in .xlsx:
BrtBeginList and its columns, the calculated and totals formulas decoded as
cell formulas are, an XML map's column properties, the table style, and the
AutoFilter and sort state built as the autoFilter and sortState elements. A
filter column whose criteria are in an extension (date groups) or on a
Boolean value is left out with a warning, as is a sort by stroke or PinYin
order.

PtgList now decodes to the structured reference .xlsx holds (Sales[Val],
Sales[[#Headers],[Key]], escaped column names, Excel's spacing flags), from
the workbook's tables, indexed when the workbook part is read. A reference
to a table that can't be read, a deleted table or another workbook keeps
the cell's saved result.

Closes #1251.
2026-11-14 12:16:33 -05:00
kiwi4boy b11a5a38b8 Merge branch 'xlsb-formulas' into xlsb-names
# Conflicts:
#	crates/xlsx/README.md
#	crates/xlsx/tests/xlsb.rs
2026-11-14 12:08:55 -05:00
kiwi4boy 6c364459f3 Merge branch 'xlsb-formulas' into xlsb-sizes
# Conflicts:
#	crates/xlsx/README.md
#	crates/xlsx/tests/xlsb.rs
2026-11-14 12:07:25 -05:00
kiwi4boy 259afde541 Merge branch 'xlsb-formulas' into xlsb-styles
# Conflicts:
#	crates/xlsx/README.md
#	crates/xlsx/tests/xlsb.rs
2026-11-14 12:04:49 -05:00
kiwi4boy abceed3f17 craft-xlsx: binary formulas keep typed spacing and Excel's number spelling
Checked against a wider Excel probe (every worksheet function Excel
accepts, operators, references, constants, spacing, shared and array
formulas), three differences from the .xlsx text are fixed:

- PtgAttrSpace: the spaces and line breaks typed in a formula are kept
  where Excel writes them in .xlsx (before an operand, an operator's
  symbol or a call, after a parenthesis's or call's opening and before its
  closing), and the text is trimmed as the .xlsx reader trims it.
- Numbers are written out in full when that takes at most 21 characters
  (100000000000000000000, 0.0000000000000000001), scientific past that
  (1E+21, 1.5E-19, 1.23456789012345E-06), as Excel spells them.
- ISO.CEILING, ECMA.CEILING, NETWORKDAYS.INTL and WORKDAY.INTL are called
  through hidden _xlfn. names in .xlsb, but .xlsx names them bare.
2026-11-14 11:56:51 -05:00
kiwi4boy d2b6416db9 craft-xlsx: binary styles: legacy number formats, automatic font colours, tinted fills
A broader Excel probe found three differences from the styles.xml Excel
writes for the same workbook:

- A number format with a newer locale tag ([$-ja-JP-x-gannen]) is only in
  alternate content: the newer spelling in a block for later versions, and
  the one .xlsx keeps as formatCode in a block listing version 12 onwards.
  The styles part now reads the alternate content meant for Excel 2007
  (version 12), so the format is no longer lost.
- A font whose colour is automatic has no <color> in .xlsx.
- A pattern fill whose pattern colour has a tint states the system
  background (bgColor indexed 65), as Excel's .xlsx does for any pattern.
2026-11-14 11:32:40 -05:00
kiwi4boy 2a786e27a2 craft-xlsx: names on macro sheets, spans over chart sheets, formula-less built-ins
A second Excel probe showed three cases where the .xlsb reader left out what
.xlsx has:

- Macro names point at an XLM macro sheet (Macro1!$A$1), which the sheet
  links treated as a sheet with no cells, so every such name was left out.
  Macro sheets have cells; references to them are now named.
- A 3-D span over a chart sheet ('Data:After Sheet'!$A$1) was refused. A
  span is spelled by its ends; a sheet with no cells between them adds
  nothing, and .xlsx spells it the same.
- Excel writes a workbook-level built-in with no formula (Database) beside
  a sheet's own. .xlsx leaves it out of definedNames, but formulas using it
  spell _xlnm.Database; they now do instead of keeping their saved results.
2026-11-14 11:30:32 -05:00
kiwi4boy e7914038f3 craft-xlsx: read the defined names of a binary workbook
Each BrtName becomes a DefinedName as Excel writes it in .xlsx: built-in
names as _xlnm.Print_Area, sheet scope as localSheetId, the formula decoded
with relative references as offsets from A1, the comment, hidden, and a
macro's function, vbProcedure or xlm, functionGroupId, shortcutKey,
publishToServer and workbookParameter. The hidden names for newer functions
and LET parameters are left out, as .xlsx does.

Cell formulas using a name that was read now decode instead of keeping
their saved results, PtgNameX through the workbook's own link is
'Other Sheet'!Local, and a deleted 3-D reference is Sheet2!#REF!, as in
.xlsx. A name whose formula can't be read is left out with a warning, and
formulas using it keep their saved results.

Closes #1250.
2026-11-14 09:55:35 -05:00
kiwi4boy c950dacd39 craft-xlsx: read row heights, column widths and default sizes of a binary sheet
BrtRowHdr fills Row's height, custom height, hidden, outline level, collapsed
and style (with thickTop, thickBot and ph kept as the XML reader keeps them);
BrtColInfo fills SheetPart::columns; BrtWsFmtInfo fills the new typed
Features::format (SheetFormat, mirroring sheetFormatPr), which the .xlsx
reader now fills too and to_xml writes from the field.

A row's ht follows Excel's .xlsx: set by hand, or differing from the
default. Column ranges outside the grid are skipped with a warning, column
records are capped at 16,384, and heights past 8,192 twips are ignored.

Closes #1254.
2026-11-13 23:50:23 -05:00
kiwi4boy 3e957e0fd1 craft-xlsx: read the styles part of a binary workbook
Package::styles() reads styles.bin into the same Styles the XML part
gives: number formats, fonts, fills, borders, cell and cell style
formats, cell styles, differential formats and indexed colours, spelled
as Excel writes them in styles.xml. A damaged part is a warning and no
styles; each table holds at most 65,536 entries.

Closes #1253.
2026-11-13 23:35:18 -05:00
kiwi4boy 20050077ad craft-xlsx: the README describes formulas in binary workbooks
They were "token streams that are not decoded". The README now says what the decoder gives
(text in the file's spelling, shared and array kinds and ranges, cell metadata, each shared copy's
own text), what keeps its saved result and why, that the function table and printer are this
crate's own, and the binary_formula_text limit with the decoder's fixed bounds.
2026-11-12 23:36:47 -05:00
Dylan M. Taylor 7dcc9950a1 craft-xlsx: pictures in cells and dynamic-array metadata
craft-xlsx: pictures in cells and dynamic-array metadata

* craft-xlsx: read parts with canonical prefixes so kept trees can be written back

The part layer read every part by local name, so extLst children (x14:, xr:, xm:),
mc:AlternateContent and r:id lost their namespaces and could not be written back.
Parts are now read with one fixed prefix per namespace (the main namespace unprefixed),
mc:Ignorable and mc:Choice/@Requires are rewritten to match, and ns::declare prepares a
kept tree for writing. craft-xml: a namespace listed with the empty prefix reads unprefixed.

* craft-xlsx: write SpreadsheetML workbooks (Document read and write)

Document holds a whole workbook: the workbook part, shared strings, styles, each worksheet's
rows and the rest of its part, and every other part kept as bytes. write regenerates the
workbook part, worksheets, shared strings and styles from the model, keeps unknown children
in place (schema order for regenerated ones), keeps part names and relationship ids, and
writes kept parts unchanged. Writers: Styles::to_xml and to_el for each table entry,
StringItem::to_el (phonetic runs checked as on reading), SheetPart::to_xml with rows
streamed, Workbook::to_el, XlsxKind. Row and DefinedName keep their other attributes;
CellStyle reads iLevel. craft-opc: LazyPackage::canonical gives a part's stored name.

* craft-xlsx: typed worksheet features and comments, written back

SheetPart::features lifts sheet views, print setup, data validation, conditional formats,
hyperlinks and the legacy drawing into types that mirror their elements (optional attributes,
unnamed ones kept) and writes them in schema order. Comments come from the comments part,
note shapes from the VML drawing; a sheet that gains comments without a VML drawing gets one.
A hyperlink to a new URL gets its own relationship. craft-sheet: Range derives Default.

* craft-xlsx: drawings, charts and the theme on craft-drawingml

Drawing reads a sheet's xdr:wsDr into anchors with typed placements and objects kept as
written; Anchor gives the object's kind, properties, chart or image relationship and xfrm.
Package::drawing, Package::chart (c: and cx: parts through craft-drawingml) and
Package::theme. Document worksheets hold their drawing part, regenerated with its
relationships kept by id; add_chart and add_picture add new chart parts (chartEx behind
mc:AlternateContent) and images with their anchors. More drawing namespaces get prefixes
(a16, asvg, aink, am3d, cx1-cx4, dgm).

* craft-xlsx: tables (ListObjects) read and written back

Table mirrors CT_Table: every attribute, columns with calculated and totals formulas, the
style info, autoFilter/sortState/extensions kept as written. Package::tables reads a sheet's
table parts; Document worksheets hold them as TableParts, regenerated with their
relationships and tableParts entries. Part names a document keeps are reserved before new
parts are named, so a new part never takes a name a later sheet keeps.

* craft-xlsx: PivotTables (caches, records, tables) read and written

Typed pivot cache definitions (source, fields, shared items, grouping),
streamed cache records and PivotTable definitions (location, fields and
items, axes, page and data fields, style), with every unmodelled child
and attribute kept. Workbook::pivot_caches lifts pivotCaches. A Document
holds caches and tables and regenerates their parts, relationships and
pivotCaches entries; an OLAP cache or a table on one stays a kept part.
SharedItems::describe gives Excel's shared-item flags and records_xml
writes a records part, after GridCraft's pivot writer.

* craft-xlsx: pictures in cells and dynamic-array metadata

Package::cell_pictures follows a cell's vm through the value and future
metadata to its _localImage rich value and image, bounded and lenient as
GridCraft's richdata.rs reads it. Document::add_cell_metadata writes the
metadata part (XLDAPR for dynamic arrays, XLRICHVALUE for pictures), the
rich-value parts and the images as GridCraft writes them.
2026-11-11 22:44:39 -05:00
Dylan M. Taylor d1f10a9612 craft-xlsx: PivotTables (caches, records, tables) read and written (#1074)
* craft-xlsx: read parts with canonical prefixes so kept trees can be written back

The part layer read every part by local name, so extLst children (x14:, xr:, xm:),
mc:AlternateContent and r:id lost their namespaces and could not be written back.
Parts are now read with one fixed prefix per namespace (the main namespace unprefixed),
mc:Ignorable and mc:Choice/@Requires are rewritten to match, and ns::declare prepares a
kept tree for writing. craft-xml: a namespace listed with the empty prefix reads unprefixed.

* craft-xlsx: write SpreadsheetML workbooks (Document read and write)

Document holds a whole workbook: the workbook part, shared strings, styles, each worksheet's
rows and the rest of its part, and every other part kept as bytes. write regenerates the
workbook part, worksheets, shared strings and styles from the model, keeps unknown children
in place (schema order for regenerated ones), keeps part names and relationship ids, and
writes kept parts unchanged. Writers: Styles::to_xml and to_el for each table entry,
StringItem::to_el (phonetic runs checked as on reading), SheetPart::to_xml with rows
streamed, Workbook::to_el, XlsxKind. Row and DefinedName keep their other attributes;
CellStyle reads iLevel. craft-opc: LazyPackage::canonical gives a part's stored name.

* craft-xlsx: typed worksheet features and comments, written back

SheetPart::features lifts sheet views, print setup, data validation, conditional formats,
hyperlinks and the legacy drawing into types that mirror their elements (optional attributes,
unnamed ones kept) and writes them in schema order. Comments come from the comments part,
note shapes from the VML drawing; a sheet that gains comments without a VML drawing gets one.
A hyperlink to a new URL gets its own relationship. craft-sheet: Range derives Default.

* craft-xlsx: drawings, charts and the theme on craft-drawingml

Drawing reads a sheet's xdr:wsDr into anchors with typed placements and objects kept as
written; Anchor gives the object's kind, properties, chart or image relationship and xfrm.
Package::drawing, Package::chart (c: and cx: parts through craft-drawingml) and
Package::theme. Document worksheets hold their drawing part, regenerated with its
relationships kept by id; add_chart and add_picture add new chart parts (chartEx behind
mc:AlternateContent) and images with their anchors. More drawing namespaces get prefixes
(a16, asvg, aink, am3d, cx1-cx4, dgm).

* craft-xlsx: tables (ListObjects) read and written back

Table mirrors CT_Table: every attribute, columns with calculated and totals formulas, the
style info, autoFilter/sortState/extensions kept as written. Package::tables reads a sheet's
table parts; Document worksheets hold them as TableParts, regenerated with their
relationships and tableParts entries. Part names a document keeps are reserved before new
parts are named, so a new part never takes a name a later sheet keeps.

* craft-xlsx: PivotTables (caches, records, tables) read and written

Typed pivot cache definitions (source, fields, shared items, grouping),
streamed cache records and PivotTable definitions (location, fields and
items, axes, page and data fields, style), with every unmodelled child
and attribute kept. Workbook::pivot_caches lifts pivotCaches. A Document
holds caches and tables and regenerates their parts, relationships and
pivotCaches entries; an OLAP cache or a table on one stays a kept part.
SharedItems::describe gives Excel's shared-item flags and records_xml
writes a records part, after GridCraft's pivot writer.
2026-11-11 22:13:49 -05:00
Dylan M. Taylor a19cf6753b craft-xlsx: tables (ListObjects) read and written back (#1062)
* craft-xlsx: read parts with canonical prefixes so kept trees can be written back

The part layer read every part by local name, so extLst children (x14:, xr:, xm:),
mc:AlternateContent and r:id lost their namespaces and could not be written back.
Parts are now read with one fixed prefix per namespace (the main namespace unprefixed),
mc:Ignorable and mc:Choice/@Requires are rewritten to match, and ns::declare prepares a
kept tree for writing. craft-xml: a namespace listed with the empty prefix reads unprefixed.

* craft-xlsx: write SpreadsheetML workbooks (Document read and write)

Document holds a whole workbook: the workbook part, shared strings, styles, each worksheet's
rows and the rest of its part, and every other part kept as bytes. write regenerates the
workbook part, worksheets, shared strings and styles from the model, keeps unknown children
in place (schema order for regenerated ones), keeps part names and relationship ids, and
writes kept parts unchanged. Writers: Styles::to_xml and to_el for each table entry,
StringItem::to_el (phonetic runs checked as on reading), SheetPart::to_xml with rows
streamed, Workbook::to_el, XlsxKind. Row and DefinedName keep their other attributes;
CellStyle reads iLevel. craft-opc: LazyPackage::canonical gives a part's stored name.

* craft-xlsx: typed worksheet features and comments, written back

SheetPart::features lifts sheet views, print setup, data validation, conditional formats,
hyperlinks and the legacy drawing into types that mirror their elements (optional attributes,
unnamed ones kept) and writes them in schema order. Comments come from the comments part,
note shapes from the VML drawing; a sheet that gains comments without a VML drawing gets one.
A hyperlink to a new URL gets its own relationship. craft-sheet: Range derives Default.

* craft-xlsx: drawings, charts and the theme on craft-drawingml

Drawing reads a sheet's xdr:wsDr into anchors with typed placements and objects kept as
written; Anchor gives the object's kind, properties, chart or image relationship and xfrm.
Package::drawing, Package::chart (c: and cx: parts through craft-drawingml) and
Package::theme. Document worksheets hold their drawing part, regenerated with its
relationships kept by id; add_chart and add_picture add new chart parts (chartEx behind
mc:AlternateContent) and images with their anchors. More drawing namespaces get prefixes
(a16, asvg, aink, am3d, cx1-cx4, dgm).

* craft-xlsx: tables (ListObjects) read and written back

Table mirrors CT_Table: every attribute, columns with calculated and totals formulas, the
style info, autoFilter/sortState/extensions kept as written. Package::tables reads a sheet's
table parts; Document worksheets hold them as TableParts, regenerated with their
relationships and tableParts entries. Part names a document keeps are reserved before new
parts are named, so a new part never takes a name a later sheet keeps.
2026-11-11 22:09:08 -05:00
Dylan M. Taylor 1acdb0dd68 craft-xlsx: drawings, charts and theme on craft-drawingml (#1058)
* craft-xlsx: read parts with canonical prefixes so kept trees can be written back

The part layer read every part by local name, so extLst children (x14:, xr:, xm:),
mc:AlternateContent and r:id lost their namespaces and could not be written back.
Parts are now read with one fixed prefix per namespace (the main namespace unprefixed),
mc:Ignorable and mc:Choice/@Requires are rewritten to match, and ns::declare prepares a
kept tree for writing. craft-xml: a namespace listed with the empty prefix reads unprefixed.

* craft-xlsx: write SpreadsheetML workbooks (Document read and write)

Document holds a whole workbook: the workbook part, shared strings, styles, each worksheet's
rows and the rest of its part, and every other part kept as bytes. write regenerates the
workbook part, worksheets, shared strings and styles from the model, keeps unknown children
in place (schema order for regenerated ones), keeps part names and relationship ids, and
writes kept parts unchanged. Writers: Styles::to_xml and to_el for each table entry,
StringItem::to_el (phonetic runs checked as on reading), SheetPart::to_xml with rows
streamed, Workbook::to_el, XlsxKind. Row and DefinedName keep their other attributes;
CellStyle reads iLevel. craft-opc: LazyPackage::canonical gives a part's stored name.

* craft-xlsx: typed worksheet features and comments, written back

SheetPart::features lifts sheet views, print setup, data validation, conditional formats,
hyperlinks and the legacy drawing into types that mirror their elements (optional attributes,
unnamed ones kept) and writes them in schema order. Comments come from the comments part,
note shapes from the VML drawing; a sheet that gains comments without a VML drawing gets one.
A hyperlink to a new URL gets its own relationship. craft-sheet: Range derives Default.

* craft-xlsx: drawings, charts and the theme on craft-drawingml

Drawing reads a sheet's xdr:wsDr into anchors with typed placements and objects kept as
written; Anchor gives the object's kind, properties, chart or image relationship and xfrm.
Package::drawing, Package::chart (c: and cx: parts through craft-drawingml) and
Package::theme. Document worksheets hold their drawing part, regenerated with its
relationships kept by id; add_chart and add_picture add new chart parts (chartEx behind
mc:AlternateContent) and images with their anchors. More drawing namespaces get prefixes
(a16, asvg, aink, am3d, cx1-cx4, dgm).
2026-11-11 21:59:45 -05:00
Dylan M. Taylor 7b936bf293 craft-xlsx: typed worksheet features (views, print, validation, conditional formats, hyperlinks, comments) (#1048)
* craft-xlsx: read parts with canonical prefixes so kept trees can be written back

The part layer read every part by local name, so extLst children (x14:, xr:, xm:),
mc:AlternateContent and r:id lost their namespaces and could not be written back.
Parts are now read with one fixed prefix per namespace (the main namespace unprefixed),
mc:Ignorable and mc:Choice/@Requires are rewritten to match, and ns::declare prepares a
kept tree for writing. craft-xml: a namespace listed with the empty prefix reads unprefixed.

* craft-xlsx: write SpreadsheetML workbooks (Document read and write)

Document holds a whole workbook: the workbook part, shared strings, styles, each worksheet's
rows and the rest of its part, and every other part kept as bytes. write regenerates the
workbook part, worksheets, shared strings and styles from the model, keeps unknown children
in place (schema order for regenerated ones), keeps part names and relationship ids, and
writes kept parts unchanged. Writers: Styles::to_xml and to_el for each table entry,
StringItem::to_el (phonetic runs checked as on reading), SheetPart::to_xml with rows
streamed, Workbook::to_el, XlsxKind. Row and DefinedName keep their other attributes;
CellStyle reads iLevel. craft-opc: LazyPackage::canonical gives a part's stored name.

* craft-xlsx: typed worksheet features and comments, written back

SheetPart::features lifts sheet views, print setup, data validation, conditional formats,
hyperlinks and the legacy drawing into types that mirror their elements (optional attributes,
unnamed ones kept) and writes them in schema order. Comments come from the comments part,
note shapes from the VML drawing; a sheet that gains comments without a VML drawing gets one.
A hyperlink to a new URL gets its own relationship. craft-sheet: Range derives Default.
2026-11-11 21:07:34 -05:00
Dylan M. Taylor ae085a2f7e craft-xlsx: write SpreadsheetML workbooks (Document read/write) (#1041)
* craft-xlsx: read parts with canonical prefixes so kept trees can be written back

The part layer read every part by local name, so extLst children (x14:, xr:, xm:),
mc:AlternateContent and r:id lost their namespaces and could not be written back.
Parts are now read with one fixed prefix per namespace (the main namespace unprefixed),
mc:Ignorable and mc:Choice/@Requires are rewritten to match, and ns::declare prepares a
kept tree for writing. craft-xml: a namespace listed with the empty prefix reads unprefixed.

* craft-xlsx: write SpreadsheetML workbooks (Document read and write)

Document holds a whole workbook: the workbook part, shared strings, styles, each worksheet's
rows and the rest of its part, and every other part kept as bytes. write regenerates the
workbook part, worksheets, shared strings and styles from the model, keeps unknown children
in place (schema order for regenerated ones), keeps part names and relationship ids, and
writes kept parts unchanged. Writers: Styles::to_xml and to_el for each table entry,
StringItem::to_el (phonetic runs checked as on reading), SheetPart::to_xml with rows
streamed, Workbook::to_el, XlsxKind. Row and DefinedName keep their other attributes;
CellStyle reads iLevel. craft-opc: LazyPackage::canonical gives a part's stored name.
2026-11-11 21:01:51 -05:00
Dylan M. Taylor 34aa8c1cfd craft-xlsx: read parts with canonical prefixes so kept trees can be written back (#1031)
The part layer read every part by local name, so extLst children (x14:, xr:, xm:),
mc:AlternateContent and r:id lost their namespaces and could not be written back.
Parts are now read with one fixed prefix per namespace (the main namespace unprefixed),
mc:Ignorable and mc:Choice/@Requires are rewritten to match, and ns::declare prepares a
kept tree for writing. craft-xml: a namespace listed with the empty prefix reads unprefixed.
2026-11-11 20:46:37 -05:00
Dylan M. Taylorandkiwi4boy 119415f46f Add craft-xlsx: XLSX and XLSB part layer (workbook, strings, styles, streamed rows) (#976)
* Add craft-sheet: the cell positions, values and tables the spreadsheet formats share

craft-xls carried its own CellRef, Range, Value, CellError, Visibility, sheet-name
quoting, built-in number format table and indexed palette. craft-xlsx and craft-ods
need the same ones, so they move to a crate with no dependencies and craft-xls
re-exports them: an application gets one Value and one CellRef whichever file it read.

Added on the way: A1 parsing (CellRef::parse, Range::parse), Range::count and a1,
CellError::parse and the newer error values SpreadsheetML stores as text,
builtin_format_id for writers.

* Add craft-xlsx: the part layer of XLSX and XLSB workbooks

Package::open finds the workbook part through craft-opc and reads the workbook
part, shared strings (runs and phonetic readings), the styles tables as indexed
tables, and a worksheet's rows one at a time with the rest of the part as a tree.
Binary workbooks give the same workbook, strings, rows and merged cells from their
records. Every other part stays reachable through Package::opc.

From GridCraft crates/xlsx (7e0d96d7): read.rs, sheet_read.rs, styles.rs, xml.rs
(string items, xstring escapes), xlsb.rs and its tests, split from GridCraft's
document model.

* craft-xlsx: XLSB opens up to 4 million cells, records counted once over the workbook

Binary workbooks over 1 million cells were refused, a quarter of what .xls allows,
and an allowance of 5 million records per part refused ordinary files: Excel writes
four records per non-empty row besides the cells, and one BrtCellBlank for every
formatted empty cell. Cells are now 4 million over the workbook (also the most
shared strings), text 256 MiB, and records 40 million for every part together, as
in craft-xls.

Ported from storytold/gridcraft#3807.

---------

Co-authored-by: kiwi4boy <kiwi4boy@gmail.com>
2026-11-11 19:32:04 -05:00