【发布时间】:2017-06-23 03:38:00
【问题描述】:
我的代码“文件格式或文件扩展名无效”出现错误。我正在使用 PHP Excel 类
这是我的代码:
<?php
session_start();
ini_set('max_execution_time', 1200); //20 mins
ob_start();
/** Error reporting */
error_reporting(E_ALL);
/** Include path **/
ini_set('include_path', ini_get('include_path').';../classes/');
/** PHPExcel */
include '../classes/PHPExcel.php';
/** PHPExcel_Writer_Excel2007 */
include '../classes/PHPExcel/Writer/Excel2007.php';
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
require_once '../classes/PHPExcel.php';
ini_set('memory_limit', '-1');
//Untested... pulled from the manual as the way to write with PHPExcel
//Save Excel 2007 file
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_end_clean();
//We'll be outputting an excel file
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
//It will be called file.xls
header("Content-Disposition: attachment;filename=\"Past_Due_Report.xls\"");
header("Cache-Control: max-age=0");
$objWriter->save('php://output');
exit();
?>
任何帮助将不胜感激 谢谢
【问题讨论】:
-
而不是打开文件保存并在文本编辑器中查看
-
我认为当我们使用 PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007') 即“Excel2007”时,文件扩展名将是 .xlsx... 所以你必须更改“Past_Due_Report. xls" 到 "Past_Due_Report.xlsx"
-
@pAsh 我已经改成 .xlsx,同样的错误
-
删除 -> Past_Due_Report.xlsx 前后的“\”
-
@pAsh 已删除 '\' 仍然出现相同的错误