PHP easily generate an Excel File

Here’s the code:

header('Pragma: public');
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");   
header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: pre-check=0, post-check=0, max-age=0');
header("Pragma: no-cache");
header("Expires: 0");
header('Content-Transfer-Encoding: none');
header('Content-Type: application/;');
header("Content-type: application/x-msexcel");
header('Content-Disposition: attachment; filename="Excel.html"');
echo '<table>'; // etc.. a normal basic HTML table. 

Note, send the file name with a .html extension not a .xls or anything, confuses OpenOffice and sometimes excel. 

Leave a Reply

Your email address will not be published. Required fields are marked *