Managing Page Breaks
A page break is a place in the text where one page ends and the next one begins. Microsoft Excel can add page breaks at any selected cell in a worksheet. The page ends at the cell where the page break is added and all the data after the page break is printed on the next page. In simple words, page breaks split worksheets into multiple pages. It is also possible to add page breaks to worksheets at runtime using Aspose.Cells. Aspose.Cells supports two kinds of page break:
- horizontal
- vertical.
This article describes that how to add horizontal or vertical page breaks into worksheets using Aspose.Cells.
Aspose.Cells & Page Breaks
Aspose.Cells provides a class, Workbook that represents an Excel file. The Workbook class contains a WorksheetCollection that allows access to each worksheet in the Excel file.
A worksheet is represented by the Worksheet class which provides a wide range of properties and methods for managing worksheets. To add the page breaks, use the Worksheet class' HorizontalPageBreaks and VerticalPageBreaks properties.
The HorizontalPageBreaks and VerticalPageBreaks properties are in fact collections that may contain several page breaks. Each collection contains several methods for managing horizontal and vertical page breaks. How these methods are used is discussed below.
Adding Page Breaks
To add a page break in a worksheet, insert vertical and horizontal page breaks at the specified cell by calling the HorizontalPageBreaks and VerticalPageBreaks collections' Add methods. Each Add method takes the cell name where the page break is to be added.
Clearing All Page Breaks
To clear all page breaks in a worksheet, call the HorizontalPageBreakCollection and VerticalPageBreakCollection collections' Clear methods.
Removing Specific Page Break
To remove a specific page break in the worksheet, call the HorizontalPageBreakCollection and VerticalPageBreakCollection collections' removeAt methods. Each removeAt method will take the index of the page break to be removed.