Issue with Calculating Correct Page Breaks using Aspose.Cells

Hi everyone,

I’m using the Aspose.Cells library to generate an Excel report, and I’m looking for a way to accurately calculate the page breaks so I can insert some rows after each break.

I tried using the GetPrintingPageBreaks function with the following options:

  • AllColumnsInOnePagePerSheet = false
  • IsCellAutoFit = true

However, the page breaks I’m getting are not correct. Any suggestions on how to resolve this issue or what might be causing the incorrect page breaks?

Thanks in advance!

@Abhishek1997

Please provide us your template file to reproduce the issue so we can look into it and try to provide solution for you.

SampleReport.zip (212.5 KB)

Hi John,

I’ve attached a zip file containing a single workbook. The workbook includes a sample sheet named “Invoice Wise Sales Register,” which has some data relevant to the issue I’m facing with page break calculations.

Thanks for looking into this!

@Abhishek1997
By testing on the latest version v24.9 using sample files and the following sample code, we can reproduce the issue. When the system display is set to 100%, Excel print preview has 58 pages, while Cells receives 55 pages. Please refer to the attachment. result.png (38.6 KB)

The sample code as follows:

Console.WriteLine("version: " + CellsHelper.GetVersion());
Workbook wb = new Workbook(filePath + "SampleReport.xlsx");
ImageOrPrintOptions options = new ImageOrPrintOptions();
options.AllColumnsInOnePagePerSheet = false;
WorkbookRender render = new WorkbookRender(wb, options);
Console.WriteLine(render.PageCount);

The output result:

version: 24.9
55

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-56855

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@Abhishek1997 ,

I have checked the page breaks in Excel, the page breaks are same as the one generated by Aspose.Cells. Please refer to the pdf file generated by Excel to check the page breaks.
SampleReport_SavedByExcel.pdf (1.2 MB)

The only difference is that the last blank page is not outputed in Aspose.Cells.

Please note, Excel may have different page breaks on Windows with different display setting in system settings. Aspose.Cells takes the result of Excel on Windows with 100% display setting as the rule.

Hi Peyton and Jhon,

Thanks for your reply. I’ve attached my sample code showing how I’m getting the page breaks and the results I’m getting. Could you please help me identify where I’m making a mistake?

Code.png (40.6 KB)

output.png (96.6 KB)

Hi @Abhishek1997 ,

The output page breaks are Ok comparing the result pdf generated by Excel:

Hi @peyton.xu ,

Is there any other way to find the last row of page?

Hi @Abhishek1997 ,

CellArea.EndRow is the last row of a page.

Code:

Workbook wb = new Workbook(srcFile);

ImageOrPrintOptions imageOrPrintOptions = new ImageOrPrintOptions();
// imageOrPrintOptions.IsCellAutoFit = true;
CellArea[] areas = wb.Worksheets[0].GetPrintingPageBreaks(imageOrPrintOptions);

Console.WriteLine(areas[0].EndRow);