How to integrate codeigniter and PHPExcel?

user2526315 picture user2526315 · Jun 27, 2013 · Viewed 31.8k times · Source

always display an error message on my browser:

An Error Was Encountered
Non-existent class: IOFactory

all classes PHPExcel, i extract on library.

Here it is my controller code

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Report extends CI_Controller 
{
     public function __construct()
    {
        parent::__construct();
        $this->load->helper(array('form','url'));
    }

    public function index()
    {   

        $this->load->library('phpexcel');
        $this->load->library('PHPExcel/IOFactory.php');
        $objPHPexcel = PHPExcel_IOFactory::load('tandaterima.xlsx');
        $objWorksheet = $objPHPexcel->getActiveSheet();
        //Daftar barang (4item)
        $objWorksheet->getCell('B16')->setValue('UTP');
        $objWorksheet->getCell('B17')->setValue('Cross');
        $objWorksheet->getCell('B18')->setValue('');
        $objWorksheet->getCell('B19')->setValue('');
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPexcel, 'Excel5');
        $objWriter->save('write5.xls');
    }
}

please help me.

Answer

save_ole picture save_ole · Oct 27, 2013

Follow the instruction here https://github.com/EllisLab/CodeIgniter/wiki/PHPExcel

Please remember to remove the PHPExcel_ part in the class name in IOFactory.php. And change the construct function from private to public