2014-12-08 46 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