Search code examples
phpjquerycssexport-to-excel

Export HTML to EXCEL with PHP & jQuery



I would like to export an HTML table to a MS Excel document (and PDF ideally) as it is displayed on the HTML/CSS page. I read a lot of pages and topics about it (on stack mainly) but everyone seemed to be talking about exporting the table, and not formatting the final excel file.

I think it should work like this:

  1. click on export button: call to jQuery
  2. jQuery creates a pure HTML document from the HTML/CSS of the table
  3. jQuery calls a PHP function/class (http://phpexcel.codeplex.com maybe) to generate the EXCEL file from the HTML code reformatted
  4. With the headers sent by PHP, the browser asks the user to save/open the excel generated file

Would this work? If so do you know any jQuery plugins and PHP classes/functions to do so? If not, what is your ideas about it?
EDIT: Thanks to Matt, I came to the idea of using an XLS file template, is it possible? It will avoid me all the formatting as it would be done in the template file. Is it possible?


Cheers,
Nicolas.


Solution

  • I finally choose to redo all the formatting with PHPexcel. The drawback is that if I change something in the HTML rendered I have to do the same in the PHPexcel helper I've created and vice versa.


    Thank you for your suggestion everyone.
    Nicolas.