ComponentOne Excel for .NET
In This Topic
    Adding a Page Break to a Worksheet
    In This Topic

    You can easily add page breaks in rows and columns for files in OpenXML (.xlsx) format using the PageBreak property.

    1. Double-click the C1XLBook component in the Toolbox to add it to your form.
    2. Add some text values and page breaks using the following code:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      C1XLBook1.Sheets(0)(2, 3).Value = "page1"
      C1XLBook1.Sheets(0).Rows(2).PageBreak = True
      C1XLBook1.Sheets(0)(0, 1).Value = "test1"
      C1XLBook1.Sheets(0)(0, 2).Value = "test2"
      C1XLBook1.Sheets(0).Columns(1).PageBreak = True
      C1XLBook1.Sheets(0)(3, 3).Value = "page2"
      ' Save and open the .xlsx file
      C1XLBook1.Save("c:\Save.xlsx")
      System.Diagnostics.Process.Start("c:\Save.xlsx")

      To write code in C#

      C#
      Copy Code
      c1XLBook1.Sheets[0][2, 3].Value = "page1";
      c1XLBook1.Sheets[0].Rows[2].PageBreak = true;
      c1XLBook1.Sheets[0][0, 1].Value = "test1";
      c1XLBook1.Sheets[0][0, 2].Value = "test2";
      c1XLBook1.Sheets[0].Columns[1].PageBreak = true;
      c1XLBook1.Sheets[0][3, 3].Value = "page2";
      // Save and open the .xlsx file
      c1XLBook1.Save(@"c:\Save.xlsx");
      System.Diagnostics.Process.Start(@"c:\Save.xlsx");
    3. Run the project to open the .xlsx file.
    4. In Excel, select the Page Layout tab, and select the Print checkbox under Gridlines. The worksheet should look similar to the following: