Spread Windows Forms 18
Spread Windows Forms 18 Product Documentation / Developer's Guide / Printing / Customizing the Appearance of the Printing / Adding a Page Break
In This Topic
    Adding a Page Break
    In This Topic

    Spread allows you to add a force page break before a specified column or row by using the SetRowPageBreak and the SetColumnPageBreak methods.  A column page break occurs to the left of the specified column and a row page break occurs above the specified row.

    You can also retrieve the number of the next column or row in the sheet where a page break occurs. To find the page breaks that are already set, use the GetRowPageBreak method to return the number of row page breaks and use the GetColumnPageBreak method to return the number of column page breaks. 

    Along with that, Spread allows you to manage the visibility of page breaks in worksheet while rendering. The DisplayPageBreaks property of the IWorksheet interface indicates whether the page break will be displayed in the worksheet or not. The default value of this boolean type property is false. You must enable it to display the page breaks in the worksheet at runtime. 

    Moreover, the displayed page breaks in worksheet while printing in Spread is similar to the page breaks displayed by Excel while previewing a worksheet for printing.  

    The displaying of page break in worksheet only works when the LegacyBehaviors.Style is excluded from LegacyBehaviors enum. 

    You can calculate the number of printed pages for the worksheet using the GetPrintPageCount method.

    The below image displays the page breaks in worksheet.

    The following code is used to add and display page breaks in worksheet.

    C#
    Copy Code
    FarPoint.Win.Spread.PrintInfo pi = new FarPoint.Win.Spread.PrintInfo();
    pi.UseMax = false;
    fpSpread1.Sheets[0].PrintInfo = pi;
    fpSpread1.Sheets[0].SetRowPageBreak(2, true);
    IWorksheet sheet = fpSpread1.AsWorkbook().ActiveSheet;
    // Enable ExcelCompatiblePrinting
    fpSpread1.Features.ExcelCompatiblePrinting = true;
    // Enable DisplayPageBreaks
    sheet.DisplayPageBreaks = true;
    sheet.PageSetup.Zoom = 100;
    // Get row page breaks
    private void Getrowpagebreak_Click(object sender, EventArgs e)
    {
      listbox1.Items.Clear(); // Clear listBox1 before adding new items
      int[] i;
      i = fpSpread1.GetRowPageBreaks(0);
      foreach (object o in i)
               {
                   listbox1.Items.Add(o); 
               }
    } 
    
    Visual Basic
    Copy Code
    Dim pi As FarPoint.Win.Spread.PrintInfo = New FarPoint.Win.Spread.PrintInfo()
    pi.UseMax = False
    FpSpread1.Sheets(0).PrintInfo = pi
    FpSpread1.Sheets(0).SetRowPageBreak(2, True) 
    Dim sheet As IWorksheet = FpSpread1.AsWorkbook().ActiveSheet 
    ' Enable ExcelCompatiblePrinting
    FpSpread1.Features.ExcelCompatiblePrinting = True
    ' Enable DisplayPageBreaks
    sheet.DisplayPageBreaks = True
    sheet.PageSetup.Zoom = 100
    ' Get row page breaks
    Private Sub GetRowPageBreak_Click(sender As Object, e As EventArgs)
      listbox1.Items.Clear()
      Dim i As Integer() = FpSpread1.GetRowPageBreaks(0)
      For Each o As Integer In i
             listbox1.Items.Add(o)
      Next
    End Sub 
    
    See Also