PHPExcel导出HTML字符串正在导出整个HTML页面

时间:2016-04-15 15:31:41

标签: php phpexcel

我在html页面上有一个表,我需要导出。我在这里搜索了其他例子,但没有什么对我有用。

这就是我所拥有的。

$filename = "DownloadReport";
//$table = dbGrid($q);

$table = "<div><table><tbody><tr><td>cars</td><td>cars</td><td>cars</td></tr></tbody></table></div>";

$tmpfile = tempnam(sys_get_temp_dir(), 'html');
file_put_contents($tmpfile, $table);


$excelHTMLReader = PHPExcel_IOFactory::createReader('HTML');
$objPHPExcel = $excelHTMLReader->load($tmpfile);
$objPHPExcel->getActiveSheet()->setTitle('anynameyouwant');

unlink($tmpfile);

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $filename . '-' . date("y.m.d") . '.xlsx"');
header('Cache-Control: max-age=0');

$writer = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$writer->save('php://output');
exit;

正确下载文件。但由于某种原因,它保存了整个html页面,缺少javascript和css文件。我只需要导出表字符串。我有一个dbGrid函数来创建我的表但是为了测试我有一个简单的表字符串。

如何只导出该表字符串,而不是整个html页面。

0 个答案:

没有答案