我有一个从数据库中获取数据并在<div id="#id1"><p> </p></div>
函数中生成HTML的函数,我回显它并轻松地在视图文件中显示。但是,现在我想使用相同的函数导出到controller
。我试过这样做,但没有出口。逻辑上它应该发生。以下是代码:
Excel
public function export2($html)
{
$filename ="excelreport.xls";
header('Content-type: application/ms-excel');
header('Content-Disposition: attachment; filename='.$filename);
echo $html;
}
包含HTML表格。从函数中调用函数$html
,该函数获取数据并创建HTML内容。
答案 0 :(得分:0)
您无法直接将数据从html导出到Excel。
您需要按照以下某个库来执行此操作。
https://phpexcel.codeplex.com/
https://github.com/elidickinson/php-export-data
尝试示例代码,让我知道您是否需要任何帮助。