EasyXLS™ library allows you to insert page breaks on rows or columns for a sheet of an Excel file. The page breaks separate the pages when the document is printed.
// Create an instance of the class that exports Excel files, having two sheets
ExcelDocument workbook = new ExcelDocument(2);
...
// Get the table of data for the first sheet
ExcelTable xlsFirstTable =
((ExcelWorksheet)workbook.easy_getSheetAt(0)).easy_getExcelTable();
...
// Insert page breaks on rows
xlsFirstTable.easy_insertPageBreakAtRow(21);
xlsFirstTable.easy_insertPageBreakAtRow(41);
xlsFirstTable.easy_insertPageBreakAtRow(61);
xlsFirstTable.easy_insertPageBreakAtRow(81);
// Set page break preview for the sheet
xlsFirstTab.setPageBreakPreview(true);
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel page breaks.xlsx");
' Create an instance of the class that exports Excel files, having two sheetsDim workbook As New ExcelDocument(2)
...
' Get the table of data for the first sheetDim xlsFirstTab As ExcelWorksheet = workbook.easy_getSheetAt(0)
Dim xlsFirstTable = xlsFirstTab.easy_getExcelTable()
...
' Insert page breaks on rows
xlsFirstTable.easy_insertPageBreakAtRow(21)
xlsFirstTable.easy_insertPageBreakAtRow(41)
xlsFirstTable.easy_insertPageBreakAtRow(61)
xlsFirstTable.easy_insertPageBreakAtRow(81)
' Set page break preview for the sheet
xlsFirstTab.setPageBreakPreview(True)
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Excel page breaks.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 table of data for the first sheet
EasyXLS::IExcelWorksheetPtr xlsFirstTab =
(EasyXLS::IExcelWorksheetPtr)workbook->easy_getSheetAt(0);
EasyXLS::IExcelTablePtr xlsFirstTable = xlsFirstTab->easy_getExcelTable();
...
// Insert page breaks on rows
xlsFirstTable->easy_insertPageBreakAtRow(21);
xlsFirstTable->easy_insertPageBreakAtRow(41);
xlsFirstTable->easy_insertPageBreakAtRow(61);
xlsFirstTable->easy_insertPageBreakAtRow(81);
// Set page break preview for the sheet
xlsFirstTab->setPageBreakPreview(true);
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Excel page breaks.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 table of data for the first sheet
ExcelWorksheet ^xlsFirstTab =
safe_cast<ExcelWorksheet^>(workbook->easy_getSheetAt(0));
ExcelTable ^xlsFirstTable = xlsFirstTab->easy_getExcelTable();
...
// Insert page breaks on rows
xlsFirstTable->easy_insertPageBreakAtRow(21);
xlsFirstTable->easy_insertPageBreakAtRow(41);
xlsFirstTable->easy_insertPageBreakAtRow(61);
xlsFirstTable->easy_insertPageBreakAtRow(81);
// Set page break preview for the sheet
xlsFirstTab->setPageBreakPreview(true);
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Excel page breaks.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 table of data for the first sheet
ExcelTable xlsFirstTable =
((ExcelWorksheet)workbook.easy_getSheetAt(0)).easy_getExcelTable();
...
// Insert page breaks on rows
xlsFirstTable.easy_insertPageBreakAtRow(21);
xlsFirstTable.easy_insertPageBreakAtRow(41);
xlsFirstTable.easy_insertPageBreakAtRow(61);
xlsFirstTable.easy_insertPageBreakAtRow(81);
// Set page break preview for the sheet
xlsFirstTab.setPageBreakPreview(true);
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel page breaks.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 table of data for the first sheet
$xlsFirstTable = $workbook->easy_getSheetAt(0)->easy_getExcelTable();
...
// Insert page breaks on rows
$xlsFirstTable->easy_insertPageBreakAtRow(21);
$xlsFirstTable->easy_insertPageBreakAtRow(41);
$xlsFirstTable->easy_insertPageBreakAtRow(61);
$xlsFirstTable->easy_insertPageBreakAtRow(81);
// Set page break preview for the sheet
$xlsFirstTab->setPageBreakPreview(true);
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Excel page breaks.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 table of data for the first worksheet
$xlsFirstTable = $workbook->easy_getSheetAt(0)->easy_getExcelTable();
...
// Insert page breaks on rows
$xlsFirstTable->easy_insertPageBreakAtRow(21);
$xlsFirstTable->easy_insertPageBreakAtRow(41);
$xlsFirstTable->easy_insertPageBreakAtRow(61);
$xlsFirstTable->easy_insertPageBreakAtRow(81);
// Set page break preview for the sheet
$xlsFirstTab->setPageBreakPreview(true);
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Excel page breaks.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 table of data for the first sheetset xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
...
' Insert page breaks on rows
xlsFirstTable.easy_insertPageBreakAtRow(21)
xlsFirstTable.easy_insertPageBreakAtRow(41)
xlsFirstTable.easy_insertPageBreakAtRow(61)
xlsFirstTable.easy_insertPageBreakAtRow(81)
' Set page break preview for the sheet
xlsFirstTab.setPageBreakPreview(True)
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Excel page breaks.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 table of data for the first sheetSet xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
...
' Insert page breaks on rows
xlsFirstTable.easy_insertPageBreakAtRow(21)
xlsFirstTable.easy_insertPageBreakAtRow(41)
xlsFirstTable.easy_insertPageBreakAtRow(61)
xlsFirstTable.easy_insertPageBreakAtRow(81)
' Set page break preview for the sheet
xlsFirstTab.setPageBreakPreview(True)
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Excel page breaks.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 table of data for the first sheetSet xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
...
' Insert page breaks on rows
xlsFirstTable.easy_insertPageBreakAtRow(21)
xlsFirstTable.easy_insertPageBreakAtRow(41)
xlsFirstTable.easy_insertPageBreakAtRow(61)
xlsFirstTable.easy_insertPageBreakAtRow(81)
' Set page break preview for the sheet
xlsFirstTab.setPageBreakPreview(True)
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Excel page breaks.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 table of data for the first sheet --><cfset xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()>
...
<!-- Insert page breaks on rows --><cfset xlsFirstTable.easy_insertPageBreakAtRow(21)><cfset xlsFirstTable.easy_insertPageBreakAtRow(41)><cfset xlsFirstTable.easy_insertPageBreakAtRow(61)><cfset xlsFirstTable.easy_insertPageBreakAtRow(81)><!-- Set page break preview for the sheet --><cfset xlsFirstTab.setPageBreakPreview(true)><!-- Export Excel file --><cfset ret = workbook.easy_WriteXLSXFile("C:\Samples\Excel page breaks.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()
...
# Insert page breaks on rows
xlsFirstTable.easy_insertPageBreakAtRow(21)
xlsFirstTable.easy_insertPageBreakAtRow(41)
xlsFirstTable.easy_insertPageBreakAtRow(61)
xlsFirstTable.easy_insertPageBreakAtRow(81)
# Set page break preview for the sheet
xlsFirstTab.setPageBreakPreview(True)
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel page breaks.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()
...
# Insert page breaks on rows
xlsFirstTable.easy_insertPageBreakAtRow(21)
xlsFirstTable.easy_insertPageBreakAtRow(41)
xlsFirstTable.easy_insertPageBreakAtRow(61)
xlsFirstTable.easy_insertPageBreakAtRow(81)
# Set page break preview for the sheet
xlsFirstTab.setPageBreakPreview(True)
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel page breaks.xlsx")
Click here to see Continuous Code Listing
The screen shot provides an example of an Excel report that has a visible page break at row 21. The page break preview layout is selected.
In order to visualize the printable area and the pagination, the view must be set on "Page Break Preview" mode using ExcelWorksheet.setPageBreakPreview method.