Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error PHPExcel in Codeigniter

I'm trying to use PHPExcel with CodeIgniter.

but i got a error

Fatal error: Call to private IOFactory::__construct() from context 'CI_Loader' in C:\ms4w\Apache\htdocs\plantation\system\core\Loader.php on line 949

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");

    }

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

please to solve this case

i use codeigniter 2.0 and php excel 1.7.7

thanks for your attention

BR

Puja

like image 339
Puja Sury Avatar asked Jun 24 '12 18:06

Puja Sury


1 Answers

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

}
like image 123
Eswar Rajesh Pinapala Avatar answered Sep 25 '22 15:09

Eswar Rajesh Pinapala