Introduction
Page setup settings also provide several Print Options (also reffered as Sheet Options) that allow users to control their printed pages of worksheets. These print options allow users to:
- Select a specific Print Area of the worksheet
- Print Titles
- Print Gridlines
- Print Row/Column Headings
- Achieve Draft Quality
- Print Comments
- Print Cell Errors
- Define Page Ordering
All of these print options are shown below in the figure:
|
Figure: Print (Sheet) Options
|
Setting Print/Sheet Options
Aspose.Cells supports all of these print options and developers can easily configure these options for their desired worksheets using the several properties offered by PageSetup class. The usage of these properties of PageSetup class is discussed below in more detail.
Set Print Area
By default, only that print area is selected that incorporates the entire area of the worksheet, which contains data but developers can also establish a specific print area of the worksheet according to their desire.
To select a specific print area, developers can use PrintArea property of the PageSetup class. You can assign the cells range of the print area to this property.
Example:
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the PageSetup of the worksheet
Aspose.Cells.PageSetup pageSetup = workbook.Worksheets[0].PageSetup;
//Specifying the cells range (from A1 cell to T35 cell) of the print area
pageSetup.PrintArea = "A1:T35";
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Obtaining the reference of the PageSetup of the worksheet
Dim pageSetup As Aspose.Cells.PageSetup = workbook.Worksheets(0).PageSetup
'Specifying the cells range (from A1 cell to T35 cell) of the print area
pageSetup.PrintArea = "A1:T35"
[JAVA]
//Instantiating a Workbook object
Workbook workbook=new Workbook();
//Accessing the first worksheet in the Workbook file
Worksheets worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.getSheet(0);
//Obtaining the reference of the PageSetup of the worksheet
PageSetup pageSetup = sheet.getPageSetup();
//Specifying the cells range (from A1 cell to T35 cell) of the print area
pageSetup.setPrintArea("A1:T35");
Set Print Titles
Aspose.Cells allows you to designate row and column headers that you want to have repeated on all pages of your printed worksheet. To do so, developers can use PrintTitleColumns and PrintTitleRows properties of the PageSetup class.
The rows or columns (to be repeated on all pages of the printed worksheet) are defined by passing their row or column numbers. For example, rows are defined as $1:$2 and columns are defined as $A:$B.
Example:
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the PageSetup of the worksheet
Aspose.Cells.PageSetup pageSetup = workbook.Worksheets[0].PageSetup;
//Defining column numbers A & B as title columns
pageSetup.PrintTitleColumns = "$A:$B";
//Defining row numbers 1 & 2 as title rows
pageSetup.PrintTitleRows = "$1:$2";
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Obtaining the reference of the PageSetup of the worksheet
Dim pageSetup As Aspose.Cells.PageSetup = workbook.Worksheets(0).PageSetup
'Defining column numbers A & B as title columns
pageSetup.PrintTitleColumns = "$A:$B"
'Defining row numbers 1 & 2 as title rows
pageSetup.PrintTitleRows = "$1:$2"
[JAVA]
//Instantiating a Workbook object
Workbook workbook=new Workbook();
//Accessing the first worksheet in the Workbook file
Worksheets worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.getSheet(0);
//Obtaining the reference of the PageSetup of the worksheet
PageSetup pageSetup = sheet.getPageSetup();
//Defining column numbers A & B as title columns
pageSetup.setPrintTitleColumns("$A:$B");
//Defining row numbers 1 & 2 as title rows
pageSetup.setPrintTitleRows("$1:$2");
Set Other Print Options
PageSetup class also provides several other properties to set general print options as follows:
- PrintGridlines , a boolean property that defines whether to print or not print gridlines
- PrintHeadings , a boolean property that defines whether to print row and column headings or not
- BlackAndWhite , a boolean property that defines whether to print worksheet in black and white mode or not
- PrintComments , defines that whether to display the print comments on the worksheet or at the end of the worksheet
- Draft , a boolean property that defines whether to print worksheet in draft quality or not
- PrintErrors , defines that whether to print cell errors as displayed, blank, dash or N/A
To set PrintComments and PrintErrors properties, Aspose.Cells also provides two enumerations, PrintCommentsType & PrintErrorsType that contain pre-defined values to be assigned to PrintComments and PrintErrors properties respectively.
The pre-defined values of PrintCommentsType enumeration are listed below with their descriptions:
|
Print Comments Types
|
Description
|
|
PrintInPlace
|
Specifies to print comments as displayed on worksheet
|
|
PrintNoComments
|
Specifies not to print comments
|
|
PrintSheetEnd
|
Specifies to print comments at the end of worksheet
|
The pre-defined values of PrintErrorsType enumeration are listed below with their descriptions:
|
Print Errors Types
|
Description
|
|
PrintErrorsBlank
|
Specifies not to print errors
|
|
PrintErrorsDash
|
Specifies to print errors as "--"
|
|
PrintErrorsDisplayed
|
Specifies to print errors as displayed
|
|
PrintErrorsNA
|
Specifies to print errors as "#N/A"
|
Example:
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the PageSetup of the worksheet
Aspose.Cells.PageSetup pageSetup = workbook.Worksheets[0].PageSetup;
//Allowing to print gridlines
pageSetup.PrintGridlines = true;
//Allowing to print row/column headings
pageSetup.PrintHeadings = true;
//Allowing to print worksheet in black & white mode
pageSetup.BlackAndWhite = true;
//Allowing to print comments as displayed on worksheet
pageSetup.PrintComments = PrintCommentsType.PrintInPlace;
//Allowing to print worksheet with draft quality
pageSetup.Draft = true;
//Allowing to print cell errors as N/A
pageSetup.PrintErrors = PrintErrorsType.PrintErrorsNA;
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Obtaining the reference of the PageSetup of the worksheet
Dim pageSetup As Aspose.Cells.PageSetup = workbook.Worksheets(0).PageSetup
'Allowing to print gridlines
pageSetup.PrintGridlines = true
'Allowing to print row/column headings
pageSetup.PrintHeadings = true
'Allowing to print worksheet in black & white mode
pageSetup.BlackAndWhite = true
'Allowing to print comments as displayed on worksheet
pageSetup.PrintComments = PrintCommentsType.PrintInPlace
'Allowing to print worksheet with draft quality
pageSetup.Draft = true
'Allowing to print cell errors as N/A
pageSetup.PrintErrors = PrintErrorsType.PrintErrorsNA
[JAVA]
//Instantiating a Workbook object
Workbook workbook=new Workbook();
//Accessing the first worksheet in the Workbook file
Worksheets worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.getSheet(0);
//Obtaining the reference of the PageSetup of the worksheet
PageSetup pageSetup = sheet.getPageSetup();
//Allowing to print gridlines
pageSetup.setPrintGridlines(true);
//Allowing to print row/column headings
pageSetup.setPrintHeadings(true);
//Allowing to print worksheet in black & white mode
pageSetup.setBlackAndWhite (true);
//Allowing to print comments as displayed on worksheet
pageSetup.setPrintComments ( PrintCommentsType.PRINT_IN_PLACE);
//Allowing to print worksheet with draft quality
pageSetup.setDraftQuality (true);
//Allowing to print cell errors as N/A
pageSetup.setPrintErrors(PrintErrorsType.PRINT_ERRORS_NA);
Set Page Order
PageSetup class provides Order property that is used to order multiple pages of your worksheet to be printed. There are two possibilities to order the pages as follows:
- Down then over thus it will print all pages down before printing pages to the right
- Over then down thus it will print pages left to right before printing pages below
Aspose.Cells provides an enumeration, PrintOrderType that contains all pre-defined order types to be assigned to Order property.
The pre-defined values of PrintOrderType enumeration are listed below with their descriptions: