0

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.

user2046410
  • 117
  • 4
  • 15
user2526315
  • 1
  • 1
  • 1
  • 1
  • Did you follow step #1 of the instructions from https://github.com/EllisLab/CodeIgniter/wiki/PHPExcel? And shouldn't it be `iofactory` (lowercase); though if the PHPExcel autoloader is working, you shouldn't need to include that as well as phpexcel itself – Mark Baker Jun 27 '13 at 07:55

6 Answers6

5

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

save_ole
  • 300
  • 1
  • 3
  • 10
  • Also I don't think there is a need to follow the "Updated Guide" link. Just place the PHPExcel.php and folder into the libraries folder – orbitory May 13 '15 at 13:55
0

ensure that u save PHPExcel/IOFactory.php inside libraries folder and load it as $this->load->library('PHPExcel/iofactory');

samlebo
  • 27
  • 1
  • 7
0

And in some Linux Server, you have to care about case.

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

Megan Fox
  • 435
  • 2
  • 6
  • 20
0

You can replace this line

$objWriter = PHPExcel_IOFactory::createWriter($objPHPexcel, 'Excel5');

by this line

IOFactory::createWriter($objPHPexcel, 'Excel5');
Majid Golshadi
  • 2,686
  • 2
  • 20
  • 29
0

First you need to place your PHPExcel folder inside thirdparty folder. Then create class file in the library folder. There you need to include thirdparty/PHPExcel file folder and extend the class. After that you can use it in your controller.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Fiaz Ahmad
  • 55
  • 1
  • 9
0

Codeiginiter 3 supports Composer to use PHPExcel:

In application/config/config.php, set $config['composer_autoload'] to TRUE.

Then you can use Composer to install PHPExcel in Codeiginiter :

composer require phpoffice/phpexcel

Further, You could try PHPExcel Helper to easier handle PHPExcel:

composer require yidas/phpexcel-helper

https://github.com/yidas/phpexcel-helper

Nick Tsai
  • 3,799
  • 33
  • 36