Back to Devexpress

Use the Excel Export API to Insert Page Breaks in a Worksheet

officefileapi-114705-excel-export-library-printing-how-to-insert-page-breaks-in-a-worksheet.md

latest2.0 KB
Original Source

Use the Excel Export API to Insert Page Breaks in a Worksheet

  • Sep 19, 2023

The following example demonstrates how to insert a page break on a worksheet to start a new page. Page breaks in a worksheet are contained in two separate IXlPageBreaks collections: one for the horizontal (row) page breaks and one for the vertical (column) page breaks. To get access to these collections, use the IXlSheet.RowPageBreaks and IXlSheet.ColumnPageBreaks properties, respectively. To add a new page break, use the IXlPageBreaks.Add method and pass an index of the row or column after which a page break should be inserted. To remove a single page break from a worksheet, use the IXlPageBreaks.Remove or IXlPageBreaks.RemoveAt method. To clear all page breaks at once, use the IXlPageBreaks.Clear method.

View Example

csharp
// Insert a page break after the column "B".
sheet.ColumnPageBreaks.Add(2);
// Insert a page break after the tenth row.
sheet.RowPageBreaks.Add(10);
vb
' Insert a page break after the column "B".
sheet.ColumnPageBreaks.Add(2)
' Insert a page break after the tenth row.
sheet.RowPageBreaks.Add(10)

The image below illustrates the result (the workbook is opened in Microsoft® Excel®).