2014-12-08 78 views
0

我試圖使用生成phpExcel庫的的Excel文件中生成的Excel文件。 的問題是,在下載文件時,它顯示在undifined格式錯誤,同時打開使用phpExcel

字符當您打開下載的文件就說明這是一個不同的格式的信息,請參閱該PIC enter image description here

,並在打開文件內容

enter image description here

和我的代碼的東西是:

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'); 
+0

其擅長你要創建的版本? 2007年? – 2014-12-08 07:07:22

+0

1.7.9,2013-06-02 – 2014-12-08 07:10:37

+0

在文本編輯器中打開文件。查找前導/尾隨空白字符,任何BOM標題,任何明文PHP錯誤消息或文件中的任何html標記,然後查找腳本將哪些內容回顯到輸出流的位置 – 2014-12-08 09:16:25

回答

0

您正在創建Excel 2007文件嗎?如果是的話請嘗試使用mimetype application/vnd.openxmlformats-officedocument.spreadsheetml.sheet和文件擴展名.xslx

參考 - PHP Excel - The file you are trying to open .xls is in a different format than specified by the file extension

+0

指定此MIME類型的位置,並且我使用「 PHPExcel「庫生成excel文件而不是」API JASPER「,如鏈接中提到的你 – 2014-12-08 07:21:18

+0

http://stackoverflow.com/questions/974079/setting-mime-type-for-excel-document – 2014-12-08 07:24:23

+0

是啊,mime tipe已經是」 application/vnd.ms-excel「,它在config中的」mimes「下指定 – 2014-12-08 08:39:33