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

Free Support Forum - aspose.com

How to get page count

Hi Team,

I am using aspose.cells to save excel into pdf and while saving i want to get the page count in pdf.

Can you please send me the .net version to find out this?


Well, Aspose.Cells renders PDF pages based on print previews of the sheets in the workbook. I think you may try the following sample code to get the page count for the sheets and workbook (total pages in the workbook that would be rendered in the PDF file format):
Sample code:

Workbook book = new Workbook(“e:\test2\Book1.xlsx”);
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.PrintingPage = PrintingPageType.Default;
int bookPageCount = 0;
for (int i = 0; i < book.Worksheets.Count; i++)
Worksheet sheet = book.Worksheets[i];
SheetRender sr = new SheetRender(sheet, imgOptions);
int sheetPageCount = sr.PageCount;
bookPageCount += sheetPageCount;


Hope, this helps a bit.

Thank you.

please send methe vb.net code which i asked initially only.


Please see the sample VB.NET code for your reference for your needs:
Sample code:

Dim book As New Workbook(“e:\test2\test2.xlsx”)

Dim imgOptions As New ImageOrPrintOptions()
imgOptions.PrintingPage = PrintingPageType.Default
Dim bookPageCount As Integer = 0
For i As Integer = 0 To book.Worksheets.Count - 1
Dim sheet As Worksheet = book.Worksheets(i)
Dim sr As New SheetRender(sheet, imgOptions)
Dim sheetPageCount As Integer = sr.PageCount

bookPageCount += sheetPageCount

Next i

Thank you.