Codeigniter中的错误PHPExcel [英] error PHPExcel in Codeigniter

查看:390
本文介绍了Codeigniter中的错误PHPExcel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用PHPExcel与CodeIgniter。

I'm trying to use PHPExcel with CodeIgniter.

但我收到了错误

致命错误:调用私有IOFactory :: __ construct()从上下文'CI_Loader'在C:\ms4w\Apache\htdocs\plantation\system\core\Loader.php在第949行

我将PHPExcel放在我的应用程式/程式库中

i put the PHPExcel in my apps/libraries



and this is my code controller

function excel()
    {

        $this->load->library('phpexcel');
        $this->load->library('PHPExcel/iofactory');

        $objPHPExcel = new PHPExcel();
        $objPHPExcel->getProperties()->setTitle("title")
        ->setDescription("description");

        // Assign cell values
        $objPHPExcel->setActiveSheetIndex(0);
        $objPHPExcel->getActiveSheet()->setCellValue('A1', 'cell value here');

        // Save it as an excel 2003 file
        $objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save("nameoffile.xls");

    }

http://codeigniter.com/wiki/PHPExcel/

请解决此问题

我使用codeigniter 2.0和php excel 1.7.7

i use codeigniter 2.0 and php excel 1.7.7

感谢您的关注

BR

Puja

推荐答案

可以设置你的函数,这也解决了你的无效字符问题,包括适当的标题,并做一个ob_end_clean();以清除任何输出缓冲。在你做save​​()之前做这个。

Here is how you could set up your function this also solves your invalid characters problem, include proper headers and do a ob_end_clean(); to clean any output buffering. Do this just before you do save() though.

 public function howToPhpExcel()
{
    $response = $this->_response;

    $this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender();

    $excel = new PHPExcel();
    $excel->setActiveSheetIndex(0);
    $worksheet = $excel->getActiveSheet();
    $worksheet->getCell('A1')->setValue('tet');
    $worksheet->getCell('B1')->setValue('tet');

    ob_end_clean();

    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename="Report.xlsx"');

    $objWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
    ob_end_clean();

    $objWriter->save('php://output');
    $excel->disconnectWorksheets();
    unset($excel);

}

这篇关于Codeigniter中的错误PHPExcel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