phpExcel in codeigniter


phpExcel in codeigniter

我尝试获取excel文件并将其覆盖为pdf。我成功了,但我没有看到数据,并告诉我不能将数据加载到pdf

这是我的代码:

        //load our new PHPExcel library
    $this->load->library('excel');
    $inputFileName = 'nameoffile';
    $excel2 = PHPExcel_IOFactory::createReader('Excel5');
    $excel2 = $excel2->load($inputFileName.'.xls');
    $excel2->setActiveSheetIndex(0);
    header('Pragma: public');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Content-Type: application/force-download');
    header('Content-Type: application/octet-stream');
    header('Content-Type: application/download');
    header("Content-Disposition: attachment;filename=from-template.pdf");
    header('Content-Transfer-Encoding: binary');
    $objWriter = PHPExcel_IOFactory::createWriter($excel2, 'pdf');
    $objWriter->save('php://output');

也许这是因为没有PHPExcel_Writer_xls,但如果您试图编写BIFF格式的.xls文件,则应该使用PHPExcel_Writer_Excel5

但是,您的代码显示您正在尝试创建一个PDF编写器。文件名是"区分大小写"的,因此要创建PDF Writer,您需要用大写指定它

$objWriter = PHPExcel_IOFactory::createWriter($excel2, 'PDF');

编辑

不要为您的阅读器使用与电子表格相同的变量

$reader = PHPExcel_IOFactory::createReader('Excel5');
$spreadsheet = $reader->load($inputFileName . '.xls');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment;filename="from-template.pdf"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0
$writer = PHPExcel_IOFactory::createWriter($spreadsheet, 'PDF');
$writer->save('php://output');
die();

这段代码非常有效。所以我是如何掩饰的。

        //load our new PHPExcel library
    $this->load->library('excel');
    $inputFileName = 'nameoffile';
    $reader = PHPExcel_IOFactory::createReader('Excel5');
    $spreadsheet = $reader->load($inputFileName . '.xls');
    header('Content-Type: application/xls');
    header('Content-Disposition: attachment;filename="from-template.xls"');
    header('Cache-Control: max-age=0');

//如果你正在为IE 9服务,那么可能需要以下内容标头("缓存控制:最大年龄=1");

//如果您通过SSL向IE提供服务,则可能需要以下内容header("费用:1997年7月26日星期一格林尼治标准时间05:00:00");//过去的日期header('上次修改:'.gmdate('D,D M Y H:i:s')。'GMT');//始终修改标头("缓存控制:缓存,必须重新验证");//HTTP://1.1header('Pagma:public');//HTTP://1.0

    $writer = PHPExcel_IOFactory::createWriter($spreadsheet, 'Excel5');
    $writer->save('php://output');
    die();