Repository navigation
Conversation
`pageSetup: { fitToWidth: 1, fitToHeight: 0 }` without `fitToPage: true`
wrote neither `<sheetPr><pageSetUpPr fitToPage="1"/>` nor the counts on
`<pageSetup>`, so the sheet printed at 100% with no warning. The reader
already treats either count as turning fit mode on, and the writer
already lets `firstPageNumber` imply `useFirstPageNumber`; fit to page
was the odd one out.
Both writer sites now go through one `isFitToPage` helper:
`fitToPage ?? (fitToWidth !== undefined || fitToHeight !== undefined)`.
An explicit `fitToPage: false` still wins and writes neither the flag
nor the counts, which only take effect in fit mode. Doc comments on the
three `PageSetup` fields describe the implication and that `0` means
"as many pages as needed".
Closes productdevbook#596
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
Closes #596
What was wrong
The writer emitted the fit-to-page counts only when
fitToPage: truewas also set. Without it, they were dropped without a warning:So the sheet printed at 100%. Reading the file back gave a
pageSetupwith only the default margins. WithfitToPage: trueadded, the output was correct and it still is.The reader already treats either count as turning fit mode on. The writer also already lets
firstPageNumberimplyuseFirstPageNumber. Fit to page was the only setting where the writer required the flag.Why the tests didn't catch it
Every fit-to-page test in
print-settings.test.ts,real-world.test.ts,xlsx-write-read-parity.test.tsand thepage-setup-attributes.test.tsregister setfitToPage: truetogether with the counts. No test wrote the counts on their own. The reader test for a lonefitToHeight(coverage-xlsx-worksheet.test.ts) parses hand-written XML, so it never touches the writer.What landed
isFitToPage(ps)helper inworksheet-writer.ts:fitToPage ?? (fitToWidth !== undefined || fitToHeight !== undefined). The<pageSetUpPr>check inwriteWorksheetXmland the count attributes inserializePageSetupboth use it. An explicitfitToPage: falsestill wins and writes neither the flag nor the counts, because the counts only take effect in fit mode.PageSetup.fitToPage,fitToWidthandfitToHeightdescribe the implication and say that0means "as many pages as needed".writeXlsxStream/writeXlsxStreamSheetshave nopageSetupsupport, so nothing changes there.docs/PARITY.mdalready says everyCT_PageSetupattribute round-trips, so this brings the code in line with it and the page needs no edit.Tests: three of the four new tests in
print-settings.test.tsfail againstmain: counts only,fitToHeightonly, and the round trip throughreadXlsx. The fourth checks thatfitToPage: falsewith counts writes nothing, which already worked and is there to stop the implication from overriding an explicitfalse.bun run testpasses on Node 24.22.0, with 240 files and 10,702 tests.Checked in Excel
In Excel for Mac, with a 20-column sheet written by
mainand by this branch. Both files open without a repair prompt.The XML matches what the existing
fitToPage: truepath already writes, so this change only makes that path reachable without the flag.Not verified
Summary by CodeRabbit
Documentation
Bug Fixes