User GuideFAQHow to export to Excel file in PHP and Classic ASP
How to export to Excel file in PHP and Classic ASP
EasyXLS™ library allows you to export data to an Excel file having one or multiple sheets. The data in cells can be formatted using predefined formats or user-defined formats.
EasyXLS can be successfully used inclusively to export large Excel files having big volume of data with fast exporting time.
EasyXLS permits you to export Excel files without Excel installed, without Interop or any other additional software installed.
Step 3: Run PHP/ASP code that exports to Excel file
The below example is a common code about how to export to Excel file in PHP and Classic ASP. After that, the best techniques about exporting data from any database like MySQL, SQL Server, Oracle or MS Access are shown. Also, more code samples indicate how to export data to XLSX, XLSM, XLS or XLSB file format.
.NET:// Create an instance of the class that exports Excel file, having one sheet
$workbook = new COM("EasyXLS.ExcelDocument");
// Create sheet
$workbook->easy_addWorksheet_2("Exported data");
// Get the table of the worksheet that will keep the data
$xlsTable = $workbook->easy_getSheetAt(0)->easy_getExcelTable();
// Add data to cellsfor ($row=0; $row<100; $row++)
{
for ($column=0; $column<5; $column++)
{
$xlsTable->easy_getCell($row+1,$column)->setValue("Data ".($row + 1).", ".($column + 1));
}
}
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\\Samples\\Export to Excel.xlsx");
// Dispose memory
$workbook->Dispose();
Java:// Create an instance of the class that exports Excel file, having one sheet
$workbook = new java("EasyXLS.ExcelDocument");
// Create sheet
$workbook->easy_addWorksheet("Exported data");
// Get the table of the worksheet that will keep the data
$xlsTable = $workbook->easy_getSheetAt(0)->easy_getExcelTable();
// Add data to cellsfor ($row=0; $row<100; $row++)
{
for ($column=0; $column<5; $column++)
{
$xlsTable->easy_getCell($row+1,$column)->setValue("Data ".($row + 1).", ".($column + 1));
}
}
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\\Samples\\Export to Excel.xlsx");
// Dispose memory
$workbook->Dispose();
<%@ Language=VBScript%><%' Create an instance of the class that exports Excel file, having one sheetset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Create sheet
workbook.easy_addWorksheet_2("Exported data")
' Get the table of the worksheet that will keep the dataset xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
' Add data to cellsfor row = 0 to 99
for column = 0 to 4
xlsFirstTable.easy_getCell(row,column).setValue("Data " & (row + 1) & ", " & (column + 1))
next
next' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Export to Excel.xlsx")
' Dispose memory
workbook.Dispose
%>
1. Export data from database to Excel in PHP and Classic ASP
EasyXLS allows exporting data from MySQL, Oracle, MS SQL Server, MS Access or any other database to Excel file.
2. Export data to XLSX file in PHP and Classic ASP
EasyXLS allows exporting data to XLSX file format. Similarly, as shown in the above code sample, you can export data to XLSX file using ExcelDocument.easy_WriteXLSXFile method.
3. Export data to XLSB file in PHP and Classic ASP
EasyXLS allows exporting data to XLSB file format. Similarly, as shown in the above code sample, you can export data to XLSB file using ExcelDocument.easy_WriteXLSBFile method.
4. Export data to XLSM file in PHP and Classic ASP
EasyXLS allows exporting data to XLSM file format. The first step is to create an XLSM or XLTM file in Microsoft Excel that has the macro code defined. The Excel file can be empty or already filled with sheets and some data like report header. This will be the Excel template file that will be loaded using ExcelDocument.easy_LoadXLSXFile method. Now, the data can be added to the Excel file similarly, as shown in the above code sample. When the Excel file is completely filled, you can export data to XLSM file using ExcelDocument.easy_WriteXLSXFile method, but the exported Excel file must have XLSM file extension.
EasyXLS allows exporting data to XLS file format. Similarly, as shown in the above code sample, you can export data to XLS file using ExcelDocument.easy_WriteXLSFile method.