Aspose Excel Footer

I have a lengthy footer that I add to only the last page.

How do I ensure that the footer will stay on the same page. That depending on the size of the data on the page the footer doesn’t get pushed to the next page.

@tkurian,

You can get the printing page breaks of an existing worksheet that will help you understand where the pages will break/end. You can use the Worksheet.GetPrintingPageBreaks method that will return an array of CellsArea which in turn could tell you where the current page breaks are. You can use this information to move the breaks at your desired locations. You can also call the aforesaid method just before saving the spreadsheet so that the API could calculate the page breaks according to the amount of data (including your last footer/text) and considering the formatting (font size) as well as the height of rows and widths of the columns, in case you are calling AutoFitRows & AutoFitColumns.
You can use the Worksheet.AddPageBreaks method or Add methods from HorizontalPageBreakCollection & VerticalPageBreakCollection classes to put the page breaks on the desired locations so your footer text should not be split into multiple pages. At the bottom of this post, you will find the code snippet to add manual page breaks.

//Clearing all page breaks
workbook.Worksheets[0].HorizontalPageBreaks.Clear();
workbook.Worksheets[0].VerticalPageBreaks.Clear();

//Add a page break at cell Y30
workbook.Worksheets[0].HorizontalPageBreaks.Add(“Y30”);
workbook.Worksheets[0].VerticalPageBreaks.Add(“Y30”); 

In case, you still could not implement your desired requirements, kindly do provide a sample Excel file containing your desired footer/text intact at the end, we will check it soon.