Calculating Number of pages in a Word and Excel document using Aspose.Cells/Aspose.Words for .NET and C#

Hi,

I was wondering if I could use Aspose.Word and Aspose.excel to get the number of pages in word and excel document respectively. Aspose.Word gives me a different page count than the actuall when I try to read it from the Document Properties.

I tried using aspose.excel to ge the number of pages using this formula:
Num of Pages = (HPageBreaks.Count + 1) * (VPageBreaks.Count + 1)

This always returns me Page count of 1; not sure if I am doing it in the right way.
Could anyone please let me know? I am in the process of evaluating this tool.

Thanks, PK

Excel Code Sample:

Aspose.Excel.Excel excel = new Excel();

excel.Open(@“C:\Report.xls”);

Worksheets sheets = excel.Worksheets;

Worksheet sheet = sheets[0];

int hpage = sheet.HPageBreaks.Count + 1;

int vpage = sheet.VPageBreaks.Count + 1;

int pagecount = hpage * vpage;

MessageBox.Show("Number of Pages: " + pagecount.ToString());

Sorry we did not find your post as you did not post it in either Aspose.Excel or Aspose.Word forum. Laurence will reply very soon and hope it’s not too late.

Excel file is different with word file. If you don’t set hpagebreaks and vpagebreaks manually, we don’t supply a method to determine the pages of document automatically.