// Load the table view into a variable
$html = $this->load->view('table_view', $data, true);
// Put the html into a temporary file
$tmpfile = time().'.html';
file_put_contents($tmpfile, $html);
// Read the contents of the file into PHPExcel Reader class
$reader = new PHPExcel_Reader_HTML;
$content = $reader->load($tmpfile);
// Pass to writer and output as needed
$objWriter = PHPExcel_IOFactory::createWriter($content, 'Excel2007');
$objWriter->save('excelfile.xlsx');
// Delete temporary file
unlink($tmpfile);
IF error happend refer below,
ref links: http://stackoverflow.com/questions/23562380/phpexcel-create-spreadsheet-from-html-table
http://stackoverflow.com/questions/25292596/phpexcel-reader-html-produces-empty-file
Edit line 427 of Classes/PHPExcel/Reader/HTML.php
, which reads
$loaded = $dom->loadHTMLFile($pFilename, PHPExcel_Settings::getLibXmlLoaderOptions());
and change it to
$loaded = $dom->loadHTMLFile($pFilename);
No comments:
Post a Comment