Page numbers in table cell as formula with hyphen

Hi, is there a formula in writer to count the numbers from other cells to indicate which “pages” are for each document in a merged file with a hyphen?

Say I make a list in a table, each row for different document. In first column I type the name (say file1, file2, file3, file4, file5). In the second column I type in how many pages each of those documents have (say 2, 5, 10, 1, 6). And in the third column I need the page numbers through hyphen that would indicate where in the merged document it will take place (that would be 2, 3-7, 8-17, 18, 19-24). Is there a way to automate it without having to recalculate everything if I insert a new row with new data in the middle and have to change the page umbers in the merged file?

The merged big file is made up of this file (which is basically just a table of contents, 2 pages) and many other PDFs (scanned). This file has 20 to 30 rows of information.

Windows 11 pro, LO version 7.3.0.3. x64, usually saved to odt, then conversion straight to pdf.

Update your question (edit it, don’t use a comment) to give more details on your document. Is it built as a master document with sub-documents? In this case, the page limits can be retrieved without computation with cross-references. Page count could probably be computed too.

Your table looks like some kind of TOC. Is this in fact what you’re trying to achieve? If so, there are built-in mechanisms to do it which need no tweaking when you add or remove a “chapter”.

And don’t forget to mention OS name, LO version and save format. The latter is very important because most of advanced tricks work only in .odt and don’t translate well in other alien formats.

thanks, I added more explanation and a screenshot in the original post, any suggestions?

Some information is still missing.
Is this a “virtual” document? I mean one .odt TOC-like document which you print (2 pages) and several other PFSs you print separately and you bind together the sheets.
Or do you really “insert” the various PDFs inside the .odt? In this case, how do you proceed because I can’t directly “import” PDFs into an .odt?

this .odt is one simple document (2 pages max), PDFs don’t go in it - they get merged/binded after, your first definition.

@ajlittoz method works but it is not so easy to update calculations in Writer. Better to use his formulas in Calc and paste everything from Calc into the table. The table can span more than one page.

You can embed an OLE Calc table in Writer but you are limited to the one page. Copy the table in Calc, go to Writer and click Edit > Paste Special > Paste Special > LibreOffice x.x Spreadsheet. Either way, the calculations and No.'s need dragging down to the end of the table to update them.

In attached sample of OLE table, I have done a Condtional format to colour the PDF page number and n-dash white if there is only one page. I have inserted New File1a and need to update the numbering. Double-click the table and then the drag cell A4 by corner handle down over the top of the yellow ones to update them. Then select cells E4:G4 and drag down by corner handle over the top of the yellow ones. Note that I used three cells for the page numbers
AskLOCumulPgNbrCalc.odt (26.3 KB)

1 Like

You can’t insert easily some cell content as an element of another paragraph. This would require creating bookmarks or cross-references with an individual name, which quickly becomes boring and error-prone. Besides, Writer allows only for very basic formulas.

However, you can visually cheat. The printed medium show onlys what you decide to be visible.

In my quick’n’dirty example AskLOCumulPgNbr.odt (11.2 KB), I use the page count column to compute the starting page of every chapter and keep it in a column (simply page no. of previous “chapter” + current page count; first page no. is manually set at 1). In the next column I compute the end page no. as start page no. + page count - 1. Since you require a dash between start and end, this computation is negated (the end page no. displays negative).

Start column is right justified and end column is kept left justified.

Start and end cells in heading row are merge so that the title can be centred over the start and end page no. columns.

I didn’t draw any borders. I lett you finish with that. Just don’t draw a border between start and end page no. columns to complete the illusion.

2 Likes