I am trying to use the PHPExcel class to export reports into excel file. What I really need to do is to go thru every row in the HTML table then place it into cells in an excel file.
I think PHPExcel has enough document to help me with created the excel file. But what I am not sure on how to do is to take an html table and break it so I can take every value and put it in an excel cell.
Thanks for your help
As simple as:
$objReader = PHPExcel_IOFactory::createReader('HTML');
$objPHPExcel = $objReader->load("myHtmlFile.html");
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save("myExcelFile.xlsx");
but you could use your same basic logic for building the HTML from your report data, and just modify it to set cell values in a PHPExcel object. If you have an MVC, then its only the View that you really need to change.
You loop through it with jQuery
$('td').each(function(){
//do stuff here...
});
If you want to mess with HTML but in PHP
, i recommend SimpleHTMLDom
If you like jquery, you'll love it.
Example code:
$html = str_get_html('<table id="mytable"><td>cell ??</td><td>cell 2</td></table>');
$html->find("#mytable td:first-child",0)->innertext = "cell 1!";
echo $html;
done.