dongya6395 2017-06-23 03:38
浏览 242

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

I am experiencing an error on my code "File Format or File Extension not valid". I am using the PHP Excel class

This is my code:

<?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();
?>

Any help will be greatly appreciated Thanks

  • 写回答

2条回答 默认 最新

  • duanlei2150 2017-06-23 05:28
    关注

    Below code works from my side.. In your code you create object 1st "PHPExcel" then include the file.. i do some needful changes. check link : 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();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn