Spread WPF 18
Features / Print / Print Options
In This Topic
    Print Options
    In This Topic

    This topic explains various printing options available in Spread for WPF. You can print a worksheet, the complete workbook, or a specified range of worksheets based on your requirements.

    To perform all these printing operations, use the Print and PrintToDocument methods of the GcSpreadSheet class. Using the PrintToDocument method, you can view the printed pages in the DocumentViewer. However, if you want to print without customizing any print settings, simply pass NULL to these print methods.

    Note that the following are not supported during the printing process.

    Print Workbook

    To print an entire workbook, use the Print method of GcSpreadSheet class. You need to set the parameter of this method to -1 to include all the worksheets of the workbook for printing.

    The following example code prints the complete workbook.

    Copy Code
    // Print all worksheets (the entire workbook).
    GrapeCity.Wpf.SpreadSheet.Printing.PrintSettings printSetting = new GrapeCity.Wpf.SpreadSheet.Printing.PrintSettings();
    spreadSheet1.Print(-1, printSetting, true);
    
    Copy Code
    ' Print all worksheets (the entire workbook).
    Dim printSetting As GrapeCity.Wpf.SpreadSheet.Printing.PrintSettings = New GrapeCity.Wpf.SpreadSheet.Printing.PrintSettings()
    spreadSheet1.Print(-1, printSetting, True)
    

    Print Worksheet

    To print a worksheet, use the Print method of the GcSpreadSheet class. To print individual worksheets in a workbook, you need to specify a worksheet by its index. The default value of this method is -1, which prints the entire workbook.

    The following example code shows how to print a worksheet with index 1.

    Copy Code
    // "1" is the index of the worksheet to print.
    GrapeCity.Wpf.SpreadSheet.Printing.PrintSettings printSetting = new GrapeCity.Wpf.SpreadSheet.Printing.PrintSettings();
    spreadSheet1.Print(1, printSetting, true);
    
    Copy Code
    ' "1" is the index of the worksheet to print.
    Dim printSetting As GrapeCity.Wpf.SpreadSheet.Printing.PrintSettings = New GrapeCity.Wpf.SpreadSheet.Printing.PrintSettings()
    spreadSheet1.Print(1, printSetting, True)
    

    Print Range of Worksheets

    To print a range of worksheets in a workbook, define the range to print by specifying the first and last worksheets in the FromPage and ToPage properties of the PrintSettings class.

    The following example code shows how to print a specific range of worksheets within a workbook.

    Copy Code
    // Print from page 1 to page 3.
    GrapeCity.Wpf.SpreadSheet.Printing.PrintSettings printSetting = new GrapeCity.Wpf.SpreadSheet.Printing.PrintSettings();
    printSetting.FromPage = 1;
    printSetting.ToPage = 3;
    spreadSheet1.Print(-1, printSetting, true);
    
    Copy Code
    ' Print from page 1 to page 3.
    Dim printSetting As GrapeCity.Wpf.SpreadSheet.Printing.PrintSettings = New GrapeCity.Wpf.SpreadSheet.Printing.PrintSettings()
    printSetting.FromPage = 1
    printSetting.ToPage = 3
    spreadSheet1.Print(-1, printSetting, True)
    

    Print Cell Range

    To print a specific area of a worksheet, you can specify the print region rather than printing the entire workbook. Set the PrintArea property in the PrintSettings class to specify the cell range that you want to define as the print area. You can set the range to be printed as a Reference with row/column indexes or as A1 references. However, if you set the PrintArea to Reference.Empty, it prints the complete worksheet. Note that this property applies only to the worksheets. 

    The following example code shows how to set the print area in the worksheet.

    Copy Code
    GrapeCity.Wpf.SpreadSheet.Printing.PrintSettings printSetting = new GrapeCity.Wpf.SpreadSheet.Printing.PrintSettings();
    // Set print area.
    printSetting.PrintArea = new Reference("A1:E5");
    spreadSheet1.Print(1, printSetting, true); // Specify -1 to print all sheets.
    
    Copy Code
    Dim printSetting As GrapeCity.Wpf.SpreadSheet.Printing.PrintSettings = New GrapeCity.Wpf.SpreadSheet.Printing.PrintSettings()
    ' Set print area.
    printSetting.PrintArea = New Reference( "A1:E5" )
    spreadSheet1.Print(1, printSetting, True) ' Specify -1 to print all sheets.
    

    Print Titles

    Print titles allow you to choose which rows and columns should appear repeatedly on each printed page. The rows' title indicates the rows that contain the cells to be repeated at the top of each page, while the columns' title specifies the columns that contain the cells to be repeated on the left side of each page.

    Use PrintTitleRows and PrintTitleColumns properties of the IPageSetUp interface to select which rows and columns will appear on each printed page.

    The following example code sets the rows and columns that will be printed as titles on each page.

    Copy Code
    // Set print titles for rows and columns.
    GrapeCity.Wpf.SpreadSheet.Printing.PrintSettings printSetting = new GrapeCity.Wpf.SpreadSheet.Printing.PrintSettings();
    spreadSheet1.Workbook.ActiveSheet.PageSetup.PrintTitleRows = new Reference("3:3");
    spreadSheet1.Workbook.ActiveSheet.PageSetup.PrintTitleColumns = new Reference("A:C");
    spreadSheet1.Print(-1, printSetting, true);
    
    Copy Code
    ' Set print titles for rows and columns.
    Dim printSetting As GrapeCity.Wpf.SpreadSheet.Printing.PrintSettings = New GrapeCity.Wpf.SpreadSheet.Printing.PrintSettings()
    spreadSheet1.Workbook.ActiveSheet.PageSetup.PrintTitleRows = New Reference("3:3")
    spreadSheet1.Workbook.ActiveSheet.PageSetup.PrintTitleColumns = New Reference("A:C")
    spreadSheet1.Print(-1, printSetting, True)