EasyXLS™ library allows you to export data to XML Spreadsheet Excel file format. The data in cells can be formatted using predefined formats or user-defined formats.
An XML Spreadsheet file is an XML file in a format designed by Microsoft specifically for Excel worksheets.
For more technical information about XML spreadsheets you can check XML Spreadsheet Reference web page.
The entire workbook can be saved as an XML Spreadsheet file (with some limitation applied to visual objects such as images, charts or drawings) and after that it can be processed as any other XML file or you can open it with Microsoft Excel.
// Create an instance of the class that exports Excel file, having multiple sheets
ExcelDocument workbook = new ExcelDocument(2);
// Set the sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab");
workbook.easy_getSheetAt(1).setSheetName("Second tab");
// Get the table of the first worksheet that will keep the data
ExcelTable xlsFirstTable =
((ExcelWorksheet)workbook.easy_getSheetAt(0)).easy_getExcelTable();
// Add data to headerfor (int column=0; column<5; column++)
{
xlsFirstTable.easy_getCell(0,column).setValue("Column " + (column + 1));
xlsFirstTable.easy_getCell(0,column).setDataType(DataType.STRING);
}
// Add data to cellsfor (int row=0; row<100; row++)
{
for (int column=0; column<5; column++)
{
xlsFirstTable.easy_getCell(row+1,column).setValue(
"Data " + (row + 1) + ", " + (column + 1));
xlsFirstTable.easy_getCell(row+1,column).setDataType(DataType.STRING);
}
}
// Apply a predefined formatting style on a range of cells
xlsFirstTable.easy_setRangeAutoFormat("A1:E101",
new ExcelAutoFormat(Styles.AUTOFORMAT_EASYXLS1));
// Export XML Spreadsheet Excel file
workbook.easy_WriteXMLFile("C:\\Samples\\Export to XML Spreadsheet.xml");
' Create an instance of the class that exports Excel file, having multiple sheetsDim workbook As New ExcelDocument(2)
' Set the sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab")
workbook.easy_getSheetAt(1).setSheetName("Second tab")
' Get the table of the first worksheet that will keep the dataDim xlsFirstTab As ExcelWorksheet = workbook.easy_getSheetAt(0)
Dim xlsFirstTable = xlsFirstTab.easy_getExcelTable()
' Add data to headerFor column As Integer = 0 To 4
xlsFirstTable.easy_getCell(0, column).setValue("Column " & (column + 1))
xlsFirstTable.easy_getCell(0, column).setDataType(DataType.STRING)
Next' Add data to cellsFor row As Integer = 0 To 99
For column As Integer = 0 To 4
xlsFirstTable.easy_getCell(row + 1, column).setValue("Data " & _
(row + 1) & ", " & (column + 1))
xlsFirstTable.easy_getCell(row + 1, column).setDataType(DataType.STRING)
NextNext' Apply a predefined formatting style on a range of cells
xlsFirstTable.easy_setRangeAutoFormat("A1:E101", _
New ExcelAutoFormat(Styles.AUTOFORMAT_EASYXLS1))
' Export XML Spreadsheet Excel file
workbook.easy_WriteXMLFile("C:\Samples\Export to XML Spreadsheet.xml")
C++// Create an instance of the class that exports Excel file
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook);
// Create the worksheets
workbook->easy_addWorksheet_2("First tab");
workbook->easy_addWorksheet_2("Second tab");
// Get the table of the first worksheet that will keep the data
EasyXLS::IExcelWorksheetPtr xlsFirstTab =
(EasyXLS::IExcelWorksheetPtr)workbook->easy_getSheetAt(0);
EasyXLS::IExcelTablePtr xlsFirstTable = xlsFirstTab->easy_getExcelTable();
// Add data to headerchar* cellValue = (char*)malloc(11*sizeof(char));
char* columnNumber = (char*)malloc(sizeof(char));
for (int column=0; column<5; column++)
{
strcpy(cellValue, "Column ");
_itoa(column+ 1, columnNumber, 10);
xlsFirstTable->easy_getCell(0,column)->setValue(strcat(cellValue, columnNumber));
xlsFirstTable->easy_getCell(0,column)->setDataType(DATATYPE_STRING);
}
// Add data to cellschar* rowNumber = (char*)malloc(sizeof(char));
for (int row=0; row<100; row++)
{
for (int column=0; column<5; column++)
{
strcpy(cellValue, "Data ");
_itoa(column+ 1, columnNumber, 10);
_itoa(row + 1, rowNumber, 10);
strcat(cellValue, rowNumber);
strcat(cellValue, ", ");
strcat(cellValue, columnNumber);
xlsFirstTable->easy_getCell(row+1,column)->setValue(cellValue);
xlsFirstTable->easy_getCell(row+1,column)->setDataType(DATATYPE_STRING);
}
}
// Create an instance of the class used to format the cells
EasyXLS::IExcelAutoFormatPtr xlsAutoFormat;
CoCreateInstance(__uuidof(EasyXLS::ExcelAutoFormat), NULL, CLSCTX_ALL,
__uuidof(EasyXLS::IExcelAutoFormat), (void**) &xlsAutoFormat);
xlsAutoFormat->InitAs(AUTOFORMAT_EASYXLS1);
// Apply a predefined formatting style on a range of cells
xlsFirstTable->easy_setRangeAutoFormat_2("A1:E101",
_variant_t((IDispatch*)xlsAutoFormat,true));
// Export XML Spreadsheet Excel file
workbook->easy_WriteXMLFile_2("C:\\Samples\\Export to XML Spreadsheet.xml");
Click here to see Continuous Code ListingC++.NET// Create an instance of the class that exports Excel file, having multiple sheets
ExcelDocument ^workbook = gcnew ExcelDocument(2);
// Set the sheet names
workbook->easy_getSheetAt(0)->setSheetName("First tab");
workbook->easy_getSheetAt(1)->setSheetName("Second tab");
// Get the table of the first worksheet that will keep the data
ExcelWorksheet ^xlsFirstTab =
safe_cast<ExcelWorksheet^>(workbook->easy_getSheetAt(0));
ExcelTable xlsFirstTable = xlsFirstTab->easy_getExcelTable();
// Add data to headerfor (int column=0; column<5; column++)
{
xlsFirstTable->easy_getCell(0,column)->setValue(
String::Concat("Column ",(column + 1).ToString()));
xlsFirstTable->easy_getCell(0,column)->setDataType(DataType::STRING);
}
// Add data to cellsfor (int row=0; row<100; row++)
{
for (int column=0; column<5; column++)
{
xlsFirstTable->easy_getCell(row+1,column)->setValue(String::Concat(
"Data ", (row + 1).ToString(), ", ", (column + 1).ToString()));
xlsFirstTable->easy_getCell(row+1,column)->setDataType(DataType::STRING);
}
}
// Apply a predefined formatting style on a range of cells
xlsFirstTable->easy_setRangeAutoFormat("A1:E101",
gcnew ExcelAutoFormat(Styles::AUTOFORMAT_EASYXLS1));
// Export XML Spreadsheet Excel file
workbook->easy_WriteXMLFile("C:\\Samples\\Export to XML Spreadsheet.xml");
Click here to see Continuous Code Listing
// Create an instance of the class that exports Excel file, having multiple sheets
ExcelDocument workbook = new ExcelDocument(2);
// Set the sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab");
workbook.easy_getSheetAt(1).setSheetName("Second tab");
// Get the table of the first worksheet that will keep the data
ExcelTable xlsFirstTable =
((ExcelWorksheet)workbook.easy_getSheetAt(0)).easy_getExcelTable();
// Add data to headerfor (int column=0; column<5; column++)
{
xlsFirstTable.easy_getCell(0,column).setValue("Column " + (column + 1));
xlsFirstTable.easy_getCell(0,column).setDataType(DataType.STRING);
}
// Add data to cellsfor (int row=0; row<100; row++)
{
for (int column=0; column<5; column++)
{
xlsFirstTable.easy_getCell(row+1,column).setValue(
"Data " + (row + 1) + ", " + (column + 1));
xlsFirstTable.easy_getCell(row+1,column).setDataType(DataType.STRING);
}
}
// Apply a predefined formatting style on a range of cells
xlsFirstTable.easy_setRangeAutoFormat("A1:E101",
new ExcelAutoFormat(Styles.AUTOFORMAT_EASYXLS1));
// Export XML Spreadsheet Excel file
workbook.easy_WriteXMLFile("C:\\Samples\\Export to XML Spreadsheet.xml");
.NET:// Create an instance of the class that exports Excel file
$workbook = new COM("EasyXLS.ExcelDocument");
// Create the worksheets
$workbook->easy_addWorksheet_2("First tab");
$workbook->easy_addWorksheet_2("Second tab");
// Get the table of the first worksheet that will keep the data
$xlsFirstTable = $workbook->easy_getSheetAt(0)->easy_getExcelTable();
// Add data to headerfor ($column=0; $column<5; $column++)
{
$xlsFirstTable->easy_getCell(0,$column)->setValue("Column " . ($column + 1));
$xlsFirstTable->easy_getCell(0,$column)->setDataType($DATATYPE_STRING);
}
// Add data to cellsfor ($row=0; $row<100; $row++)
{
for ($column=0; $column<5; $column++)
{
$xlsFirstTable->easy_getCell($row+1,$column)->setValue(
"Data ".($row + 1).", ".($column + 1));
$xlsFirstTable->easy_getCell($row+1,$column)->setDataType($DATATYPE_STRING);
}
}
// Create an instance of the class used to format the cells
$xlsAutoFormat = new COM("EasyXLS.ExcelAutoFormat");
$xlsAutoFormat->InitAs($AUTOFORMAT_EASYXLS1);
// Apply a predefined formatting style on a range of cells
$xlsFirstTable->easy_setRangeAutoFormat_2("A1:E101", $xlsAutoFormat);
// Export XML Spreadsheet Excel file
$workbook->easy_WriteXMLFile_2("C:\Samples\Export to XML Spreadsheet.xml");
Click here to see Continuous Code ListingJava:// Create an instance of the class that exports Excel files
$workbook = new java("EasyXLS.ExcelDocument");
// Create two worksheets
$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();
// Add data in cells for report headerfor ($column=0; $column<5; $column++)
{
$xlsFirstTable->easy_getCell(0,$column)->setValue("Column " . ($column + 1));
$xlsFirstTable->easy_getCell(0,$column)->setDataType($DATATYPE_STRING);
}
// Add data in cells for report valuesfor ($row=0; $row<100; $row++)
{
for ($column=0; $column<5; $column++)
{
$xlsFirstTable->easy_getCell($row+1,$column)->setValue(
"Data ".($row + 1).", ".($column + 1));
$xlsFirstTable->easy_getCell($row+1,$column)->setDataType($DATATYPE_STRING);
}
}
// Create an instance of the class used to format the cells
$xlsAutoFormat = new java("EasyXLS.ExcelAutoFormat");
$xlsAutoFormat->InitAs($AUTOFORMAT_EASYXLS1);
// Apply the predefined format to the cells
$xlsFirstTable->easy_setRangeAutoFormat("A1:E101", $xlsAutoFormat);
// Export XML Spreadsheet file
$workbook->easy_WriteXMLFile("C:\Samples\Tutorial32 - export XML spreadsheet file.xml");
Click here to see Continuous Code Listing
' Create an instance of the class that exports Excel fileSet workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Create the worksheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
' Get the table of the first worksheet that will keep the dataSet xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
' Add data to headerfor column = 0 to 4
xlsFirstTable.easy_getCell(0,column).setValue("Column " & (column + 1))
xlsFirstTable.easy_getCell(0,column).setDataType(DATATYPE_STRING)
next' Add data to cellsfor row = 0 to 99
for column = 0 to 4
xlsFirstTable.easy_getCell(row+1,column).setValue( _
"Data " & (row + 1) & ", " & (column + 1))
xlsFirstTable.easy_getCell(row+1,column).setDataType(DATATYPE_STRING)
nextnext' Create an instance of the class used to format the cellsDim xlsAutoFormat
Set xlsAutoFormat = Server.CreateObject("EasyXLS.ExcelAutoFormat")
xlsAutoFormat.InitAs(AUTOFORMAT_EASYXLS1)
' Apply a predefined formatting style on a range of cells
xlsFirstTable.easy_setRangeAutoFormat_2 "A1:E101", xlsAutoFormat
' Export XML Spreadsheet Excel file
workbook.easy_WriteXMLFile_2("C:\Samples\Export to XML Spreadsheet.xml")
' Create an instance of the class that exports Excel fileSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Create the worksheets
workbook.easy_addWorksheet_2 ("First tab")
workbook.easy_addWorksheet_2 ("Second tab")
' Get the table of the first worksheet that will keep the dataSet xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
' Add data to headerFor Column = 0 To 4
xlsFirstTable.easy_getCell(0, Column).setValue ("Column " & (Column + 1))
xlsFirstTable.easy_getCell(0, Column).setDataType (DataType.DATATYPE_STRING)
Next' Add data to cellsFor row = 0 To 99
For Column = 0 To 4
xlsFirstTable.easy_getCell(row + 1, Column).setValue ( _
"Data " & (row + 1) & ", " & (Column + 1))
xlsFirstTable.easy_getCell(row + 1, Column).setDataType ( _
DataType.DATATYPE_STRING)
NextNext' Create an instance of the class used to format the cellsDim xlsAutoFormat
Set xlsAutoFormat = CreateObject("EasyXLS.ExcelAutoFormat")
xlsAutoFormat.InitAs (Styles.AUTOFORMAT_EASYXLS1)
' Apply a predefined formatting style on a range of cells
xlsFirstTable.easy_setRangeAutoFormat_2 "A1:E101", xlsAutoFormat
' Export XML Spreadsheet Excel file
workbook.easy_WriteXMLFile_2 ("C:\Samples\Export to XML Spreadsheet.xml")
' Create an instance of the class that exports Excel fileSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Create the worksheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
' Get the table of the first worksheet that will keep the dataSet xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
' Add data to headerFor Column = 0 To 4
xlsFirstTable.easy_getCell(0,column).setValue("Column " & (Column + 1))
xlsFirstTable.easy_getCell(0,column).setDataType(DATATYPE_STRING)
Next' Add data to cellsFor row = 0 To 99
For column = 0 To 4
xlsFirstTable.easy_getCell(row+1,column).setValue( _
"Data " & (row + 1) & ", " & (column + 1))
xlsFirstTable.easy_getCell(row+1,column).setDataType(DATATYPE_STRING)
NextNext' Create an instance of the class used to format the cellsDim xlsAutoFormat
Set xlsAutoFormat = CreateObject("EasyXLS.ExcelAutoFormat")
xlsAutoFormat.InitAs(AUTOFORMAT_EASYXLS1)
' Apply a predefined formatting style on a range of cells
xlsFirstTable.easy_setRangeAutoFormat_2 "A1:E101", xlsAutoFormat
' Export XML Spreadsheet Excel file
workbook.easy_WriteXMLFile_2 ("C:\Samples\Export to XML Spreadsheet.xml")
<!-- Create an instance of the class that exports Excel file --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Create the worksheets --><cfset ret = workbook.easy_addWorksheet("First tab")><cfset ret = workbook.easy_addWorksheet("Second tab")><!-- Get the table of the first worksheet that will keep the data --><cfset xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()><!-- Add data to header --><cfloop from="0"to="4"index="column"><cfset xlsFirstTable.easy_getCell(0, evaluate(column)).setValue(
"Column " & evaluate(column + 1))><cfset xlsFirstTable.easy_getCell(0, evaluate(column)).setDataType(
DataType.STRING)></cfloop><!-- Add data to cells --><cfloop from="0"to="99"index="row"><cfloop from="0"to="4"index="column"><cfset xlsFirstTable.easy_getCell(
evaluate(row + 1),evaluate(column)).setValue(
"Data " & evaluate(row + 1) & ", " & evaluate(column + 1))><cfset xlsFirstTable.easy_getCell(
evaluate(row + 1),evaluate(column)).setDataType(
DataType.STRING)></cfloop>
</cfloop><!-- Create an instance of the class used to format the cells --><cfobject type="java"class="EasyXLS.ExcelAutoFormat"name="xlsAutoFormat"action="CREATE"><cfset xlsAutoFormat.InitAs(Styles.AUTOFORMAT_EASYXLS1)><!-- Apply a predefined formatting style on a range of cells --><cfset xlsFirstTable.easy_setRangeAutoFormat("A1:E101", xlsAutoFormat)><!-- Export XML Spreadsheet Excel file --><cfset ret = workbook.easy_WriteXMLFile("C:\Samples\Export to XML Spreadsheet.xml")>
.NET:# Create an instance of the class that exports Excel files, having two sheets
workbook = ExcelDocument(2)
# Set the sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab")
workbook.easy_getSheetAt(1).setSheetName("Second tab")
# Get the table of data for the first worksheet
xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
# Add data in cells for report headerfor column in range(5):
xlsFirstTable.easy_getCell(0,column).setValue("Column " + str(column + 1))
xlsFirstTable.easy_getCell(0,column).setDataType(DataType.STRING)
# Add data in cells for report valuesfor row in range(100):
for column in range(5):
xlsFirstTable.easy_getCell(row+1,column).setValue("Data " + str(row + 1) + ", " + str(column + 1))
xlsFirstTable.easy_getCell(row+1,column).setDataType(DataType.STRING)
# Apply a predefined format to the cells
xlsFirstTable.easy_setRangeAutoFormat("A1:E101", ExcelAutoFormat(Styles.AUTOFORMAT_EASYXLS1))
# Export XML Spreadsheet file
workbook.easy_WriteXMLFile("C:\\Samples\\Tutorial32 - export XML spreadsheet file.xml")
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)
# Set the sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab")
workbook.easy_getSheetAt(1).setSheetName("Second tab")
# Get the table of data for the first worksheet
xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
# Add data in cells for report headerfor column in range(5):
xlsFirstTable.easy_getCell(0,column).setValue("Column " + str(column + 1))
xlsFirstTable.easy_getCell(0,column).setDataType(gateway.jvm.DataType.STRING)
# Add data in cells for report valuesfor row in range(100):
for column in range(5):
xlsFirstTable.easy_getCell(row+1,column).setValue("Data " + str(row + 1) + ", " + str(column + 1))
xlsFirstTable.easy_getCell(row+1,column).setDataType(gateway.jvm.DataType.STRING)
# Apply a predefined format to the cells
xlsFirstTable.easy_setRangeAutoFormat("A1:E101",
gateway.jvm.ExcelAutoFormat(gateway.jvm.Styles.AUTOFORMAT_EASYXLS1))
# Export XML Spreadsheet file
workbook.easy_WriteXMLFile("C:\\Samples\\Tutorial32 - export XML spreadsheet file.xml")
Click here to see Continuous Code Listing
The screen shot below represents the exported data to XML Spreadsheet file generated by the code sample above. The file has two worksheets (First Tab and Second Tab). The values and the data type of the cells from the first worksheet are set.
Formatting cells
EasyXLS™ enables you to format cells, rows and columns in order to set the fonts and colors.