iOfficeAI / iOfficeAI/OfficeCLI
[xlsx] workbooks created by `create` lack the required `xl/styles.xml` part — Excel opens them but strict OPC parsers fail
- Dominant language
- C#
- Stars
- 30.7k
- Forks
- 2.1k
- Avg merge
- 9d 8h
- Merged PRs (30d)
- 5
Description
## Environment
- OfficeCLI v1.0.149 (official release binary, `officecli-win-x64.exe`, SHA256 verified against `SHA256SUMS`)
- Windows 11 x64; headless tool→CLI invocation (execFile, direct argv)
- Reproduction does not depend on platform: it is a package-defect of the xlsx writer
## Problem
Workbooks created by OfficeCLI lack the `xl/styles.xml` part entirely. Verified over 5 workbooks from a stress corpus (blank, data-filled, and one with embedded charts): none contain the styles part, `[Content_Types].xml` has no `/xl/styles.xml` Override, and `xl/_rels/workbook.xml.rels` has no workbook→styles relationship.
Excel opens these files fine (the absence is treated as an implied empty stylesheet), but strict OPC parsers fail with `entry not found: xl/styles.xml` — that is exactly what our integrated viewer reports.
## How to verify
```powershell
node -e "const A=require('adm-zip');const z=new A('hoja.xlsx');console.log(z.getEntries().map(e=>e.entryName).join('\n'))"
```
Observed entry list for a data-filled workbook:
```text
xl/workbook.xml
xl/worksheets/sheet1.xml
xl/theme/theme1.xml
docProps/core.xml
docProps/app.xml
docProps/custom.xml
_rels/.rels
xl/_rels/workbook.xml.rels
[Content_Types].xml
```
No `xl/styles.xml`. `[Content_Types].xml` has no Override for it; `xl/_rels/workbook.xml.rels` has no styles relationship. For comparison, docx blanks from the same binary DO include `word/styles.xml`.
## Root cause (verified against source, main @ `1f0fd19`)
`BlankDocCreator.CreateExcel()` adds `WorkbookPart` + `WorksheetPart` + `ThemePart`, but never a `WorkbookStylesPart`. The styles part only comes into existence when a cell style is applied via `ExcelStyleManager.EnsureStylesPart()` (`set --prop fill/font/numfmt/...`, hyperlinks, conditional formatting, table styles, import). A workbook created blank and then filled with plain values or charts stays without the part.
Two observations that support the fix:
1. The docx blank already stamps its `StyleDefinitionsPart` (`BlankDocCreator.CreateWord`), and the theme gap for xlsx got the same parity fix this year (`theme1.xml` — the code comment says "xlsx alone omitted it"); the styles part is the remaining gap of the same kind.
2. The OfficeCLI xlsx reader is fully null-guarded for a missing stylesheet (`ExcelHandler.HtmlPreview`, `ExcelDataFormatter`, `CheckOverflow`/`CheckNumericOverflow`/`CheckGeneralPrecision` — all fall back to defaults), so adding the part by default cannot break existing flows.
## Suggested fix (minimal)
In `BlankDocCreator.CreateExcel()`, right after the existing theme part (mirroring the earlier theme fix):
```csharp
var stylesPart = workbookPart.AddNewPart();
stylesPart.Stylesheet = ExcelStyleManager.CreateDefaultStylesheet(); // private static → internal static
stylesPart.Stylesheet.Save();
```
(Reuses the existing minimal stylesheet from `ExcelStyleManager`. A defensive secondary injection point would be `ExcelHandler.Save()`, which would also cover files created by `import` or foreign templates.)
## Notes
- We ship a temporary server-side conformance shim (inject the minimal stylesheet + Override + relationship after saving) so our product works meanwhile — but the durable fix belongs in the writer, and we would happily re-test as soon as a release includes it.
- Happy to provide the full 5-file verification corpus if useful.
Contributor guide
Research direction
Start in BlankDocCreator.CreateExcel(), then read ExcelStyleManager.EnsureStylesPart() and the existing default stylesheet implementation. Verify the generated package with the provided adm-zip command and inspect [Content_Types].xml plus xl/_rels/workbook.xml.rels. Done means blank and plain-value workbooks include xl/styles.xml with its Override and workbook relationship.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100