Hi, I’m using Aspose.Cells for NET (24.5) to set the page size of a workbook and then get the printing pagebreak indexes based on that page size in order to shift some of the content so it doesn’t get split by a page break but the GetPrintingPageBreaks method seems to return incorrect values in some cases when compared to Excel. Here is the code I’m using:
Workbook input = new Workbook(inputPath);
Worksheet worksheet = input.Worksheets[“Sheet1”];
worksheet.PageSetup.PaperSize = PaperSizeType.PaperA4;
var options = new ImageOrPrintOptions();
options.IsOptimized = true;
var pageBreaks = worksheet.GetPrintingPageBreaks(options);
Here is a blank sample input Excel file:
sample_input.zip (17.4 KB)
When I open the file in Excel, I see pagebreaks after rows 38, 60, 82, 104, 126, 148, 170. But the Aspose method returns these pagebreaks:
Screenshot_102.png (19.5 KB)
Is there anyway to get close to Excel’s page break indexes using Aspose or am I missing a necessary step as the values seem to be quite different? Let me know if I can provide any additional info, thanks
@sdonapati
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-55870
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.
@sdonapati ,
-
Excel has different page breaks in different system display settings on Windows. Aspose.Cells takes the Excel result in 100% system display setting as the standard. Please change system display setting to 100% in Windows settings->Display:
system_100_display_setting.png (57.6 KB)
-
When you open the source file in Excel, Excel will recalculate the height of rows that are auto-height. You can use the code worksheet.AutoFitRows(true);
to do the same thing in Aspose.Cells. The code will be
Workbook input = new Workbook(inputPath);
Worksheet worksheet = input.Worksheets[“Sheet1”];
worksheet.PageSetup.PaperSize = PaperSizeType.PaperA4;
//only auto fit the height of rows that are auto-height.
worksheet.AutoFitRows(true);
var options = new ImageOrPrintOptions();
options.IsOptimized = true;
var pageBreaks = worksheet.GetPrintingPageBreaks(options);
The page breaks of Aspose.Cells and Excel will be same:
pagebreaks_Excel.png (9.9 KB)
pagebreaks_Aspose.png (30.0 KB)
Please let us know your feedback.
@peyton.xu
Thank you for your help! This resolved my issue and the page breaks are mostly accurate now. I still see a few test files where it seems to be off by 1 row but this margin of error should work for our purposes.
@sdonapati,
Good to know that your issue has been resolved by following the suggestion and code segment. Please feel free to write back to us if you have any further queries or comments.