Skip to content

fix(cell): number the printed pages across the sheets of an ODS workbook - #260

Open
chrip wants to merge 12 commits into
mainfrom
fix/ods-page-numbers-continue-across-sheets
Open

chrip wants to merge 12 commits into
mainfrom
fix/ods-page-numbers-continue-across-sheets

Conversation

@chrip

@chrip chrip commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A spreadsheet from ODS that is printed with page numbers in its headers or footers starts again at 1 on every sheet. In ODF the printed pages are numbered across the whole document, as LibreOffice Calc does: sheet 2 goes on where sheet 1 stopped. Only a sheet whose page style sets a first page number starts again, and the sheets after it continue from there.

Depends on

  • fix(x2t): record the source file type of a workbook from ODS in Editor.bin core#364 (merged: x2t writes the source file type into Editor.bin). isOpenDocumentSource() reads sourceFileType from Editor.bin. This PR takes effect once DocumentServer's core pin includes #364; with an older x2t the PDF export of a 3-sheet ODS where sheet 2 starts at 5 still prints 1 2 5 6 1 2 instead of 1 2 5 6 7 8.
  • fix(sse): write the print panel's first page number only when set or edited web-apps#473 (print panel). For a sheet without a first page number the print panel shows 1, and any change in the panel wrote that 1 into the sheet, which made the sheet start again at 1. That PR writes the first page number only when it was edited or the sheet already has one. It has to land with this PR or before it.
  • fix(OdfFile): continue the page numbers when saving a workbook from ODS core#435 (ODS export, stacked on #364). Saving a workbook from ODS dropped first-page-number="continue", so LibreOffice numbered the saved file differently (1 2 1 2 1 2 instead of 1 to 6). That PR writes "continue" for the sheets without a first page number of a workbook from ODS. Without it this PR still prints correctly in Euro-Office, but a file saved by Euro-Office prints differently in LibreOffice.

Change

For a workbook from ODS, flat ODS or an ODS template, drawForPrint asks the new _getOdfPrintPageNumbering for the index of the page since the last restart and the number of the first page of that run, modelled on LibreOffice's print code:

  • a sheet with its own first page number starts again;
  • a sheet without one continues from the last sheet that has one, or from 1;
  • only the sheets of the print job count (calcPagesPrint records them in CPrintPagesData.jobSheets, also those without printed pages), so a sheet printed alone starts at its own number or 1, and an empty first sheet of the job still passes on its number. drawForPrint gets them as a new last argument from the print path and the print preview; pages without jobSheets get no ODF numbering;
  • printing the whole workbook keeps hidden sheets among the sheets of the job, as LibreOffice does: a hidden sheet prints no pages but passes on its first page number (3 sheets of 2 pages, sheet 2 hidden and starting at 5: 1 2, then 5 6);
  • the count follows the print order of the job: selected tabs print in the order they were selected, so a sheet printed first never takes its number from a sheet printed after it;
  • a first page number of 0 means "continue";
  • the first page and odd/even headers use the same index, so the first page header is shown on the first page of the run and odd/even follow the position in the run, not the printed number (as LibreOffice 24.2 does: a run that starts at 4 gets the first page header on page 4 and the even header on page 5);
  • print preview settings of a sheet win over the sheet's own.

Known differences (the first two because page style names are not kept in the spreadsheet model):

  • LibreOffice continues when the next sheet uses the very same page style with a first page number. Here every sheet with its own first page number starts again (files saved from XLSX, where every sheet has its own page style, behave as in LibreOffice).
  • LibreOffice starts again at 1 when the next sheet switches to a page style that sets no first page number at all (only "continue" continues). The converter does not tell "not set" from "continue" apart, so here such a sheet continues. With the core PR above, a file saved by Euro-Office writes "continue" for such sheets, so after a save LibreOffice numbers it as Euro-Office does.
  • LibreOffice prints and numbers selected sheets in sheet order. Here selected sheets print in the order they were selected, and the numbers follow the pages: with sheet 3 selected before sheet 1, and sheet 1 starting at 5, LibreOffice numbers sheet 1 as 5, 6 and sheet 3 as 7, 8; here sheet 3 prints first as 1, 2 and sheet 1 as 5, 6.

The first two could be fixed in the converter by writing a first page number only where LibreOffice starts again.

The run's first number reaches the page number field through a new optional argument of drawHeaderFooter, calculateTokens and calculateText. XLSX and other sources keep the per-sheet numbering.

Tests

QUnit, print json params suite (tests/cell/spreadsheet-calculation/PrintJsonParamsTests.js):

  • ODF numbering: XLSX and unknown sources get none; for ODS, flat ODS and ODS templates the pages are numbered across the sheets, a sheet with its own first page number starts again and the sheets after it continue, a numbered sheet of the job without printed pages still passes on its number, 0 continues, a sheet printed alone takes no number from the sheets before it, a numbered sheet outside the job passes nothing on, sheets selected out of order are numbered in print order. Every case passes the job's sheets as calcPagesPrint records them; pages without them get no ODF numbering.
  • drawForPrint hands the index and first number to the header/footer for ODS (a numbered and an unnumbered second sheet) and XLSX.
  • The real drawHeaderFooter (only _drawHeaderFooter stubbed): the page number text of header and footer runs on across the sheets, and the first page header is used at the start of each run, then even and odd.
  • Print preview: a first page number set or cleared in the preview's page options wins over the sheet's own, only while the preview is open.
  • drawForPrint with printed pages (cells, drawings and fonts stubbed), the path real printing takes.
  • calcPagesPrint (with the real _calcPagesPrintSheet) records the sheets of the job for each print type, selected sheets keep the order they were selected in, and hidden sheets stay in the job of a whole-workbook print.

