![](/img/trans.png)
[英]Error while opening generated excel file in php codeigniter using phpExcel
[英]Error while opening an Excel file that generated using phpExcel
我試圖使用生成庫phpExcel在笨的Excel文件。 問題是下載文件時,它以未定義的格式顯示字符
打開下載的文件時,它顯示的是另一種格式的消息,請參閱圖片
並且在打開文件內容時
我的代碼是:
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$this->load->library('excel');
$sheet = new PHPExcel();
$objWorkSheet = $sheet->createSheet();
$sheet->getProperties()->setTitle('JDI Problem Improvement Strip')->setDescription('JDI Problem Improvement Strip');
$sheet->setActiveSheetIndex(0);
$sheet_writer = PHPExcel_IOFactory::createWriter($sheet, 'Excel5');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="01simple.xls"');
header('Cache-Control: max-age=0');
$sheet_writer->save('php://output');
您正在創建Excel 2007文件嗎? 如果是這樣,請嘗試使用mimetype application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
和文件擴展名.xslx
ob_end_clean();
ob_start();
它清除緩沖區並獲得正確的輸出。 至少對我來說,它可以解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.