user2526315
user2526315

Reputation: 11

How to integrate codeigniter and PHPExcel?

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.

Upvotes: 1

Views: 36364

Answers (6)

Nick Tsai
Nick Tsai

Reputation: 4129

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

Upvotes: 0

user3606625
user3606625

Reputation: 31

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

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

Upvotes: 0

Fiaz Ahmad
Fiaz Ahmad

Reputation: 55

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.

Upvotes: 0

Flaviano
Flaviano

Reputation: 1

You can replace this line

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

by this line

IOFactory::createWriter($objPHPexcel, 'Excel5');

Upvotes: 0

save_ole
save_ole

Reputation: 310

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

Upvotes: 5

samlebo
samlebo

Reputation: 27

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

Upvotes: 0

Related Questions