The numbering case fails without the change. Each of these breaks a test: drawHeaderFooter not passing the run's first number on, _getOdfPrintPageNumbering ignoring the preview's page options or the preview state, and numbering pages without jobSheets from the pages.

check-build.yml runs on this PR (unit tests, code style, build, e2e).

Commits

  • fix(cell): leave out empty pages when printing a workbook from ODS (from fix(cell): leave out empty pages when printing a workbook from ODS #213, already in main)
  • fix(cell): number the printed pages across the sheets of an ODS workbook
  • fix(cell): restart ODS page numbers at every numbered sheet, count only printed sheets (review follow-up)
  • fix(cell): take the sheets of the print job from calcPagesPrint for ODS page numbers (review follow-up)
  • fix(cell): number ODS pages in the print order of the job (review follow-up)
  • test(cell): stub the zoom in the calcPagesPrint print job test (test fix: the case read the zoom of a view without a drawing context)
  • fix(cell): name the selection order as a known difference of ODS page numbers (review follow-up: JSDoc + one assertion)
  • fix(cell): number ODS pages only from the sheets of the print job, test the header/footer path (review follow-up: drop the fallback without jobSheets, two new test cases)
  • Merge branch 'main' into fix/ods-page-numbers-continue-across-sheets
  • fix(cell): leave hidden sheets out of the ODS page numbers (review follow-up: jobSheets moved to CPrintPagesData, drawForPrint tested with printed pages; its hidden-sheet part is reverted by the last commit)
  • docs(cell): say how the ODS header choice compares with LibreOffice
  • fix(cell): let a hidden sheet pass on its ODS first page number (review follow-up: a hidden sheet stays in the job of a whole-workbook print and passes on its first page number, as in LibreOffice)

Assisted-by: ClaudeCode:claude-opus-5-5

🤖 Generated with Claude Code

chrip and others added 7 commits November 17, 2026 08:39
LibreOffice Calc does not print a page that has nothing on it: no cell
value or formula, no comment or sparkline, no cell border, no drawing
object and no text running in from a cell on its left. A background fill
alone does not count. A sheet whose data sits in a few distant blocks
therefore prints only the pages with data. The editor printed every page
of the used range, so the same ODS file came out with many blank pages
and different page numbers. Excel prints such pages, so the rule applies
only to workbooks opened from an OpenDocument spreadsheet.

How it works:
- The workbook reads a new `SourceFileType` record (id 100) from the
  binary file into `Workbook.sourceFileType` and writes it back on save,
  but not into copied ranges. The core PR "fix(x2t): record the source
  file type of a workbook from ODS in Editor.bin" writes it for ODS,
  flat ODS and ODS templates; without it the record is never set and
  nothing changes, so the two PRs can merge in either order. Id 100 lies
  outside the range of the existing workbook records; should upstream
  ONLYOFFICE ever give id 100 to a record of its own, this one has to
  move to another id.
- When the print path (`WorkbookView.calcPagesPrint`) lays out the pages
  of such a workbook, `_addPrintPage` checks each page with
  `_isPrintPageEmpty`, modelled on LibreOffice's
  `ScDocument::IsPrintEmpty`, and leaves empty pages out. Left-out pages
  do not count toward the 1500 page limit; after 1500 left-out pages the
  layout stops and the usual limit warning is shown.
- Page break preview and the page lines on the sheet still get every
  page, as in LibreOffice.
- A range whose pages are all empty adds no page, so an empty sheet
  prints nothing. Only when the whole job has no page is the first empty
  page printed.
- Text running in from the left is measured once per cell and layout
  pass, not once per page to its right.

Known difference: LibreOffice also counts a merged cell that starts left
of the page and has no value; this is rare and not ported (a comment in
the code says so).

Large sheets now fill the 1500 page limit with pages that carry data
instead of blank ones, so printing them needs more memory than before
(in one 1500 page sheet about 14 % more), as the extra pages hold text
and borders.

Tests: a new QUnit case in the print json params suite. With an XLSX or
unknown source every page is kept. With an ODS, flat ODS or ODS template
source, pages with a value, a border, a formula with an empty result, a
comment or a sparkline stay; pages with only a fill or only a diagonal
line are left out; a job without content prints one page; the limit of
left-out pages is honoured; text running in from the left is measured
once per cell. The test fails without the change.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>
A spreadsheet from ODS printed with page numbers in its headers or
footers starts again at 1 on every sheet. ODF numbers the printed pages
across the whole document (LibreOffice ScPrintFuncCache): sheet 2 goes on
where sheet 1 stopped. Only a sheet whose page style sets a first page
number starts again, and the sheets after it continue from there.

The print path takes the page index of the current sheet (the Excel
rule) for the page number field, the first page header and the odd/even
headers.

For a workbook from ODS, flat ODS or an ODS template, drawForPrint now
asks _getOdfPrintPageNumbering for the index of the page since the last
restart and the number of the first page of that run, as LibreOffice
does:
- a sheet starts again when it has a first page number and the sheet
  before it has another one or none (LibreOffice compares the page style
  names; sheets with the same page style carry the same number, so the
  number stands in for the name);
- a sheet without one takes the number of the last sheet that has one,
  or 1;
- a first page number of 0 means "continue", as in LibreOffice;
- the first page and odd/even headers use the same index (LibreOffice
  PrintHF), so the first page header is shown on the first page of the
  run, not on the first page of every sheet;
- print preview settings of a sheet win over the sheet's own, as for the
  header/footer text.
The run's first number reaches the page number field through a new
optional argument of drawHeaderFooter, calculateTokens and calculateText.
XLSX and other sources keep the per-sheet numbering.

Tests: a new QUnit case in the print json params suite. XLSX and unknown
sources get no ODF numbering; for ODS, flat ODS and ODS templates the
pages are numbered across the sheets, a sheet with its own first page
number starts again and the sheets after it continue, the same number on
the next sheet continues, a sheet without printed pages still restarts,
0 continues, and the page number field adds the run's first number. The
test fails without the change.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>
…ly printed sheets

Follow-up to the numbering of printed pages across the sheets of an ODS
workbook.

- A sheet with its own first page number now always starts the count
  again. The first version continued when the sheet before it had the
  same number, standing in for "the same page style". The converse does
  not hold: files saved from XLSX give every sheet its own page style,
  and LibreOffice restarts each of them even when the numbers are equal.
  The page style names are not kept in the model, so the case where
  LibreOffice continues (the very same page style with a first page
  number on the next sheet) is a known difference, noted in the code.
- Only the sheets of the print job count. Printing one sheet took over
  the first page number of a sheet before it; LibreOffice starts from 1
  there, because sheets outside the job pass nothing on.

Tests: the QUnit case now also drives drawForPrint (blank page path,
header/footer stubbed) and checks the index and first number it hands
to the header/footer for ODS and XLSX, a sheet printed alone, and a job
that starts at a numbered sheet.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>
…DS page numbers

Follow-up to the numbering of printed pages across the sheets of an ODS
workbook.

The sheets of the print job were taken from the printed pages. Sheets
without printed pages (empty or hidden) were missing from that list, so
a first page number on such a sheet was lost when the job began there:
a whole workbook whose empty first sheet starts at 5 printed 1, 2 on the
next sheet instead of 5, 6. And a numbered sheet between two printed
sheets that was not in the job still passed on its number.

calcPagesPrint now records the sheets of the job on the page list
(jobSheets: every sheet for the whole workbook, the selected sheets, or
the active sheet), and the numbering walks back over those sheets only.
LibreOffice also starts the count again at a numbered sheet that is not
printed; that case is noted in the code as a known difference, together
with the page-style cases.

Tests: new QUnit cases for a first sheet without pages, a single sheet,
and a numbered sheet outside the job; drawForPrint is also checked with
a run of pages across two sheets, so the index it hands on is covered;
and a new case checks the sheets calcPagesPrint records for each print
type.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>
Selected tabs print in the order they were selected (the tab bar keeps
the click order), so the sheets of a print job need not be in ascending
order. The walk back to the sheet that starts the current run of page
numbers went by sheet index from the lowest sheet of the job, so with
tabs selected as sheet 3, then sheet 1 (numbered 5), the pages of
sheet 3, printed first, took their number from sheet 1, printed after
them, and were numbered 5, 6 instead of 1, 2.

Walk back by position in the job's sheet list, which is the print
order, and count the previous pages by that position. Without a job
sheet list the derivation from the printed pages stays as it was.

Also compute the sheet of a selection print once, and let the
calcPagesPrint test remove its stubs with delete, as the other tests do.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>
calcPagesPrint reads the view zoom before it lays out the pages and
sets it back afterwards. The test stubbed changeZoom but not getZoom,
which reads the drawing context; the test workbook view has none, so
the case died before its first assertion. Stub getZoom as well and
remove the stub afterwards, as for the other stubs.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>
… numbers

Review follow-up. ODS page numbers follow the print order of the job,
and selected sheets print in the order they were selected. LibreOffice
prints and numbers selected sheets in sheet order instead, so with the
sheets selected as 3 then 1, and sheet 1 starting at 5, LibreOffice
numbers sheet 1 as 5, 6 and sheet 3 as 7, 8, while here sheet 3 gets
1, 2 and sheet 1 gets 5, 6. Pages and numbers stay together here;
changing the print order of selected sheets is out of scope. Name this
under the known differences of _getOdfPrintPageNumbering.

Add a calcPagesPrint assertion that selected sheets keep the order they
were selected in, which the page numbering relies on.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>
@chrip
chrip requested a review from a team as a code owner November 23, 2026 08:02
@chrip
chrip requested review from MonaAghili and j-base64 and removed request for a team November 23, 2026 08:02

@MonaAghili MonaAghili left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The print panel turns a touched sheet into a restart at 1
    For a sheet without a first page number the panel shows "First page number: 1" (Print.js fillPageOptions: value ? value : 1), and every property change goes through getPageOptions, which calls asc_setFirstPageNumber(spinner value). asc_setFirstPageNumber always sets useFirstPageNumber = true.
    On a 3-sheet ODS (S2 starts at 5, S1/S3 "continue"), with S3 selected in "Settings of sheet": changing any of gridlines, orientation, margins, page size, scaling, row and column headings or print titles makes the preview number S3 from 1 instead of 7. Print and Save then write useFirstPageNumber = true, 1 into the model: the PDF sent to the printer numbers the pages 1 2 5 6 1 2, reopening the panel still shows S3 from 1, and the ODS the server saves has first-page-number="1" on S3.
    Before this PR a first page number of 1 made no difference to the output. It needs a web-apps change (set the first page number only when the spinner was edited or the sheet already had one), landing with this PR or before it.

  2. No effect without the source file type in Editor.bin
    isOpenDocumentSource() reads sourceFileType from Editor.bin, which current x2t does not write. With the stock x2t the PDF export of the file above prints 1 2 5 6 1 2 instead of 1 2 5 6 7 8. Please name the dependency on core#364 in the description and merge after it.

  3. After one save in the editor, Euro-Office and LibreOffice number the same file differently
    The ODS export drops "continue" and gives every sheet its own page style. In LibreOffice a different page style without a first page number restarts at 1, so after one edit and save:

    • three sheets that all "continue": LibreOffice 1 2 1 2 1 2, this PR 1 2 3 4 5 6 (before the save both print 1-6)
    • the file above: LibreOffice 1 2 5 6 1 2, this PR 1 2 5 6 7 8
      Adding first-page-number="continue" to the page styles without a number makes LibreOffice print 1-6 and 1 2 5 6 7 8 again. So known difference #2 is the normal case for any ODS saved by Euro-Office; please either export "continue" for sheets without a number or describe it as a change in behaviour.
  4. The branch without jobSheets is unreachable, and most assertions test it
    Every pages array drawForPrint numbers comes from WorkbookView.calcPagesPrint, which always sets jobSheets. Replacing the fallback with "return null" breaks 12 of the 21 numbering assertions (10 numbering cases and both ODS drawForPrint ones), so the path real printing takes through drawForPrint is not covered. Please drop the fallback and give those cases a jobSheets list.

  5. Two behaviours are not protected by the tests
    The suite still passes when either of these breaks:

    • drawHeaderFooter not passing opt_firstPageNumber to calculateTokens (drawHeaderFooter is stubbed in the test).
    • _getOdfPrintPageNumbering ignoring the print preview pageOptionsMap.
      Please add a case that runs the real drawHeaderFooter (stub only _drawHeaderFooter) and checks the page number text and the first/odd/even choice, and a case with a preview pageOptionsMap.
  6. Unit tests and code style did not run on this PR
    check-build.yml only runs for PRs into main/fork/develop/release/hotfix, and this PR targets fix/cell-print-skip-empty-pages, so CI did not catch the calcPagesPrint test that died before its first assertion (fixed in 85e7435). Please retarget to main once the base is in so CI checks it. Merging now would land it in the base branch, not main.

…st the header/footer path

Review follow-up.

_getOdfPrintPageNumbering no longer guesses the sheets of the job from
the printed pages. Every page list it is called with comes from
calcPagesPrint, which records the sheets of the job, so the fallback
was never taken in real printing. Without jobSheets it now returns
null, which keeps the per-sheet numbering.

The numbering cases and the drawForPrint case now pass the job's
sheets as calcPagesPrint records them, so they test the path real
printing takes. One assertion checks that pages without jobSheets get
no ODF numbering.

Two new cases:
- the real drawHeaderFooter, with only the drawing stubbed: the page
  number text of headers and footers runs on across the sheets, and the
  first page header is used at the start of each run, then even and odd;
- print preview: a first page number set or cleared in the preview's
  page options wins over the sheet's own, and only while the preview is
  open.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>
@chrip

chrip commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the careful review, @MonaAghili. Point by point:

  1. Print panel turns a touched sheet into a restart at 1. Fixed in web-apps: fix(sse): write the print panel's first page number only when set or edited web-apps#473 (a draft until I have tried it in the editor)
    (fix(sse): write the print panel's first page number only when set or edited). getPageOptions now calls
    asc_setFirstPageNumber only when the spinner was edited or the sheet already has a first page number, so the 1
    the panel shows stays a default. I did not add a guard in sdkjs: sdkjs cannot tell "the user typed 1" from "the
    panel sent its default 1", and an explicit 1 is a valid setting (an ODS page style can restart at 1). The
    web-apps PR should land with this one or before it; it is listed under "Depends on" in the description.

  2. No effect without the source file type in Editor.bin. The description now has a "Depends on" section that
    names core#364 and says this PR changes nothing until it is merged.

  3. ODS export drops "continue". Fixed in core on the branch fix/ods-first-page-number-continue (stacked on core#364); I will open the PR once its build and tests have run. x2t now reads the
    SourceFileType record when it reads an Editor.bin, and for a workbook from ODS it writes
    first-page-number="continue" on the page layout of every sheet without a first page number. Sheets with a
    number keep it, and workbooks from XLSX keep the old output (no attribute, so LibreOffice starts each sheet at 1,
    as the editor numbers them). Its tests save plain.ods from an Editor.bin with and without the record and a new
    3-sheet fixture (sheet 2 starts at 5). The second known difference in the description now says that a file
    saved by Euro-Office prints the same in LibreOffice once that PR is in.

  4. Unreachable fallback without jobSheets. Removed in 008c8ad: without jobSheets,
    _getOdfPrintPageNumbering now returns null (per-sheet numbering). All numbering cases and the drawForPrint
    case pass the job's sheets as calcPagesPrint records them, and one assertion checks that pages without them
    get no ODF numbering. The old "one sheet printed" case without job sheets was the same as the one with
    [1], so I merged the two.

  5. Two behaviours not protected. Added in 008c8ad:

    • a case that runs the real drawHeaderFooter (only _drawHeaderFooter stubbed) over two sheets (the second
      starts at 5) with different first, odd and even headers and footers. It checks the text per page: F1 E2 F5 E6 O7;
    • a case with a preview pageOptionsMap: a number cleared in the preview continues, a number set in the preview
      starts again, and with the preview closed the sheets' own settings count.

    I checked that each of these changes now fails a test: drawHeaderFooter not passing opt_firstPageNumber,
    ignoring the preview pageOptionsMap, ignoring isStart(), and numbering pages without jobSheets from the
    pages.

  6. CI did not run. Not a code change: I'll retarget to main once fix(cell): leave out empty pages when printing a workbook from ODS #213 is merged. Until then I ran the
    check-build.yml steps locally: the code-style check passes, and node tests/runAll.js (develop build with
    sdkjs-forms master) passes all suites except the engineering, mathematic and statistical formula suites. Those
    fail locally with the same counts (4, 1, 83 assertions) on the PR head before my commit, so they are not caused
    by this PR.

Assisted-by: ClaudeCode:claude-opus-5-5

Base automatically changed from fix/cell-print-skip-empty-pages to main November 23, 2026 23:12
@chrip

chrip commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@MonaAghili The core part of point 3 is open now: Euro-Office/core#435 (stacked on core#364). Its ooxml_test and test_odf pass locally, including a 3-sheet case where sheet 2 keeps its first page number 5 and the other two get "continue". The description of this PR links it under "Depends on".

Assisted-by: ClaudeCode:claude-opus-5-5

@moodyjmz moodyjmz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocked on Euro-Office/web-apps#473, which isn't merged yet. Without it, any change in the print panel looks like it writes first-page-number="1". The six points from the earlier review are otherwise handled here or in Euro-Office/core#364 (merged) and Euro-Office/core#435. #260 only takes effect once DocumentServer's core pin includes #364.

Details
  • Hidden sheets: _calcPagesPrintSheet skips hidden sheets, but the whole-workbook branch of calcPagesPrint still adds them to jobSheets (WorkbookView.js:4211), so a hidden sheet with its own first page number restarts the numbering of the visible sheets after it. Intended? The calcPagesPrint test stubs _calcPagesPrintSheet, so nothing covers it either way.
  • Real print call site not covered: the drawForPrint test passes printPagesData = null, so it only reaches the blank-page call (WorksheetView.js:4184). Dropping the first page number at the call real printing uses (:4242) alone still passes. One case with a non-null page and the drawing stubbed would cover it.
  • Nit: jobSheets is a property on the arrPages array, so for (var i in this.pages.arrPages) in recalculatePageClipRect (WorkbookElems.js:14897) now visits it for every workbook, XLSX included. Harmless today; asc_CPrintPagesData looks like the better home.
  • Odd/even and first-page headers now follow the position in the run (a run starting at 4 puts the even header on page "5"). Has this been compared with LibreOffice?

chrip added a commit to Euro-Office/web-apps that referenced this pull request Nov 25, 2026
The print panel shows 1 for a sheet whose first page number is 0, but
counted the sheet as having a number of its own. The next change of any
other setting then wrote the 1 shown in the spinner into the sheet. For
a workbook from ODS, sdkjs reads 0 as "go on from the sheet before"
(Euro-Office/sdkjs#260), so that sheet restarted at 1.

Count a first page number only when it is set and not 0, as sdkjs does.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>
chrip and others added 2 commits November 25, 2026 10:34
A hidden sheet is not printed, but calcPagesPrint still listed it among
the sheets of the print job. A hidden sheet with a first page number of
its own then restarted the numbers of the visible sheets after it.
_calcPagesPrintSheet now says whether it printed the sheet, and only
printed sheets are kept for the numbering.

The sheets of the job now live on CPrintPagesData.jobSheets instead of
as an extra property on the arrPages array, so loops over arrPages no
longer see it. drawForPrint takes them as a new last argument from
printSheets and the print preview.

Tests: calcPagesPrint now runs the real _calcPagesPrintSheet with
hidden sheets, and drawForPrint is tested with printed pages (cells,
drawings and fonts stubbed), the path real printing takes.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>
LibreOffice 24.2 picks the first page and odd/even headers by the
position in the page count, not by the printed number: with a count
that starts at 4, page 4 gets the first page header and page 5 the even
one, and a sheet that goes on with the count gets no first page header.
sdkjs already does the same. Write that down next to the numbering.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>
@chrip

chrip commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the second pass, @moodyjmz. All four points below.

  • Hidden sheets: not intended, fixed in 239206e. _calcPagesPrintSheet now says whether it printed the sheet, and calcPagesPrint only keeps printed sheets for the numbering, in every branch. So a hidden numbered sheet no longer restarts the visible sheets after it. The calcPagesPrint test now runs the real _calcPagesPrintSheet with hidden sheets. I also checked LibreOffice 24.2: it doesn't count a hidden sheet's pages and never hands its number to a sheet that has none of its own.
  • Real print call site: added a drawForPrint case with printed pages (cells, drawings and fonts stubbed) in 239206e. Dropping the first page number at the call real printing uses now fails that case. I checked this by making that change and running the test.
  • jobSheets on arrPages: moved to CPrintPagesData.jobSheets (239206e). drawForPrint gets it as a new last argument from printSheets and the print preview, so loops over arrPages don't see it any more. A test checks that arrPages has no such property.
  • Odd/even and first-page headers vs LibreOffice: yes, now compared. I built ODS files with a page style starting at 4 (style:first-page-number="4") and different first, odd and even headers, then printed them to PDF with LibreOffice 24.2 headless. LibreOffice picks the header by position in the run, not by the printed number: page 4 gets the first-page header, page 5 the even one, page 6 the odd one. A sheet that goes on with the same page style gets no new first-page header (pages 7, 8, 9 get even, odd, even). That is what sdkjs does now, so I left the code as it is and wrote it down next to the numbering (0cc29ae). The difference already listed in the comment remains: sdkjs doesn't keep page style names, so a sheet with the same numbered style starts again instead of going on.

On the blocker: web-apps#473 also got a fix for the 0 case you reported there, 931591d225. The print panel now counts a first page number only when it is set and not 0, as sdkjs does. And yes, #260 only takes effect once the DocumentServer core pin includes core#364.

QUnit: PrintJsonParamsTests passes (74 assertions). The full suite gives 73/78. The 5 failures (engineering, mathematic and statistical formula precision, js-api-forms, oformXml) fail the same way on main.

Assisted-by: ClaudeCode:claude-opus-5-5

@chrip

chrip commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

@MonaAghili all six points from your review are addressed, details in my comments from 24 and 25 Nov. The fallback and the tests are in 008c8ad, core#364 is merged, and the branch targets main. The print panel point is Euro-Office/web-apps#473 and the ODS export point is Euro-Office/core#435; both still wait for a review, and core#435 has main merged as of today. moodyjmz's four points are in 239206e and 0cc29ae. Could you take another look?

Assisted-by: ClaudeCode:claude-opus-5-5

@chrip
chrip requested a review from MonaAghili November 30, 2026 10:45

@MonaAghili MonaAghili left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. A hidden sheet with its own first page number no longer passes it on, unlike LibreOffice
    239206e leaves hidden sheets out of jobSheets, so the sheet after a hidden numbered sheet continues from the visible sheet before it. In LibreOffice the next sheet takes the hidden sheet's number.
    Test file: 3 sheets of 2 pages each, header with sheet name and page number. S1 and S3 have first-page-number="continue", S2 has first-page-number="5". PDF export:

    • S2 visible: LibreOffice 24.2.7, this PR and dcfa11a all print 1 2, 5 6, 7 8
    • S2 hidden: LibreOffice 24.2.7 prints S1 1 2, S3 5 6. dcfa11a prints the same. This PR (0cc29ae, x2t PDF export) prints S1 1 2, S3 3 4.
      The LibreOffice code agrees (read in Collabora's copy of the engine). Printing the whole document selects every sheet, hidden ones too (ScModelObj::FillRenderMarkData). ScPrintFunc::InitParam marks a hidden sheet as not printed (the !IsVisible branch), so CountPages gives it no pages, but InitParam still reads its first page number, and ScPrintFuncCache hands that number to the next sheet (nFirstAttr).
      Note: in LibreOffice a sheet whose page style differs from the one before it and has no first-page-number restarts at 1, so the sheet after the hidden one needs "continue" to show this.
      Please keep every sheet in jobSheets in the whole-workbook branch of calcPagesPrint (WorkbookView.js:4216-4219), and update the test at PrintJsonParamsTests.js:364-365, the two hidden cases at :632-637 and the JSDoc at WorksheetView.js:5480-5481. Moving jobSheets to CPrintPagesData can stay.
  2. The description is out of date
    It still says this PR is based on #213's branch and that check-build.yml does not run, it names arrPages.jobSheets (now CPrintPagesData.jobSheets), and the commit list stops before 239206e and 0cc29ae.

@moodyjmz moodyjmz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mona's 11-30 point 1 holds: the behaviour I asked about on 11-24 is what LibreOffice does. LibreOffice doesn't count a hidden sheet's pages, but it does hand the hidden sheet's first page number on to a "continue" sheet after it, and dcfa11a matched that in Mona's run. Please restore every sheet in jobSheets in the whole-workbook branch, as Mona describes. With Euro-Office/web-apps#473 approved, that is the last thing I'd block on.

LibreOffice 25.8.4.2, PDF export

3 sheets of 2 pages each, header with sheet name and page number.

S1 / S2 / S3 first page number S2 S1 S3
continue / 5 / continue visible 1 2 7 8 (S2: 5 6)
continue / 5 / continue hidden 1 2 5 6
continue / 5 / 9 hidden 1 2 9 10
continue / continue / continue hidden 1 2 3 4

The last row is the control: S2's own pages don't advance the count, so the 5 in the second row is S2's number handed on. Same result as Mona's 24.2.7 run.

Repro: flat ODS with one page style per sheet, table:display="false" on S2, soffice --headless --convert-to pdf.

chrip added a commit to Euro-Office/core that referenced this pull request Dec 1, 2026
…DS (#435)

* fix(x2t): record the source file type of a workbook from ODS in Editor.bin

LibreOffice Calc leaves pages without content out when it prints a
spreadsheet; Excel prints them. For the editor to print a workbook from
an ODS file the way ODF applications do, it has to know that the
workbook came from an OpenDocument spreadsheet. In the browser the
editor knows the file format, but when the converter prints a workbook
(PDF or image output), the binary file only holds the converted
spreadsheet model and the source format is lost.

This adds a `SourceFileType` workbook record (id 100) to the binary
format, holding the file type the workbook was converted from.
`xlsx_dir2xlst_bin` sets it when the input is ODS, flat ODS or an ODS
template; `CXlsxSerializer::setSourceFileType` passes it through
`BinaryFileWriter` to `BinaryWorkbookTableWriter`, which writes the
record after `AppName`. Readers that do not know the record skip it:
x2t's own reader does so when a workbook is saved back to XLSX or ODS,
and so does the current editor. The id is outside the range of the
existing workbook records so that it cannot clash with the next record
added there. Should upstream ONLYOFFICE ever give id 100 to a record of
its own, this one has to move to another id.

The record is used by the sdkjs PR "fix(cell): leave out empty pages
when printing a workbook from ODS", which leaves empty pages out when
printing such a workbook. Without that PR nothing changes in the output.
The two can merge in either order: each one alone changes nothing
visible.

Known limit: conversions that render the workbook from a zipped XLSX
instead of the binary file do not carry the record.

Tests: new `editorbin_source_file_type.cpp` in ooxml_test with three
small fixtures. An ODS, a flat ODS and an ODS template converted to the
binary format contain the record with their file type; an XLSX does not.
The ODS cases fail without the change; the XLSX case is the control.

The full ctest run and the conversion test pass.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>

* test(x2t): save a workbook whose Editor.bin carries the source file type

The SourceFileType record goes back to x2t whenever the editor saves a
workbook from ODS: the editor keeps the record and writes it again into
the Editor.bin it sends. x2t's reader skips the record as an unknown
item, but no test covered that direction.

Two new cases convert plain.ods to an Editor.bin with the record and,
through XLSX, to one without it, then save both to XLSX and to ODS. The
saved files must be the same: xl/workbook.xml, the sheet, the shared
strings and the styles for XLSX, content.xml and styles.xml for ODS.
Each Editor.bin is checked first for having or not having the record,
and every x2t run gets its own temp dir.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>

* fix(x2t): record the source file type when x2t only gets file names

xlsx_dir2xlst_bin writes the SourceFileType record from
params.m_nFormatFrom. The document server never passes m_nFormatFrom:
it sends m_sFileFrom and m_nFormatTo, and x2t detects the source type
from the file and stores it back into the params before converting, so
opening a file and converting it to PDF or an image both carry the
record. A call with the file names only (x2t in.ods out.bin, no
m_nFormatTo either) takes its direction from the extensions instead and
never stores the type, so that binary file came out without the record.

odf2oot_bin, which this call ends in, now detects the type of the source
file when it is still unknown, before it hands the workbook to
xlsx_dir2xlst_bin.

Tests: two new cases convert an ODS and an ODS template given by file
names only and decode the base64 Editor.bin; both fail without the
change. The comment of the existing cases now says that their params
(m_nFormatTo only) are the ones the document server sends.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>

* test(x2t): read the Editor.bin of the file-name cases as written

Follow-up to the two previous commits.

x2t writes Editor.bin without base64 unless the params say otherwise
(m_bIsNoBase64 defaults to true), also when it only gets file names.
The two file-name cases tried to decode base64 and would have failed
with the fix too; they now read the file as it is, like the other
cases.

The save cases no longer compare xl/sharedStrings.xml: the workbook of
plain.ods holds a drawing and no text cells, so neither save writes
that part. They compare the drawing part instead.

Comments: the file-name cases detect the type in odf2oot_bin, not in
the ODF reader; the save cases use x2t's own Editor.bin, where the
record is the last workbook item, and x2t skips the record by its
length like any unknown item. Also a correction to the message of the
first follow-up: the editor keeps the record and writes it again only
with the editor change from the sdkjs PR.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>

* test(x2t): compare the saved workbooks up to x2t's name counters

Follow-up to the previous commits.

The save cases convert five times in one process. x2t numbers OOXML
part names (IFileContainer::m_mapEnumeratedGlobal) and ODF automatic
style names (style_family_counts_) per process, not per conversion, so
the second save wrote xl/drawings/drawing2.xml and ce4, co2, Mpm2
where the first wrote drawing1.xml and ce3, co1, Mpm1. Both cases
failed on that alone. The document server starts one x2t per
conversion, so it never sees these numbers move.

The cases now number such names in the order they first appear before
comparing, find the drawing part by listing xl/drawings, and also
compare the sheet relationships and [Content_Types].xml of the XLSX.
Run as separate x2t processes, both saves are byte for byte the same.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>

* test(x2t): renumber only names, not cell references

Follow-up to the previous commit.

P, T and N are also column letters, so the renumbering of the
previous commit also rewrote cell references (N5, P1:P3, [.T4]) and
would have let a moved cell pass. It now only renumbers a whole quoted
name ("ce3") or a part path (/drawing1.xml"), and only in the parts
whose names move: the ODS content.xml and styles.xml, the sheet
relationships and [Content_Types].xml of the XLSX. The XLSX workbook,
sheet, styles and drawing parts are compared byte for byte again.

Also a correction to the message of the previous commit: the ODS
names that moved were ce3 to ce6 in content.xml and ce1 to ce4 in
styles.xml (and co1 to co2, Mpm1 to Mpm2).

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>

* test(x2t): compare the content types of the saved workbook as a set

[Content_Types].xml lists its entries in no fixed order, and the macOS
build writes them in a different order than the Linux one, so
SaveToXlsxSkipsTheRecord failed there although both files list the same
parts. Compare the sorted Default and Override entries instead.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>

* fix(OdfFile): continue the page numbers when saving a workbook from ODS

In ODS the printed pages of a spreadsheet are numbered on across the
sheets: a page style with first-page-number="continue" goes on from the
sheet before, and only one with a number starts again. The ODS reader
turns "continue" into "no first page number", and the editor numbers
the pages of a workbook from ODS on across the sheets in the same way
(Euro-Office/sdkjs#260). On save the ODS writer gave every sheet its own
page style and left the attribute out. LibreOffice starts a different
page style without a first page number again at 1, so after one save
the same file printed 1 2 1 2 1 2 in LibreOffice instead of 1 to 6.

Now x2t reads the SourceFileType record (#364) when it reads an
Editor.bin, and passes it to the ODS writer through ConvertParams. For a
workbook from ODS, flat ODS or an ODS template, the page layout of a
sheet without a first page number gets first-page-number="continue". A
sheet with its own number keeps it. Workbooks from XLSX and other
sources keep the old output: there the editor numbers every sheet from 1,
which is what LibreOffice does with page styles without the attribute.

The attribute list for style:first-page-number can now hold "continue"
(the reader also records it, but nothing reads it there yet).

Tests (ooxml_test, editorbin_source_file_type.cpp):
- SaveToOdsContinuesThePageNumbers replaces SaveToOdsSkipsTheRecord:
  saved from the Editor.bin with the record, the page layout gets
  first-page-number="continue"; saved from the one without it, no first
  page number; otherwise styles.xml and content.xml are the same.
- SaveToOdsKeepsAFirstPageNumber: page_numbers.fods (sheet 2 starts at 5,
  sheets 1 and 3 continue) opened and saved to ODS keeps 5 on sheet 2 and
  writes "continue" for the other two.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>

* test(x2t): give the page number fixture a page size

The XLSX writer writes a sheet's pageSetup only when it has a paper
size or an orientation, so the first page number of a page layout
without them never reached the ODS writer, and SaveToOdsKeepsAFirstPageNumber
found no first-page-number="5". Page layouts saved by LibreOffice always
have a page size; page_numbers.fods now has A4 portrait in both.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>

---------

Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
chrip added a commit to Euro-Office/web-apps that referenced this pull request Dec 1, 2026
…edited (#473)

* fix(sse): write the print panel's first page number only when set or edited

For a sheet without a first page number the print panel shows 1 in
"First page number", and every change in the panel (gridlines,
orientation, margins, page size, scaling, headings, print titles) wrote
that 1 into the sheet's page setup: asc_setFirstPageNumber always turns
useFirstPageNumber on. After Print or Save the sheet had a first page
number of 1 it never had before.

With Excel's per-sheet numbering that made no difference. A workbook
from ODS numbers its printed pages on across the sheets (Euro-Office/sdkjs#260),
and there a sheet with a first page number starts again: the touched
sheet printed from 1, and the saved ODS kept first-page-number="1".

The panel now sets the first page number only when the spinner was
edited, or when the sheet already has one. The 1 it shows for other
sheets stays a default.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>

* fix(sse): treat a first page number of 0 as none in the print panel

The print panel shows 1 for a sheet whose first page number is 0, but
counted the sheet as having a number of its own. The next change of any
other setting then wrote the 1 shown in the spinner into the sheet. For
a workbook from ODS, sdkjs reads 0 as "go on from the sheet before"
(Euro-Office/sdkjs#260), so that sheet restarted at 1.

Count a first page number only when it is set and not 0, as sdkjs does.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>

---------

Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Printing the whole workbook left hidden sheets out of the sheets of the
print job, so the sheet after a hidden sheet with its own first page
number continued from the visible sheet before it. LibreOffice selects
every sheet when the whole document is printed, hidden ones too: a
hidden sheet prints no pages, but its first page number is still read
and handed to the next sheet (ScPrintFuncCache). Example: three sheets
of two pages, the second hidden and starting at 5; LibreOffice numbers
the third sheet 5 6, this branch numbered it 3 4.

calcPagesPrint now keeps every sheet in jobSheets in the whole-workbook
branch. Printing selected sheets is unchanged: a sheet that is not part
of the job still passes nothing on, as in LibreOffice.

Tests: the numbering case for a hidden numbered sheet and the two
hidden-sheet calcPagesPrint cases now expect the hidden sheet in the
job; the JSDoc drops the known difference this removes.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>
@chrip

chrip commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, both points hold.

  1. Hidden numbered sheet: you are right, I had it backwards. LibreOffice's ScPrintFuncCache takes the first page number of every selected sheet, and printing the whole document selects the hidden ones too, so the hidden sheet's number reaches the next sheet. fa12d3e keeps every sheet in jobSheets in the whole-workbook branch of calcPagesPrint. Your file now prints S1 1 2, S3 5 6 with S2 hidden. I updated the numbering case at PrintJsonParamsTests.js:364, the two hidden calcPagesPrint cases and the JSDoc, which no longer lists this as a known difference. Printing selected sheets is unchanged: a sheet outside the job still passes nothing on, which matches LibreOffice (an unselected sheet hands on the previous sheet's number). jobSheets stays on CPrintPagesData.

  2. Description: updated. It no longer mentions fix(cell): leave out empty pages when printing a workbook from ODS #213 as the base or check-build.yml not running, it names CPrintPagesData.jobSheets and lists every commit up to this one.

Assisted-by: ClaudeCode:claude-opus-5-5

@chrip
chrip requested a review from MonaAghili December 3, 2026 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants