如何在Codeigniter中将xls转换为xlsx

时间:2018-07-11 09:30:46

标签: php codeigniter phpexcel

我正在使用PHPExcel下载xlsx格式的文件。我正在使用codeigniter框架。以前我正在下载xls格式。到时文件下载成功。如果我尝试以xlsx格式下载,则会出现如下图所示的错误。enter image description here

我的代码是:

$this->load->library('Excel');
$this->excel->setActiveSheetIndex(0);
$this->excel->getActiveSheet()->setTitle('Sales Data'); 
$filename='Salesdata.xlsx';
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel2007');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition:attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');

当我添加为xls格式时没有错误。当我添加为filename.xlsx时,它给出了错误。请采取任何解决方案。

1 个答案:

答案 0 :(得分:0)

您可以继续输入php Output bufferscodeigniter download helper 例如:-

$filename='Salesdata.xlsx';
ob_start();
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel2007');
//force user to download the Excel file without writing it to server's HD
$objWriter->save('php://output');
$this->load->helper('download');
$excelFileContents = ob_get_clean();
force_download($filename, $excelFileContents);