We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Not getting correct page count for Excel spreadsheets

Hi,



I’m not getting the correct page #'s when counting pages for Excel spreadsheets. I want the number of pages that would print. This is the code that I’m using:

Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(doc2CountStream);

Worksheet worksheet = workbook.Worksheets[0];

Aspose.Cells.Rendering.ImageOrPrintOptions printoption = new Aspose.Cells.Rendering.ImageOrPrintOptions();

printoption.PrintingPage = PrintingPageType.Default;

Aspose.Cells.Rendering.SheetRender sheetRender = new Aspose.Cells.Rendering.SheetRender(worksheet, printoption);

pageCount = sheetRender.PageCount;



For the attached file the page count comes out to 2, but when I default print it only prints one page. Thanks for your help!

Hi,


Thanks for the template file and sample code.

I have evaluated your issue scenario/ case using your template file a bit. Well, it is not an issue with the product by any means. Your Excel file does actually have two pages. For confirmation, open your file into MS Excel manually and take the Print Preview of the sheet or view the Page Break Preview, you will see two pages, the second page is blank though.

To accommodate your needs, you may try to add the following lines of code (see the lines in bold) to your code segment:
e.g
Sample code:

Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(“e:\test2\Developer+Misc+Info+new.xlsx”);
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Cells.DeleteBlankColumns();
worksheet.Cells.DeleteBlankRows();
Aspose.Cells.Rendering.ImageOrPrintOptions printoption = new Aspose.Cells.Rendering.ImageOrPrintOptions();
printoption.PrintingPage = PrintingPageType.Default;
Aspose.Cells.Rendering.SheetRender sheetRender = new Aspose.Cells.Rendering.SheetRender(worksheet, printoption);
int pageCount = sheetRender.PageCount;

Hope, this helps a bit.

Thank you.