This article guides to insert a page break in Excel using C#. Although Excel adds automatic page breaks in the sheets, you may add page breaks manually by following the steps and the sample code demonstrating how to break page in Excel using C#. You can add as many page breaks as desired in multiple rows and columns.
Steps to Set Page Break in Excel using C#
- Set the IDE to use Aspose.Cells for .NET to insert a page break
- Load the Excel file into the Workbook class object for adding manual breaks
- Access the target sheet for setting breaks
- Add horizontal page breaks using the HorizontalPageBreaks collection
- Add vertical page break with VerticalPageBreaks collection
- Save the resultant workbook with a single manual page break
These steps describe how to make page break in Excel using C#. Load the workbook and access the sheet where you want to add manual page breaks. Use the collection of page breaks in each sheet for adding horizontal and vertical breaks at a specified cell. Save the workbook with the manually added page breaks in it.
Code to Create Page Break in Excel using C#
Use the HorizontalPageBreaks and VerticalPageBreaks collections for adding page break in Excel using C#. These classes have many other methods and properties for different purposes. For example, checking the capacity of the collection, adding page breaks using various overloaded Add() methods, searching the existing page breaks, finding the existence of a particular page break, and finding elements using the predicates to list a few.
This article has taught us how to change page break in Excel using C#. If you want to insert comments in an Excel file, refer to the article on how to insert comment in Excel using C#.