Managing Page Breaks

Page Breaks

Aspose.Cells provides a Workbook class that represents an Excel file. The Workbook class contains a Worksheets collection that allows access to each worksheet in the Excel file.

A worksheet is represented by the Worksheet class. The Worksheet class provides a wide range of properties and methods used to manage a worksheet.

To add the page breaks, use the Worksheet class' HorizontalPageBreaks and VerticalPageBreaks properties.

The HorizontalPageBreaks and VerticalPageBreaks properties are collections that may contain several page breaks. Each collection contains several methods for managing horizontal and vertical page breaks.

Adding Page Breaks

To add a page break in a worksheet, insert vertical and horizontal page breaks at the specified cell by calling the HorizontalPageBreakCollection.Add() and VerticalPageBreakCollection.Add() methods. Each Add method takes the name of the cell where the break should 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, call the HorizontalPageBreakCollection.RemoveAt() and VerticalPageBreakCollection.RemoveAt() methods. Each RemoveAt method takes the index of the page break about to be removed.

Important to know

When you set FitToPages properties (that is FitToPagesTall and FitToPagesWide) in page setup settings, the page break settings are affected, so, if you print the worksheet, the page break settings are not considered although they are still set.