EasyXLS™ library allows you to create Excel files with multiple sheets. There are two types of sheets: worksheets and chart sheets.
EasyXLS library can be integrated in:
- ASP.NET web pages - Windows applications - Windows Forms (WinForms) - Console applications - Windows service applications - ASP.NET MVC web applications - PHP and ASP web pages - Java applications
A worksheet is a sheet that contains a grid that consists of cells that are organized in rows and columns. The corresponding class in the library is ExcelWorksheet class.
The below source code sample shows how to export an Excel file with multiple sheets.
// Create an instance of the class that exports Excel files
ExcelDocument workbook = new ExcelDocument();
// Create a worksheet
workbook.easy_addWorksheet("First tab");
// Create another worksheet
workbook.easy_addWorksheet("Second tab");
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel file multiple sheets.xlsx");
' Create an instance of the class that exports Excel filesDim workbook As New ExcelDocument
' Create a worksheet
workbook.easy_addWorksheet("First tab")
' Create another worksheet
workbook.easy_addWorksheet("Second tab")
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Excel file multiple sheets.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 a worksheet
workbook->easy_addWorksheet_2("First tab");
// Create another worksheet
workbook->easy_addWorksheet_2("Second tab");
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Excel file multiple sheets.xlsx");
C++.NET// Create an instance of the class that exports Excel files
ExcelDocument ^workbook = gcnew ExcelDocument();
// Create a worksheet
workbook->easy_addWorksheet("First tab");
// Create another worksheet
workbook->easy_addWorksheet("Second tab");
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Excel file multiple sheets.xlsx");
// Create an instance of the class that exports Excel files
ExcelDocument workbook = new ExcelDocument();
// Create a worksheet
workbook.easy_addWorksheet("First tab");
// Create another worksheet
workbook.easy_addWorksheet("Second tab");
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel file multiple sheets.xlsx");
.NET:// Create an instance of the class that exports Excel files
$workbook = new COM("EasyXLS.ExcelDocument");
// Create a worksheet
$workbook->easy_addWorksheet_2("First tab");
// Create another worksheet
$workbook->easy_addWorksheet_2("Second tab");
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Excel file multiple sheets.xlsx");
Java:// Create an instance of the class that exports Excel files
$workbook = new java("EasyXLS.ExcelDocument");
// Create a worksheet
$workbook->easy_addWorksheet("First tab");
// Create another worksheet
$workbook->easy_addWorksheet("Second tab");
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Excel file multiple sheets.xlsx");
' Create an instance of the class that exports Excel filesset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Create a worksheet
workbook.easy_addWorksheet_2("First tab")
' Create another worksheet
workbook.easy_addWorksheet_2("Second tab")
' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Excel file multiple sheets.xlsx")
' Create an instance of the class that exports Excel filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Create a worksheet
workbook.easy_addWorksheet_2("First tab")
' Create another worksheet
workbook.easy_addWorksheet_2("Second tab")
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Excel file multiple sheets.xlsx")
' Create an instance of the class that exports Excel filesset workbook = CreateObject("EasyXLS.ExcelDocument")
' Create a worksheet
workbook.easy_addWorksheet_2("First tab")
' Create another worksheet
workbook.easy_addWorksheet_2("Second tab")
' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Excel file multiple sheets.xlsx")
<!--Create an instance of the class that exports Excel files --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Create a worksheet --><cfset ret = workbook.easy_addWorksheet("First tab")><!-- Create another worksheet --><cfset ret = workbook.easy_addWorksheet("Second tab")><!-- Export Excel file --><cfset ret = workbook.easy_WriteXLSXFile("C:\Samples\Excel file multiple sheets.xlsx")>
.NET:# Create an instance of the class that exports Excel files
workbook = ExcelDocument()
# Create a worksheet
workbook.easy_addWorksheet("First tab")
# Create another worksheet
workbook.easy_addWorksheet("Second tab")
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel file multiple sheets.xlsx")
Java:# Create an instance of the class that exports Excel files
workbook = gateway.jvm.ExcelDocument()
# Create a worksheet
workbook.easy_addWorksheet("First tab")
# Create another worksheet
workbook.easy_addWorksheet("Second tab")
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel file multiple sheets.xlsx")
The screen shot provides an example of an Excel file that has multiple sheets.
Create chart sheet
A chart sheet is a sheet that contains a graph. The corresponding class in the library is ExcelChartSheet class.
The below source code sample shows how to export an Excel file having one worksheet and one chart sheet.
// Create an instance of the class that exports Excel files
ExcelDocument workbook = new ExcelDocument();
// Create a worksheet
workbook.easy_addWorksheet("SourceData");
...
// Create a chart sheet
workbook.easy_addChart("Chart", "=SourceData!$A$1:$D$5", Chart.SERIES_IN_COLUMNS);
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel file multiple sheets.xlsx");
' Create an instance of the class that exports Excel filesDim workbook As New ExcelDocument
' Create a worksheet
workbook.easy_addWorksheet("SourceData")
...
' Create a chart sheet
workbook.easy_addChart("Chart", "=SourceData!$A$1:$D$5", Chart.SERIES_IN_COLUMNS)
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Excel file multiple sheets.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 a worksheet
workbook->easy_addWorksheet_2("SourceData");
...
// Create a chart sheet
workbook->easy_addChart_5("Chart", "=SourceData!$A$1:$D$5", CHART_SERIES_IN_COLUMNS);
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Excel file multiple sheets.xlsx");
Click here to see Continuous Code ListingC++.NET// Create an instance of the class that exports Excel files
ExcelDocument ^workbook = gcnew ExcelDocument();
// Create a worksheet
workbook->easy_addWorksheet("SourceData");
...
// Create a chart sheet
workbook->easy_addChart("Chart", "=SourceData!$A$1:$D$5", Chart::SERIES_IN_COLUMNS);
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Excel file multiple sheets.xlsx");
Click here to see Continuous Code Listing
// Create an instance of the class that exports Excel files
ExcelDocument workbook = new ExcelDocument();
// Create a worksheet
workbook.easy_addWorksheet("SourceData");
...
// Create a chart sheet
workbook.easy_addChart("Chart", "=SourceData!$A$1:$D$5", Chart.SERIES_IN_COLUMNS);
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel file multiple sheets.xlsx");
.NET:// Create an instance of the class that exports Excel files
$workbook = new COM("EasyXLS.ExcelDocument");
// Create a worksheet
$workbook->easy_addWorksheet_2("SourceData");
...
// Create a chart sheet
$workbook->easy_addChart_5("Chart", "=SourceData!\$A$1:\$D$5",
$CHART_SERIES_IN_COLUMNS);
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Excel file multiple sheets.xlsx");
Click here to see Continuous Code ListingJava:// Create an instance of the class that exports Excel files
$workbook = new java("EasyXLS.ExcelDocument");
// Create a worksheet
$workbook->easy_addWorksheet("SourceData");
...
// Add a chart sheet
$workbook->easy_addChart("Chart",
"=SourceData!\$A$1:\$D$5", $CHART_SERIES_IN_COLUMNS);
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Excel file multiple sheets.xlsx");
Click here to see Continuous Code Listing
' Create an instance of the class that exports Excel filesset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Create a worksheet
workbook.easy_addWorksheet_2("SourceData")
...
' Create a chart sheet
workbook.easy_addChart_5 "Chart", "=SourceData!$A$1:$D$5", CHART_SERIES_IN_COLUMNS
' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Excel file multiple sheets.xlsx")
<!--Create an instance of the class that exports Excel files --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Create a worksheet --><cfset ret = workbook.easy_addWorksheet("SourceData")>
...
<!-- Create a chart sheet --><cfset workbook.easy_addChart("Chart", "=SourceData!$A$1:$D$5",
Chart.CHART_SERIES_IN_COLUMNS)><!-- Export Excel file --><cfset ret = workbook.easy_WriteXLSXFile("C:\Samples\Excel file multiple sheets.xlsx")>
.NET:# Create an instance of the class that exports Excel files
workbook = ExcelDocument()
# Create an worksheet
workbook.easy_addWorksheet("SourceData")
...
# Add a chart sheet
workbook.easy_addChart("Chart", "=SourceData!$A$1:$D$5", Chart.SERIES_IN_COLUMNS)
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel file multiple sheets.xlsx")
Click here to see Continuous Code ListingJava:# Create an instance of the class that exports Excel files
workbook = gateway.jvm.ExcelDocument()
# Create an worksheet
workbook.easy_addWorksheet("SourceData")
...
# Add a chart sheet
workbook.easy_addChart("Chart", "=SourceData!$A$1:$D$5", gateway.jvm.Chart.SERIES_IN_COLUMNS)
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel file multiple sheets.xlsx")
Click here to see Continuous Code Listing
The screen shot provides an example of an Excel file that has a worksheet and a chart sheet.
Insert sheets into workbook
In addition to appending a sheet, a worksheet or a chart sheet can be inserted between other sheets. The below source code sample shows how to insert a worksheet after the first sheet.
// Create an instance of the class that creates Excel files, having two worksheets
ExcelDocument workbook = new ExcelDocument(2);
// Insert a worksheet
workbook.easy_insertWorksheet(1, "Inserted Sheet");
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel inserted sheet.xlsx");
' Create an instance of the class that creates Excel files, having two worksheetsDim workbook As New ExcelDocument(2)
' Insert a worksheet
workbook.easy_insertWorksheet(1, "Inserted Sheet")
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Excel inserted sheet.xlsx")
C++// Create an instance of the class that creates Excel files, having two worksheets
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook) ;
// Create two worksheets
workbook->easy_addWorksheet_2("First tab");
workbook->easy_addWorksheet_2("Second tab");
// Insert a worksheet
workbook->easy_insertWorksheet_2(1, "Inserted Sheet");
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Excel inserted sheet.xlsx");
C++.NET// Create an instance of the class that creates Excel files, having two worksheets
ExcelDocument ^workbook = gcnew ExcelDocument(2);
// Insert a worksheet
workbook->easy_insertWorksheet(1, "Inserted Sheet");
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Excel inserted sheet.xlsx");
// Create an instance of the class that creates Excel files, having two worksheets
ExcelDocument workbook = new ExcelDocument(2);
// Insert a worksheet
workbook.easy_insertWorksheet(1, "Inserted Sheet");
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel inserted sheet.xlsx");
.NET:// Create an instance of the class that creates Excel files, having two worksheets
$workbook = new COM("EasyXLS.ExcelDocument");
// Create two worksheets
$workbook->easy_addWorksheet_2("First tab");
$workbook->easy_addWorksheet_2("Second tab");
// Insert a worksheet
$workbook->easy_insertWorksheet_2(1, "Inserted Sheet");
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Excel inserted sheet.xlsx");
Java:// Create an instance of the class that creates Excel files, having two worksheets
$workbook = new java("EasyXLS.ExcelDocument");
// Create two sheets
$workbook->easy_addWorksheet("First tab");
$workbook->easy_addWorksheet("Second tab");
// Insert a worksheet
$workbook->easy_insertWorksheet(1, "Inserted Sheet");
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Excel inserted sheet.xlsx");
' Create an instance of the class that creates Excel files, having two worksheetsset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Create two worksheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
' Insert a worksheet
workbook.easy_insertWorksheet_2 1, "Inserted Sheet"' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Excel inserted sheet.xlsx")
' Create an instance of the class that creates Excel files, having two worksheetsSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Create two worksheets
workbook.easy_addWorksheet_2 ("First tab")
workbook.easy_addWorksheet_2 ("Second tab")
' Insert a worksheet
workbook.easy_insertWorksheet_2 1, "Inserted Sheet"' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Excel inserted sheet.xlsx")
' Create an instance of the class that creates Excel files, having two worksheetsset workbook = CreateObject("EasyXLS.ExcelDocument")
' Create two worksheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
' Insert a worksheet
workbook.easy_insertWorksheet_2 1, "Inserted Sheet"' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Excel inserted sheet.xlsx")
<!-- Create an instance of the class that creates Excel files, having two worksheets --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Create two worksheets --><cfset ret = workbook.easy_addWorksheet("First tab")><cfset ret = workbook.easy_addWorksheet("Second tab")><!-- Insert a worksheet --><cfset ret = workbook.easy_insertWorksheet(1, "Inserted Sheet")><!-- Export Excel file --><cfset ret = workbook.easy_WriteXLSXFile("C:\Samples\Excel inserted sheet.xlsx")>
.NET:# Create an instance of the class that creates Excel files, having two worksheets
workbook = ExcelDocument(2)
# Insert a worksheet
workbook.easy_insertWorksheet(1, "Inserted Sheet")
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel inserted sheet.xlsx")
Java:# Create an instance of the class that creates Excel files, having two worksheets
workbook = gateway.jvm.ExcelDocument(2)
# Insert a worksheet
workbook.easy_insertWorksheet(1, "Inserted Sheet")
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel inserted sheet.xlsx")