PHP: Turn HTML table into spread sheet?

2.3k Views Asked by At

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!!

3

There are 3 best solutions below

4
On BEST ANSWER

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 :)

0
On

Output the same data as Comma Separated Values (CSV). Most spreadsheet applications will recognize this.

1
On

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