PHP Excel API错误:文件格式或文件扩展名无效

我在我的代码“文件格式或文件扩展名无效”上遇到错误。 我正在使用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(); ?> 

任何帮助将不胜感激谢谢

下面的代码工作在我身边..在你的代码中,你创build对象第一个“PHPExcel”,然后包括文件..我做了一些必要的修改。 检查链接: https : //github.com/PHPOffice/PHPExcel

 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';*/ require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; // Create new PHPExcel object $objPHPExcel = new PHPExcel(); 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();