Free Support Forum - aspose.com

How to get total number of pages in a Worksheet

Hi,
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.

@kalaza,

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:
e.g
Sample code:

   Workbook workbook = new Workbook("Book1.xlsx");
                Worksheet worksheet = workbook.getWorksheets().get(0);    
                ImageOrPrintOptions printoption = new ImageOrPrintOptions();
                printoption.setPrintingPage(PrintingPageType.DEFAULT);   
                SheetRender sr = new SheetRender(worksheet, printoption);
                int pageCount = sr.getPageCount();
                System.out.println(pageCount.toString());

Hope, this helps a bit.

Hi,
Many thanks. Works like a charm.

@kalaza,

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.