How to find a page number in calc macro

I have written a macro that creates a calc spreadsheet from base tables and queries.
The spreadsheet (based on a template) has 4 sheets, each with a different page style.
Some of the sheets can be larger than just one page when I export it as pdf.
Because I want to print consecutive page numbers in the pdf I need to change the start number of a page in my basic macro. So far this is not a problem, because it is simple to update the FirstPageNumber of the page style in basic. But in order to change the start number of the next sheet I need to know the last actual page number of the previous sheet and that is something that I cannot find in the UNO-properties.
Who can help me?

As a workaround I found a simple solution by counting the rows of the sheet.
I can see for example that for a certain page style a row break is inserted every 32 rows, which can then be converted to a number of pages.

Use XSheetPageBreak interface of Spreadsheet object. Together with XPrintAreas interface, and XCellRangesQuery interface, you may calculate the number of printed pages.

Note however, that the calculation would only match the current print configuration. When you open Print or PDF Export dialog, you may use settings that would make the calculations wrong (e.g., using Whole sheet export feature for PDF).

… or use this construction:

nPages=ThisComponent.getRendererCount(ThisComponent.Sheets(0), Array()) ' number of pages for the first sheet of the document
1 Like

This is great! It is exactly what I was looking for!
Thanks a lot!

Thank you for this suggestion but the right solution was offered by sokol92.