Search code examples
phpexcelphp4spreadsheet

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


Solution

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