How to export to Excel file in PHP and ASP classic
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.
Concept in action:
The below example is a common code about how to export to Excel file in PHP and ASP classic. 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.
<?php// Create an instance of the class that exports Excel file, having one sheet
$workbook = new COM("EasyXLS.ExcelDocument");
// Create sheet
// 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
<%@ Language=VBScript%><%' Create an instance of the class that exports Excel file, having one sheetset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Create sheet
' 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' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Export to Excel.xlsx")
' Dispose memory
1. Export data from database to Excel in PHP and ASP classic
EasyXLS allows exporting data from MySQL, Oracle, MS SQL Server, MS Access or any other database to Excel file.
4. Export data to XLSM file in PHP and ASP classic
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.