[BUG] xlsx: a targeted edit re-serializes every untouched worksheet part (default namespace → `x:` prefix)
Summary
Editing a single cell rewrites every worksheet part in the package, including sheets the command never addressed. The rewrite also changes the namespace style: Excel and openpyxl emit the default-namespace form (<worksheet xmlns="...">, <c>, <f>), while OfficeCLI emits the prefixed form (<x:worksheet>, <x:c>, <x:f>).
This is the xlsx counterpart of #267 (pptx: targeted edit re-serializes every untouched slide part).
Content is preserved — see the impact section — so this is a round-trip fidelity issue rather than a data-loss one.
Environment
- OfficeCLI:
1.0.144 - OS: Windows 11 (x64)
- Source XLSX producers tested: Microsoft Excel (365), openpyxl
Reproduction
- In Excel, create a workbook with a few cells and one formula (
=B2*2), save asrepro.xlsx. - Edit one cell:
officecli set repro.xlsx "/Sheet1/D1" --prop value=EDITED --json
officecli close repro.xlsx
- Inspect
xl/worksheets/sheet1.xml:
before: <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" ...><sheetData><row ...><c r="A1" ...>
after: <x:worksheet xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main" ...><x:sheetData><x:row ...><x:c r="A1" ...>
On a 4-sheet Excel-authored workbook (~60k declared cells), editing one cell on sheet 4 rewrote all four worksheet parts this way — sheets 1–3 were never addressed by the command.
Impact (measured)
Verified not broken: values, formulas and styles survive. On the 4-sheet workbook, openpyxl reads the rewritten file and 5200 compared cells match the original exactly; python-calamine and Excel also read it correctly and formulas recalculate.
What it does cost:
- No untouched part is byte-preserved. Any package-level integrity check, cache keyed on part hashes, or review of "what did the tool actually change" sees the whole workbook as modified.
- Size growth: the prefixed form is more verbose —
xl/worksheets/sheet1.xmlgrew from 383,485 to 450,730 bytes (+17.5%) uncompressed for a workbook whose data did not change. - Serialization flip-flop: alternating edits between openpyxl/Excel and OfficeCLI rewrite the whole worksheet set each time, in opposite directions.
- Consumers that match the XML literally (regex-based scanners rather than namespace-aware parsers) stop matching after the change.
Note that a plain git diff is not affected in the obvious way: worksheet XML is emitted as a single line with no newlines, and git treats .xlsx as binary regardless. The churn shows up in XML-aware or pretty-printing diff pipelines.
Expected
Worksheet parts the command did not address are byte-preserved, and the edited part keeps the input's serialization style (or there is an option to preserve it).
Actual
All worksheet parts are re-serialized with the x: prefix on any save.
Fixed on main (next release) — really precise report, and the "xlsx counterpart of #267" framing was exactly right. Root cause: the stale-formula-cache sweep that runs after an edit iterated every worksheet and materialized each part's DOM; the SDK then re-serializes any materialized part on save (with its x:-prefixed default), so one cell edit rewrote the whole workbook. The sweep now probes each worksheet's raw stream for a formula cell first and skips any sheet that is neither edited nor formula-bearing, so those parts stay byte-identical (no x: reflip, no size growth). Verified on a multi-sheet workbook: a data-only untouched sheet is byte-preserved while formula sheets still refresh. Note this matches #267's scope — the edited part and formula sheets are still re-serialized; fully preserving the touched part's original serialization is a separate, larger change.
Verified fixed in v1.0.145 (commit 18252ac) — thanks!
On my 4-sheet Excel-authored workbook, editing one cell on sheet 4 now leaves the genuinely untouched sheets byte-identical (md5 match). The only other part rewritten was the one sheet containing a formula, which is fair game for recalculation. The rewritten parts still switch to the x: prefixed serialization, but the core issue — untouched parts being re-serialized — is resolved, so closing.