Repository navigation
fix(xlsx): quote sheet names in print area and print titles - #588
productdevbook merged 2 commits into
Conversation
buildNamedRanges wrote `_xlnm.Print_Area` and `_xlnm.Print_Titles` as
`${sheet.name}!range` without quoting. For a sheet name that needs quotes
(a space, punctuation, an apostrophe) the defined name is not a valid
reference, and Excel silently ignores it as a print setting.
Move the chart writer's quoteSheetName into _refs.ts and use it for the
derived print ranges too.
Closes productdevbook#587
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing: 3
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
| Check name | Status | Explanation |
|---|---|---|
| Linked Issues check | ✅ Passed | The change satisfies issue #587. buildNamedRanges now applies quoteSheetName to printArea, printTitlesRow, and printTitlesColumn. The helper leaves plain identifiers unchanged, quotes names … |
| Out of Scope Changes check | ✅ Passed | The changes stay within issue #587. Moving the existing helper to src/_refs.ts supports shared quoting behavior for chart references and derived print ranges. The added tests verify the requested wr… |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files. |
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title clearly and concisely describes the main change: quoting sheet names in generated print-area and print-title references. |
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
`_refs.ts` imports `cell-utils`' formula walker, so sharing `quoteSheetName` from there put 1.1 KB gzipped into `readXlsx` — the chart *reader* is in that bundle — and 0.8 KB into `writeXlsx`, taking both over `scripts/size-budget.json`. A leaf module carries the three lines instead, with the same single implementation behind productdevbook#587. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Taking this with one commit on top, and the diagnosis in the description was right — the reader strips to the last The one problem was where the shared helper landed. The three lines now live in |
Closes #587
buildNamedRangesbuilt_xlnm.Print_Areaand_xlnm.Print_Titlesas${sheet.name}!rangewith no quoting. For a sheet such asDetail Sheet, the workbook gotDetail Sheet!$1:$4, which Excel opens without complaint but ignores as a print setting.The chart series writer already had a
quoteSheetNamehelper that quotes names when needed and doubles embedded'. I moved it unchanged tosrc/_refs.tsnext tounquoteSheetand used it for the derived print ranges as well, so both writers quote the same way. A comment at the call site references #587.Output for the issue's repro:
Why the tests didn't catch it
The existing print-range tests only use sheet names that need no quoting (
Report,Sheet1). The reader strips everything up to the last!, so the round trip passed either way.Tests
Added to
test/named-ranges.test.ts:Detail Sheet(area, row titles and column titles) andO'Brien('O''Brien'!$1:$1). This one fails againstmainwithDetail Sheet!$A$1:$B$4.main, because the reader already handles quoted names. It is there so the write and read sides stay in step now that the writer quotes.Local
bun run test(Bun 1.4.2, Node 24):oxlint,oxfmt --checkand bothtsc --noEmitruns are clean.html-import.test.ts› "refuses a table whose colspans describe more cells than a sheet holds", which hits its 20s timeout on my machine during the full parallel run and passes when run on its own. That test doesn't touch this change.Not verified
<c:f>references.A1) or start with a digit-like token are quoted only if they fail^[A-Za-z_][A-Za-z0-9_]*$, which is the existing helper's rule. I didn't change that rule here.Summary by CodeRabbit