Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Turn HTML table into spread sheet?

I am generating an HTML table full of data. They need it to be an editable spreadsheet though that they can save and edit.

I currently have it exactly as they want but as an HTML table, is there anyway I can convert this to an excel spread sheet that they can download?

Thanks!!

like image 631
JD Isaacks Avatar asked Oct 15 '09 16:10

JD Isaacks


2 Answers

Here's what I use, hasn't failed me yet:

 header('Cache-Control: no-store, no-cache, must-revalidate');     // HTTP/1.1
 header('Cache-Control: pre-check=0, post-check=0, max-age=0');    // HTTP/1.1
 header ("Pragma: no-cache");
 header("Expires: 0");
 header('Content-Transfer-Encoding: none');
 header('Content-Type: application/vnd.ms-excel;');                 // This should work for IE & Opera
 header("Content-type: application/x-msexcel");                     // This should work for the rest
 header('Content-Disposition: attachment; filename="'.basename('yourFilenameHere.xls').'"');

'yourFilenameHere.xls' should obviously be changed :)

like image 71
Steven Mercatante Avatar answered Nov 02 '22 11:11

Steven Mercatante


You could use Spreadsheet_Excel_Writer PEAR package to achive a downloadable file as output.

like image 36
erenon Avatar answered Nov 02 '22 09:11

erenon