How to: Insert Page Breaks in a Worksheet
A worksheet’s page breaks are stored in two PageBreaksCollection collections:
Worksheet.HorizontalPageBreaks - Provides access to the collection of horizontal page breaks.
Worksheet.VerticalPageBreaks - Provides access to the collection of vertical page breaks.
Use the PageBreaksCollection.Add method to insert page breaks.
// Insert a page break after the "F" column.
worksheet.VerticalPageBreaks.Add(6);
// Insert a page break below the 14th row.
worksheet.HorizontalPageBreaks.Add(14);
The image below shows the result (the workbook is opened in Microsoft® Excel®).
Delete a Page Break
Use the following API to remove page breaks from a worksheet:
PageBreaksCollection.Remove - Removes a page break at the specified row or column index.
PageBreaksCollection.RemoveAt - Removes a page break at the specified index in PageBreaksCollection.
PageBreaksCollection.Clear - Clears all page breaks.