Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
打开使用phpExcel生成的Excel文件时出错_Php_Codeigniter_Phpexcel - Fatal编程技术网

打开使用phpExcel生成的Excel文件时出错

打开使用phpExcel生成的Excel文件时出错,php,codeigniter,phpexcel,Php,Codeigniter,Phpexcel,我正在尝试使用Codeigniter中的phpExcel库生成Excel文件。 问题是,在下载文件时,它以未定义的格式显示字符 打开下载的文件时,会显示不同格式的消息,请参考图片 并在打开文件内容时作为 我的代码是: if ( ! defined('BASEPATH')) exit('No direct script access allowed'); $this->load->library('excel'); $sheet = new PHPExcel();

我正在尝试使用Codeigniter中的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应用程序/vnd.openxmlformats-officedocument.spreadsheetml.sheet和文件扩展名.xslx

参考-


它清理缓冲区并获得正确的输出。至少对我来说,它解决了这个问题。

您正在尝试创建哪个excel版本?2007?在文本编辑器中打开文件。查找文件中的前导/尾随空白字符、任何BOM表标题、任何明文PHP错误消息或任何html标记,然后找到脚本将这些信息回送到输出流的位置,在那里指定此mime类型,我使用PHPExcel库生成excel文件,而不是youyeah在链接中提到的API JASPER,mime tipe已经是application/vnd.ms-excel,它在配置中的mime下指定
ob_end_clean(); 
ob_start();