C1Excel Task-Based Help > Adding a Page Break to a Worksheet |
You can easily add page breaks in rows and columns for files in OpenXML (.xlsx) format using the PageBreak and PageBreak properties.
Add a reference to C1.WPF.Excel.dll or C1.Silverlight.Excel.dll and create a C1XLBook.
C# |
Copy Code
|
---|---|
// Create a new workbook to be saved C1XLBook book = new C1XLBook(); |
Add some text values and page breaks using the following code:
C# |
Copy Code
|
---|---|
book.Sheets[0][2, 3].Value = "page1"; book.Sheets[0].Rows[2].PageBreak = true; book.Sheets[0][0, 1].Value = "test1"; book.Sheets[0][0, 2].Value = "test2"; book.Sheets[0].Columns[1].PageBreak = true; book.Sheets[0][3, 3].Value = "page2"; |
Save and open the .xlsx file.
C# |
Copy Code
|
---|---|
// Save and open the file book.Save(@"C:\test.xlsx"); System.Diagnostics.Process.Start(@"C:\test.xlsx"); |
In Excel, select the Page Layout tab, and select the Print checkbox under Gridlines. The worksheet should look similar to the following: