Wednesday, December 26, 2012
How to Generate Excel file using PHP
I assume that everyone have the basic knowledge of HTML and PHP
There are many methods to generate Excel files using PHP. I am jotting down two methods:
1. Simple header method
On the top of the page where you are writing the code to generate the excel file, put the following code
header ("Content-type: application/vnd.ms-excel");
header ("Content-Disposition: attachment; filename=\"filename.xls" );
Apply CSS styles to your table so that it will automatically reflect in your excel sheet.
2. Using PHPExcel
The best solution to generate custom excel reports. You are able to add worksheets, images etc. You can rename the sheets. Output your spreadsheet object to different file formats like CSV, PDF etc.
Initially you may find it complex. But please don't stop. Work it out. Later it will really help you. To know more on PHPExcel and for downloading the package click here.