Free Support Forum -

How to get total number of pages in a Worksheet

I am rendering xlsx to pdf and also using PdfSaveOptions -> setPageIndex(…) and setPageCount(…). For the page setup I need to know the total number of pages in a sheet.

Thanks in advance.


Well, you may try to use SheetRender.getPageCount() attribute to get number of pages in a worksheet, see the following sample code for your reference:
Sample code:

   Workbook workbook = new Workbook("Book1.xlsx");
                Worksheet worksheet = workbook.getWorksheets().get(0);    
                ImageOrPrintOptions printoption = new ImageOrPrintOptions();
                SheetRender sr = new SheetRender(worksheet, printoption);
                int pageCount = sr.getPageCount();

Hope, this helps a bit.

Many thanks. Works like a charm.


Good to know that it figures out your issue now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.