EasyXLS™ library provides the methods for setting the page setup options such as page orientation (portrait and landscape), paper size, scaling factor, fit paper width and paper height, paper margins, print area, rows to be repeated, print order, print gridlines, black and white printing, draft quality, row and column headings and comments printing.
The below example shows how to export an Excel file with a specified print area, rows repeated at top, page orientation as portrait, paper size as A4 and other related settings.
// Create an instance of the class that exports Excel files, having two sheets
ExcelDocument workbook = new ExcelDocument(2);
...
// Get the first sheet
ExcelWorksheet xlsFirstTab = (ExcelWorksheet)workbook.easy_getSheetAt(0);
// Get the object that stores the page setup options for the first sheet
ExcelPageSetup xlsPageSetup = xlsFirstTab.easy_getPageSetup();
// Set print area
xlsPageSetup.easy_setPrintArea("A1:E101");
// Set the rows to repeat at top
xlsPageSetup.easy_setRowsToRepeatAtTop("$1:$1");
// Set center horizontally option
xlsPageSetup.setCenterHorizontally(true);
// Set page orientation
xlsPageSetup.setOrientation(PageSetup.ORIENTATION_PORTRAIT);
// Set page order
xlsPageSetup.setPageOrder(PageSetup.PAGE_ORDER_DOWN_THEN_OVER);
// Set paper size
xlsPageSetup.setPaperSize(PageSetup.PAPER_SIZE_A4);
// Set where the comments to be printed
xlsPageSetup.setPrintComments(PageSetup.COMMENTS_AT_END_OF_SHEET);
// Set the gridlines to be printed
xlsPageSetup.setPrintGridlines(true);
// Set page break preview for the sheet
xlsFirstTab.setPageBreakPreview(true);
...
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Page Setup.xlsx");
' Create an instance of the class that exports Excel files, having two sheetsDim workbook As New ExcelDocument(2)
...
' Get the first sheetDim xlsFirstTab As ExcelWorksheet = workbook.easy_getSheetAt(0)
' Get the object that stores the page setup options for the first sheetDim xlsPageSetup = xlsFirstTab.easy_getPageSetup()
' Set print area
xlsPageSetup.easy_setPrintArea("A1:E101")
' Set the rows to repeat at top
xlsPageSetup.easy_setRowsToRepeatAtTop("$1:$1")
' Set center horizontally option
xlsPageSetup.setCenterHorizontally(True)
' Set page orientation
xlsPageSetup.setOrientation(PageSetup.ORIENTATION_PORTRAIT)
' Set page order
xlsPageSetup.setPageOrder(PageSetup.PAGE_ORDER_DOWN_THEN_OVER)
' Set paper size
xlsPageSetup.setPaperSize(PageSetup.PAPER_SIZE_A4)
' Set where the comments to be printed
xlsPageSetup.setPrintComments(PageSetup.COMMENTS_AT_END_OF_SHEET)
' Set the gridlines to be printed
xlsPageSetup.setPrintGridlines(True)
' Set page break preview for the sheet
xlsFirstTab.setPageBreakPreview(True)
...
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Page Setup.xlsx")
C++// Create an instance of the class that exports Excel files
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook) ;
...
// Create two sheets
workbook->easy_addWorksheet_2("First tab");
workbook->easy_addWorksheet_2("Second tab");
// Get the first sheet
EasyXLS::IExcelWorksheetPtr xlsFirstTab =
(EasyXLS::IExcelWorksheetPtr)workbook->easy_getSheetAt(0);
// Get the object that stores the page setup options for the first sheet
EasyXLS::IExcelPageSetupPtr xlsPageSetup = xlsFirstTab->easy_getPageSetup();
// Set print area
xlsPageSetup->easy_setPrintArea_2("A1:E101");
// Set the rows to repeat at top
xlsPageSetup->easy_setRowsToRepeatAtTop_2("$1:$1");
// Set center horizontally option
xlsPageSetup->setCenterHorizontally(true);
// Set page orientation
xlsPageSetup->setOrientation(PAGESETUP_ORIENTATION_PORTRAIT);
// Set page order
xlsPageSetup->setPageOrder(PAGESETUP_PAGE_ORDER_DOWN_THEN_OVER);
// Set paper size
xlsPageSetup->setPaperSize(PAGESETUP_PAPER_SIZE_A4);
// Set where the comments to be printed
xlsPageSetup->setPrintComments(PAGESETUP_COMMENTS_AT_END_OF_SHEET);
// Set the gridlines to be printed
xlsPageSetup->setPrintGridlines(true);
// Set page break preview for the sheet
xlsFirstTab->setPageBreakPreview(true);
...
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Page Setup.xlsx");
Click here to see Continuous Code ListingC++.NET// Create an instance of the class that exports Excel files, having two sheets
ExcelDocument ^workbook = gcnew ExcelDocument(2);
...
// Get the first sheet
ExcelWorksheet ^xlsFirstTab =
safe_cast<ExcelWorksheet^>(workbook->easy_getSheetAt(0));
// Get the object that stores the page setup options for the first sheet
ExcelPageSetup ^xlsPageSetup = xlsFirstTab->easy_getPageSetup();
// Set print area
xlsPageSetup->easy_setPrintArea("A1:E101");
// Set the rows to repeat at top
xlsPageSetup->easy_setRowsToRepeatAtTop("$1:$1");
// Set center horizontally option
xlsPageSetup->setCenterHorizontally(true);
// Set page orientation
xlsPageSetup->setOrientation(PageSetup::ORIENTATION_PORTRAIT);
// Set page order
xlsPageSetup->setPageOrder(PageSetup::PAGE_ORDER_DOWN_THEN_OVER);
// Set paper size
xlsPageSetup->setPaperSize(PageSetup::PAPER_SIZE_A4);
// Set where the comments to be printed
xlsPageSetup->setPrintComments(PageSetup::COMMENTS_AT_END_OF_SHEET);
// Set the gridlines to be printed
xlsPageSetup->setPrintGridlines(true);
// Set page break preview for the sheet
xlsFirstTab->setPageBreakPreview(true);
...
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Page Setup.xlsx");
Click here to see Continuous Code Listing
// Create an instance of the class that exports Excel files, having two sheets
ExcelDocument workbook = new ExcelDocument(2);
...
// Get the first sheet
ExcelWorksheet xlsFirstTab = (ExcelWorksheet)workbook.easy_getSheetAt(0);
// Get the object that stores the page setup options for the first sheet
ExcelPageSetup xlsPageSetup = xlsFirstTab.easy_getPageSetup();
// Set print area
xlsPageSetup.easy_setPrintArea("A1:E101");
// Set the rows to repeat at top
xlsPageSetup.easy_setRowsToRepeatAtTop("$1:$1");
// Set center horizontally option
xlsPageSetup.setCenterHorizontally(true);
// Set page orientation
xlsPageSetup.setOrientation(PageSetup.ORIENTATION_PORTRAIT);
// Set page order
xlsPageSetup.setPageOrder(PageSetup.PAGE_ORDER_DOWN_THEN_OVER);
// Set paper size
xlsPageSetup.setPaperSize(PageSetup.PAPER_SIZE_A4);
// Set where the comments to be printed
xlsPageSetup.setPrintComments(PageSetup.COMMENTS_AT_END_OF_SHEET);
// Set the gridlines to be printed
xlsPageSetup.setPrintGridlines(true);
// Set page break preview for the sheet
xlsFirstTab.setPageBreakPreview(true);
...
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Page Setup.xlsx");
.NET:// Create an instance of the class that exports Excel files
$workbook = new COM("EasyXLS.ExcelDocument");
// Create two sheets
$workbook->easy_addWorksheet_2("First tab");
$workbook->easy_addWorksheet_2("Second tab");
...
// Get the first sheet
$xlsFirstTab = $workbook->easy_getSheetAt(0);
// Get the object that stores the page setup options for the first sheet
$xlsPageSetup = $xlsFirstTab->easy_getPageSetup();
// Set print area
$xlsPageSetup->easy_setPrintArea_2("A1:E101");
// Set the rows to repeat at top
$xlsPageSetup->easy_setRowsToRepeatAtTop_2("$1:$1");
// Set center horizontally option
$xlsPageSetup->setCenterHorizontally(true);
// Set page orientation
$xlsPageSetup->setOrientation($PAGESETUP_ORIENTATION_PORTRAIT);
// Set page order
$xlsPageSetup->setPageOrder($PAGESETUP_PAGE_ORDER_DOWN_THEN_OVER);
// Set paper size
$xlsPageSetup->setPaperSize($PAGESETUP_PAPER_SIZE_A4);
// Set where the comments to be printed
$xlsPageSetup->setPrintComments($PAGESETUP_COMMENTS_AT_END_OF_SHEET);
// Set the gridlines to be printed
$xlsPageSetup->setPrintGridlines(true);
// Set page break preview for the sheet
$xlsFirstTab->setPageBreakPreview(true);
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Page Setup.xlsx");
Click here to see Continuous Code ListingJava:// Create an instance of the class that exports Excel files
$workbook = new java("EasyXLS.ExcelDocument");
// Create two sheets
$workbook->easy_addWorksheet("First tab");
$workbook->easy_addWorksheet("Second tab");
...
// Get the first sheet
$xlsFirstTab = $workbook->easy_getSheetAt(0);
// Get the object that stores the page setup options for the first sheet
$xlsPageSetup = $xlsFirstTab->easy_getPageSetup();
// Set print area
$xlsPageSetup->easy_setPrintArea("A1:E101");
// Set the rows to repeat at top
$xlsPageSetup->easy_setRowsToRepeatAtTop("$1:$1");
// Set center on page option
$xlsPageSetup->setCenterHorizontally(true);
// Set page orientation
$xlsPageSetup->setOrientation($PAGESETUP_ORIENTATION_PORTRAIT);
// Set page order
$xlsPageSetup->setPageOrder($PAGESETUP_PAGE_ORDER_DOWN_THEN_OVER);
// Set paper size
$xlsPageSetup->setPaperSize($PAGESETUP_PAPER_SIZE_A4);
// Set where the comments to be printed
$xlsPageSetup->setPrintComments($PAGESETUP_COMMENTS_AT_END_OF_SHEET);
// Set the gridlines to be printed
$xlsPageSetup->setPrintGridlines(true);
// Set page break preview for the sheet
$xlsFirstTab->setPageBreakPreview(true);
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Page Setup.xlsx");
Click here to see Continuous Code Listing
' Create an instance of the class that exports Excel filesset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
...
' Create two sheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
' Get the first sheetset xlsFirstTab = workbook.easy_getSheetAt(0)
' Get the object that stores the page setup options for the first sheetset xlsPageSetup = xlsFirstTab.easy_getPageSetup()
' Set print area
xlsPageSetup.easy_setPrintArea_2("A1:E101")
' Set the rows to repeat at top
xlsPageSetup.easy_setRowsToRepeatAtTop_2("$1:$1")
' Set center horizontally option
xlsPageSetup.setCenterHorizontally(true)
' Set page orientation
xlsPageSetup.setOrientation(PAGESETUP_ORIENTATION_PORTRAIT)
' Set page order
xlsPageSetup.setPageOrder(PAGESETUP_PAGE_ORDER_DOWN_THEN_OVER)
' Set paper size
xlsPageSetup.setPaperSize(PAGESETUP_PAPER_SIZE_A4)
' Set where the comments to be printed
xlsPageSetup.setPrintComments(PAGESETUP_COMMENTS_AT_END_OF_SHEET)
' Set the gridlines to be printed
xlsPageSetup.setPrintGridlines(True)
' Set page break preview for the sheet
xlsFirstTab.setPageBreakPreview(True)
...
' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Page Setup.xlsx")
' Create an instance of the class that exports Excel filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
...
' Create two sheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
' Get the first sheetSet xlsFirstTab = workbook.easy_getSheetAt(0)
' Get the object that stores the page setup options for the first sheetSet xlsPageSetup = xlsFirstTab.easy_getPageSetup()
' Set print area
xlsPageSetup.easy_setPrintArea_2("A1:E101")
' Set the rows to repeat at top
xlsPageSetup.easy_setRowsToRepeatAtTop_2("$1:$1")
' Set center horizontally option
xlsPageSetup.setCenterHorizontally(True)
' Set page orientation
xlsPageSetup.setOrientation(PageSetup.PAGESETUP_ORIENTATION_PORTRAIT)
' Set page order
xlsPageSetup.setPageOrder(PageSetup.PAGESETUP_PAGE_ORDER_DOWN_THEN_OVER)
' Set paper size
xlsPageSetup.setPaperSize(PageSetup.PAGESETUP_PAPER_SIZE_A4)
' Set where the comments to be printed
xlsPageSetup.setPrintComments(PageSetup.PAGESETUP_COMMENTS_AT_END_OF_SHEET)
' Set the gridlines to be printed
xlsPageSetup.setPrintGridlines(True)
' Set page break preview for the sheet
xlsFirstTab.setPageBreakPreview(True)
...
' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Page Setup.xlsx")
' Create an instance of the class that exports Excel filesset workbook = CreateObject("EasyXLS.ExcelDocument")
...
' Create two sheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
' Get the first sheetset xlsFirstTab = workbook.easy_getSheetAt(0)
' Get the object that stores the page setup options for the first sheetset xlsPageSetup = xlsFirstTab.easy_getPageSetup()
' Set print area
xlsPageSetup.easy_setPrintArea_2("A1:E101")
' Set the rows to repeat at top
xlsPageSetup.easy_setRowsToRepeatAtTop_2("$1:$1")
' Set center horizontally option
xlsPageSetup.setCenterHorizontally(True)
' Set page orientation
xlsPageSetup.setOrientation(PAGESETUP_ORIENTATION_PORTRAIT)
' Set page order
xlsPageSetup.setPageOrder(PAGESETUP_PAGE_ORDER_DOWN_THEN_OVER)
' Set paper size
xlsPageSetup.setPaperSize(PAGESETUP_PAPER_SIZE_A4)
' Set where the comments to be printed
xlsPageSetup.setPrintComments(PAGESETUP_COMMENTS_AT_END_OF_SHEET)
' Set the gridlines to be printed
xlsPageSetup.setPrintGridlines(True)
' Set page break preview for the sheet
xlsFirstTab.setPageBreakPreview(True)
...
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Page Setup.xlsx")
<!-- Create an instance of the class that exports Excel files --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE">
...
<!-- Create two sheets --><cfset ret = workbook.easy_addWorksheet("First tab")><cfset ret = workbook.easy_addWorksheet("Second tab")><!-- Get the first sheet --><cfset xlsFirstTab = workbook.easy_getSheetAt(0)><!-- Get the object that stores the page setup options for the first sheet --><cfset xlsPageSetup = xlsFirstTab.easy_getPageSetup()><!-- Set print area --><cfset xlsPageSetup.easy_setPrintArea("A1:E101")><!-- Set the rows to repeat at top --><cfset xlsPageSetup.easy_setRowsToRepeatAtTop("$1:$1")><!-- Set center horizontally option --><cfset xlsPageSetup.setCenterHorizontally(true)><!-- Set page orientation --><cfset xlsPageSetup.setOrientation(PageSetup.ORIENTATION_PORTRAIT)><!-- Set page order --><cfset xlsPageSetup.setPageOrder(PageSetup.PAGE_ORDER_DOWN_THEN_OVER)><!-- Set paper size --><cfset xlsPageSetup.setPaperSize(PageSetup.PAPER_SIZE_A4)><!-- Set where the comments to be printed --><cfset xlsPageSetup.setPrintComments(PageSetup.COMMENTS_AT_END_OF_SHEET)><!-- Set the gridlines to be printed --><cfset xlsPageSetup.setPrintGridlines(true)><!-- Set page break preview for the sheet --><cfset xlsFirstTab.setPageBreakPreview(true)>
...
<!-- Export Excel file --><cfset ret = workbook.easy_WriteXLSXFile("C:\Samples\Page Setup.xlsx")>
.NET:# Create an instance of the class that exports Excel files, having two sheets
workbook = ExcelDocument(2)
...
# Get the table of data for the first worksheet
xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
# Get the object that stores the page setup options for the first sheet
xlsPageSetup = xlsFirstTab.easy_getPageSetup()
# Set print area
xlsPageSetup.easy_setPrintArea("A1:E101")
# Set the rows to repeat at top
xlsPageSetup.easy_setRowsToRepeatAtTop("$1:$1")
# Set center on page option
xlsPageSetup.setCenterHorizontally(True)
# Set page orientation
xlsPageSetup.setOrientation(PageSetup.ORIENTATION_PORTRAIT)
# Set page order
xlsPageSetup.setPageOrder(PageSetup.PAGE_ORDER_DOWN_THEN_OVER)
# Set paper size
xlsPageSetup.setPaperSize(PageSetup.PAPER_SIZE_A4)
# Set where the comments to be printed
xlsPageSetup.setPrintComments(PageSetup.COMMENTS_AT_END_OF_SHEET)
# Set the gridlines to be printed
xlsPageSetup.setPrintGridlines(True)
# Set page break preview for the sheet
xlsFirstTab.setPageBreakPreview(True)
...
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Page Setup.xlsx")
Click here to see Continuous Code ListingJava:# Create an instance of the class that exports Excel files, having two sheets
workbook = gateway.jvm.ExcelDocument(2)
...
# Get the table of data for the first worksheet
xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
# Get the object that stores the page setup options for the first sheet
xlsPageSetup = xlsFirstTab.easy_getPageSetup()
# Set print area
xlsPageSetup.easy_setPrintArea("A1:E101")
# Set the rows to repeat at top
xlsPageSetup.easy_setRowsToRepeatAtTop("$1:$1")
# Set center on page option
xlsPageSetup.setCenterHorizontally(True)
# Set page orientation
xlsPageSetup.setOrientation(gateway.jvm.PageSetup.ORIENTATION_PORTRAIT)
# Set page order
xlsPageSetup.setPageOrder(gateway.jvm.PageSetup.PAGE_ORDER_DOWN_THEN_OVER)
# Set paper size
xlsPageSetup.setPaperSize(gateway.jvm.PageSetup.PAPER_SIZE_A4)
# Set where the comments to be printed
xlsPageSetup.setPrintComments(gateway.jvm.PageSetup.COMMENTS_AT_END_OF_SHEET)
# Set the gridlines to be printed
xlsPageSetup.setPrintGridlines(True)
# Set page break preview for the sheet
xlsFirstTab.setPageBreakPreview(True)
...
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Page Setup.xlsx")
Click here to see Continuous Code Listing
The screen shot provides an example of an Excel report that has the following page setup options for a worksheet: print area, rows to be repeated at top, center horizontally, page orientation (portrait), page order (down), paper size (A4), print comments and gridlines, page break at row 21.
In order to visualize the printable area and the pagination, the view must be set on "Page Break Preview" mode using ExcelWorksheet.setPageBreakPreview method.