PHPExcel:输出时出现CodeIgniter错误

时间:2015-07-21 10:28:36

标签: php codeigniter phpexcel

我有这个控制器,它将我的数据从数据库呈现到PHPExcel库。

  

https://arjunphp.com/how-to-use-phpexcel-with-codeigniter/

这是我的控制者:

  $scope.servicesAdded = [{stepNumber:-1,otherData:""},
                          {stepNumber:-2,otherData:""},
                          {stepNumber:1,otherData:""}];

确实下载了excel文件。唯一的问题是数据混乱,而且都是错误的。

Screenshot of downloaded excel file

为什么会这样?我的控制器有问题吗?

请提供解决方案......

1 个答案:

答案 0 :(得分:2)

添加 ob_end_clean(); 后 $ objWriter = PHPExcel_IOFactory :: createWriter($ this-> excel,' Excel5');

最终代码是

$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
ob_end_clean();
$objWriter->save('php://output');