logo logo

Easily integrate/load PHPExcel into CodeIgniter Framework

PHPExcel is a set of PHP classes/library to read and write Excel files (.XLS/.XLSX). Based on CodeIgniter wiki page, integrating and using PHPExcel into CodeIgniter framework need some modification in PHPExcel source code. With the steps that I will show you, you will not need to edit any PHPExcel source code and the usage is very convenient just like you use on “plain-straight” PHP.

Pre-requisite: I tested this on CodeIgniter 2.1 and PHPExcel 1.7.7

Here we go:

  • download PHPExcel from https://github.com/PHPOffice/PHPExcel (yup, they move from codeplex to github)
  • Extract the compressed archive (.zip or .tar.gz). Only extract the files inside Classes folder. Extract them to CodeIgniter’s application/third_party/ folder. Your application/third_party/ folder will look like this:
extract phpexcel into codeigniter

CI application folder’s structure

  • Create new PHP file inside CI’s application/libraries/ name it Excel.php. This is the source code (source [Bahasa Indonesia] [DEAD LINK!!]: http://belajarcoding.com/php/codeigniter/membuat-laporan-excel-di-php-dengan-codeigniter-dan-phpexcel.html):

  • Your CI’s application/libraries/ folder will looke like this:
  • codeigniter's application/libraries stuctureThat’s it. Now you can use PHPExcel library in your CodeIgniter’s controller code.

Example usage (with commentary):

Have fun with CodeIgniter and PHPExcel! :)


95 Responses to “Easily integrate/load PHPExcel into CodeIgniter Framework”

  1. Don Lafferty says:

    This was amazingly simple. I tried a bunch of other examples and they all failed miserably. This one worked first time with the least amount of work.

    Thank you!

  2. Chingiz says:

    This is the best post about Codeigniter + PHPExcel i’ve read ever

  3. Don Lafferty says:

    I was able to take what I learned here and integrate PHPWord and I suspect PHPPowerPoint would be just as easy.

    • admin says:

      wow .. glad to hear that!
      I haven’t tried other PHPOffice product. They surely have done a great job.

      • Kr. Sameer says:

        I Need to Upload Data From Excel Sheet into mysql Database using codeigniter..
        but i m not getting that correct i need help.
        please reply with a simple code like this

  4. This is simply the best, have struggled with Codeigniter + Excel..

  5. Shiro says:

    Thank you for the information, very helpful

  6. EmpreJorge says:

    Awesome, very helpful.
    Really easy to follow

  7. tunde.net says:

    This is simply awesome. Tried it just once and worked correctly. What about reading from excel? Thanks alot

    • admin says:

      there’s a lot of example on PHPExcel ‘Tests’ folder, one of them is how to load an Excel file. Basically, you do something like this:

      • maas says:


        thanks :)

      • ramu says:

        i’m working on a project which can’t be revealed so my question is……
        i would display data from database which contains columns of date and cheque no the latter contains cheque number but the earlier contains either date or empty field.I need to compare the cheque number from database with the cheque number from an excel sheet if matches ,then the date column in view page need to be displayed with date column in excel sheet where cheque number matches if not leave it empty.Means the date column should only display the matched date without directly updating in database.Only when i press update button (which is there in viewpage ) it should update the date column in database.This is all should happen in Codeigniter. Please help me i working on it for days still not able to complete.Thank u in advance.

  8. Emiliano says:

    Thank you very much! I was looking exactly for this.

  9. Hi i wanted that generated file to be emailed as attachment can you help

  10. cyberfly says:

    thank you very much works like a charm.

    here some example code if you want to write cell value programmatically

    $letter = "A";



  11. Penjaga WC says:

    Gan, ane cuma ingin tanya apakah tulisan


    ente ambil dari blog ane?


    Kalo memang iya tolong hargai tag yang ane cantumin donk, jangan main hapus aje…

    Ane bukannya ingin dihargain tapi ane cuma berharap ente bisa menghargai hasil pemikiran orang lain

    Terima kasih

  12. sayad says:

    first of all , thank you very much.
    Now i am getting a excel page , but actually i need to export the values from a flexigrid to excel.. how can i implement such a query in my application?
    please help me for doing that..
    can you send me an example for reading the data from a grid to excel using codeigniter.

  13. hadi says:

    thanks its great

  14. betty says:

    how about importing excel data into mysql db. The above example is nice but it’s not what am looking for. I want to import excel sheet into mysql in codeigniter. can any body help please?

    • Neeraj Singh says:

      load->library('Lib_excel', null, 'excel');
      // load excel file
      $objPHPExcel = $this->excel->load($excelFileName);
      // get active sheets
      $objWorksheet = $objPHPExcel->getActiveSheet();
      // get highest row column
      $lastRow = $objWorksheet->getHighestRow();
      // check cell value empty or not
      for ($i = $startRow; $i getActiveSheet()->getCell($columnName . $i)->getValue();
      if ($colB == NULL || $colB == '') {
      die('The Cell' . ' B' . $i . ' is empty. Please, remove or fill with data');
      // get excel data with range e.g. (B2:B56)
      $cellValues = $objPHPExcel->getActiveSheet()->rangeToArray("$columnName$startRow:$columnName$lastRow");
      // return all data as array
      return $cellValues;

      load->model('Mod_excel', 'ModExcel', true);
      // Load CRUD lib
      * Upload Coupon Code from Excel
      public function createCouponCode() {
      $crud = new grocery_CRUD();
      $crud->set_field_upload('coupon_no', '../public/uploads/');
      $output = $crud->render();
      * Call back Function form CRUD Upload
      * @param array $files_to_upload
      * @param array $field_info
      * @return string
      function _excel_uploaded_file($files_to_upload = array(), $field_info = array()) {
      $insert_data = array();
      $ext = '';
      $file_tmp_path = '';
      foreach ($files_to_upload as $value) {
      $ext = pathinfo($value['name'], PATHINFO_EXTENSION);
      $file_tmp_path = $value['tmp_name'];
      $allowed_formats = array(
      if (in_array($ext, $allowed_formats)) {
      $excelFileName = $file_tmp_path;
      $columnName = 'B';
      $startRow = '2';
      $cellValues = $this->ModExcel->readWithExcel($excelFileName, $columnName, $startRow);
      $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($cellValues));
      foreach ($iterator as $value) {
      $insert_data[] = array(
      'coupon_no' => $value
      $this->output->enable_profiler(TRUE); //Turns on CI debugging
      $this->db->insert_batch('coupon_code', $insert_data);
      echo ($status) ? true : false;
      } else {
      return 'Error: Wrong file format. Use Excel 2007 format';

      • Neeraj Singh says:

        load->library(‘Lib_excel’, null, ‘excel’);
        // load excel file
        $objPHPExcel = $this->excel->load($excelFileName);
        // get active sheets
        $objWorksheet = $objPHPExcel->getActiveSheet();
        // get highest row column
        $lastRow = $objWorksheet->getHighestRow();
        // check cell value empty or not
        for ($i = $startRow; $i getActiveSheet()->getCell($columnName . $i)->getValue();
        if ($colB == NULL || $colB == ”) {
        die(‘The Cell’ . ‘ B’ . $i . ‘ is empty. Please, remove or fill with data’);
        // get excel data with range e.g. (B2:B56)
        $cellValues = $objPHPExcel->getActiveSheet()->rangeToArray(“$columnName$startRow:$columnName$lastRow”);
        // return all data as array
        return $cellValues;

        load->model(‘Mod_excel’, ‘ModExcel’, true);
        // Load CRUD lib
        * Upload Coupon Code from Excel
        public function createCouponCode() {
        $crud = new grocery_CRUD();
        $crud->set_field_upload(‘coupon_no’, ‘../public/uploads/’);
        $output = $crud->render();
        * Call back Function form CRUD Upload
        * @param array $files_to_upload
        * @param array $field_info
        * @return string
        function _excel_uploaded_file($files_to_upload = array(), $field_info = array()) {
        $insert_data = array();
        $ext = ”;
        $file_tmp_path = ”;
        foreach ($files_to_upload as $value) {
        $ext = pathinfo($value[‘name’], PATHINFO_EXTENSION);
        $file_tmp_path = $value[‘tmp_name’];
        $allowed_formats = array(
        if (in_array($ext, $allowed_formats)) {
        $excelFileName = $file_tmp_path;
        $columnName = ‘B’;
        $startRow = ‘2’;
        $cellValues = $this->ModExcel->readWithExcel($excelFileName, $columnName, $startRow);
        $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($cellValues));
        foreach ($iterator as $value) {
        $insert_data[] = array(
        ‘coupon_no’ => $value
        $this->output->enable_profiler(TRUE); //Turns on CI debugging
        $this->db->insert_batch(‘coupon_code’, $insert_data);
        echo ($status) ? true : false;
        } else {
        return ‘Error: Wrong file format. Use Excel 2007 format’;

  15. Jack Sparow says:

    AWESOME tutorial, you just saved me soooo much time with this one. Thanx for taking the time to share this with us!

  16. eka says:

    alo bos
    gimana implementasi phpexcel_reader_ireadfilter di CI? ini saya butuh mroses file XLS yang sizenya besar
    thank you

    • admin says:

      spt yg pernh dibilang oleh salah satu pembaca ahowto, phpexcel tidak cocok digunakan untuk memproses file dengan ukuran besar (memory habis dan timeout). baiknya cari alternatif lain (mungkin bisa diubah ke csv dulu).

      untuk readfilter nya sendiri, belum pernah coba juga .. sorry.. :(

  17. alenn says:

    Hi admin, thanks for sharing this, so far the best integration of phpexcel into Codeigniter tutorial.

    Simple and least works needed!

  18. Christian says:

    follow your steps as it is in the guide but when Habro the generated excel I get an error that says:
    has a different format than specified by the file extension, You may help me with this problem?.
    codegniter use 2.0, PHPExcel 1.7.7

    • admin says:

      Habro what???!!
      Try renaming the excel file extension from .xls into .xlsx or vice-versa. It seems your error is related to file extension.

      • Christian says:

        I made the switch and continues with the same error, which may be?

        This is the error that I generated =

        Filename: PHPExcel/IOFactory.php
        A PHP Error was encountered
        Severity: 4096
        Message: Argument 1 passed to PHPExcel_Writer_Excel5::__construct() must be an instance of PHPExcel, instance of PHPExcel_Worksheet given, called in C:\xampp\htdocs\academiatotto\entrenamientoenlinea\libraries\PHPExcel\IOFactory.php on line 141 and defined
        Filename: Writer/Excel5.php
        Line Number: 107
        A PHP Error was encountered
        Severity: 4096
        Message: Argument 1 passed to PHPExcel_Writer_Excel5_Workbook::__construct() must be an instance of PHPExcel, instance of PHPExcel_Worksheet given, called in
        Filename: Excel5/Workbook.php
        Line Number: 203
        Fatal error: Call to undefined method PHPExcel_Worksheet::getSheetCount() in C:\xampp\htdocs\academiatotto\entrenamientoenlinea\libraries\PHPExcel\Writer\Excel5\Workbook.php
        on line233

        thanks for help

  19. Christian says:

    Here is the code
    load->library(array(‘table’, ‘form_validation’,’excel’));
    $this->tipo_nota = ‘nota’;
    function generarExcelempre()

    $this->excel->getActiveSheet()->setTitle(‘test worksheet’);

    $this->excel->getActiveSheet()->setCellValue(‘A1’, ‘This is just some text value’);





    $filename = ‘just_some_random_name.xls’;
    header(‘Content-Type: application/vnd.ms-excel’);
    header(‘Content-Disposition: attachment;filename=”‘ . $filename . ‘”‘);
    header(‘Cache-Control: max-age=0’);
    $objWriter = PHPExcel_IOFactory::createWriter($this->excel, ‘Excel5’);


    if (!defined('BASEPATH'))
    exit('No direct script access allowed');
    * =======================================
    * Author : Muhammad Surya Ikhsanudin
    * License : Protected
    * Email : mutofiyah@gmail.com
    * Dilarang merubah, mengganti dan mendistribusikan
    * ulang tanpa sepengetahuan Author
    * =======================================
    require_once APPPATH.”/third_party/PHPExcel.php”;

    class Excel extends PHPExcel {

    public function __construct() {
    //thanks for help

  20. Christian says:

    I found that the code we explain on page works 100%, I think it’s a configuration error codeigniter export makes strange characters

  21. peca says:

    Hi, i get everything as described but I got the foloving
    error: A PHP Error was encountered Severity: Warning Message:
    realpath() [function.realpath]: SAFE MODE
    Restriction in effect. The script whose uid is 1096 is not allowed
    to access /tmp owned by uid 208 Filename: Shared/File.php Line
    Number: 136 ÐÏࡱá;þÿ
    ¤°äUntitled SpreadsheetUnknown CreatorUnknown Creator@ûFðÍ@ûFðÍ »
    ÌÑB°=¼%r8X”1ܐCalibri1¼Calibriàõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À
    àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À à À à”È
    worksheetÁÁgæ®üCThis is just some text value »
    }$ }$ }$ ý >¶@å ggÿÿÿÿÿ þÿÕÍÕœ.“—+,ù®0¼HPX`hp xŽä
    WorksheetFeuilles de calculRoot Entryÿÿÿÿÿÿÿÿ
    ÀFûFðÍûFðÍ@SummaryInformation(ÿÿÿÿ ÀFèWorkbookÿÿÿÿÿÿÿÿÿÿÿÿ

  22. ramji says:


    How to save (using mysql) excel data using codeigniter.

    Thanks in Advance


  23. Bryan says:

    Thanks so much for this.
    At first I get garbage on my downloaded excel file.
    But recently I faced a problem where I need to download some attachments and the downloaded attachments have a white blank line at the beginning of the binary file.

    Same happen with here and I just added ob_clean(); before saving the file.

    • tj says:

      that did the trick for me. Was getting ‘gibberish’ when I opened the file. Added the ob_clean(); and all is fine.

  24. Rob says:

    Awesome, thanks a lot!

  25. Guillermo says:

    Hey, good post. Just a note maybe can help someone, If you´re recieving error when exporting in 2007 format:
    “Excel found unreadable content in ‘*.xlsx’. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes.”

    Try adding die(); at the endo of the code:

    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename="myfile.xlsx"');
    header('Cache-Control: max-age=0');
    $objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel2007');


    It worked for me!

  26. Nacho says:

    Thanks a lot!

  27. tomexsans says:

    thank you , big help

  28. hanifa says:

    it doesn’t have view page, does it?

  29. Daniel says:

    Great idea!

  30. nagaraju says:

    hi this is very good, but i want to export entire table data, how it is possible can you help

  31. Anja says:

    cool, thank !!!!

    Misaotra e!!!

  32. Faysal says:

    Please some one helpme, My table name “tbl_user” what will be the controller.

  33. oriza says:

    Terimakasih!!! :)

  34. Angel says:

    Hi! I did all that you said but I get the error:
    “An Error Was Encountered
    Unable to load the requested class: excel”

    My controller name is “exportar.php”:


  35. Angel says:

    if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);

    include_once APPPATH.’controllers/controller_ppal.php’;

    class Exportar extends Controller_Ppal {

    function Informe() {

  36. Angel says:

    I can’t draw a chart using PHPExcel, I get the error:
    Fatal error: Call to a member function cellExists() on a non-object in ***\application\third_party\PHPExcel\Calculation.php on line 3327

    $objWriter = PHPExcel_IOFactory::createWriter($this->excel, ‘Excel2007’);

  37. rieki says:

    i’ve tried exactly the same as you write on tutorial above, but yet, there’s an error at my output.


    the ‘excel’ there, was returned an error as it said that it was undefined property thus resulting a Fatal error: Call to a member function setActiveSheetIndex() on a non-object.

    any advise what should i do?
    thanks for advance

  38. drunken says:

    thank you !

  39. Sean says:

    Dude this is sensational. Crystal clear, simple, works, plus a good practical example of its usage. A+

    One very minor suggestion might be to preface this guide by mentioning you assume the user is familiar with CodeIgniter. I noticed you’re getting a lot of pleading questions here from people who obviously haven’t used it before.

  40. dnyaneshwar kashid says:

    here i am using codeigniter 2.0.0 , i have used above mention method for implementing PHPExcel library , i have export excel file but i have got following output in excel file, suggest me why this weird output showing.

    ÐÏࡱá;þÿ þÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿþÿÿÿ

    þÿÿÿ !þÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿþÿà…ŸòùOh«‘+’³Ù0t
    Xˆ°Ìì8 T
    lä Office 2007 XLSX Test Document Office 2007 XLSX Test DocumentMaarten Balliauwoffice 2007 openxml phpDTest document for Office 2007 XLSX, generated using PHP classes.Maarten Balliauw@€à½ïð£Î@€à½ïð£Î »
    ÌÑB°=¼%r8X”1ܐCalibriàõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À à À “€ÿ’â8ÿÿÿÿÿÿÿÿÿÿÿÿ€€€€€€€€€ÀÀÀ€€€™™ÿ™3fÿÿÌÌÿÿffÿ€€fÌÌÌÿ€ÿÿÿÿÿÿ€€€€€ÿÌÿÌÿÿÌÿÌÿÿ™™Ìÿÿ™ÌÌ™ÿÿÌ™3fÿ3ÌÌ™ÌÿÌÿ™ÿfff™–––3f3™f333™3™3f33™333…†SimpleÁÁgæ®ü€Hello dddddddddddnyanhow are youi amfinethankyou
    ÌÑ*+‚€Áƒ„&ffffffæ?’ffffffæ?(è?)è?¡”dXX333333Ó?333333Ó?U} $ } $ } $ } $ ý

    þÿÕÍÕœ.“—+,ù®0à PXt |„Œ”
    œ ²äTest result file 
    Worksheet Feuilles de calculRoot Entryÿÿÿÿÿÿÿÿ ÀF€à½ïð£Î€à½ïð£Î€SummaryInformation(ÿÿÿÿ ÀF¤Workbookÿÿÿÿÿÿÿÿÿÿÿÿ ÀFRDocumentSummaryInformation8ÿÿÿÿÿÿÿÿÿÿÿÿ ÀFþÿÿÿþÿÿÿþÿÿÿýÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

  41. Dave says:

    Good stuff bro, works like a charm with nested foreach

  42. Jean-François MAVEL says:

    thema codeigniter and excel

    this element dont exist any more:

    Create new PHP file inside CI’s application/libraries/ name it Excel.php. This is the source code (source [Bahasa Indonesia]: http://belajarcoding.com/php/codeigniter/membuat-laporan-excel-di-php-dengan-codeigniter-dan-phpexcel.html):

    Now BelajarCoding.com is for sale
    I dont know how it is possible to have this element
    Please, if you know some thing give me a information back
    Greating JFM

  43. Vasi says:

    Now, this is amazing simple! Thanks a lot!

  44. fetrian says:

    works like a charm.. thanks!

  45. jimena says:

    this is awesome. I’m using and customizing it accordingly to my needs. This saved me a lot of work! 😀

  46. Anand says:

    got unreadable excel sheet

  47. Abdelaziz Elrashed says:

    Thanks a lot man, you saved my time ^_^

  48. luwie hartiarsa says:

    hello i have trouble when i’m copy and try example
    the output in file is like that
    ÐÏࡱá;þÿ þÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
    may some one help me :(

  49. kamaljit says:

    Thanks it works fine

    let me knw how to auto adjust column width

  50. Yesid Carrillo says:

    Be aware: Both libraries/Excel.php and controllers/YourController.php need to be encoded as “UTF without BOM” (ANSI as UTF8). If you encoded them as UTF8, your output file can not be opened in MS Excel. It took me hours discover this.

  51. Isra says:

    Thanks a lot.
    how could I write in existing file and downdload it.
    Note: I don’t want to save this data to the source file.

  52. Nisham says:

    i cant download it but getting answers with invalid charecters.

  53. Ray says:

    I can’t get this to work whenever I load the database library in the autoload.php in the /config folder. Is there a way to fix this?

  54. adrian says:

    alguien sabe como implementar esto mismo en YII FRAMEWORK POR FAVOR TENGO DIAS EN ESTO

  55. candra says:

    sore master sebelumnya makasih tutorial bermanfaat sekali, sy bingung cara execute di view nya gimana..saya menggunakan button untuk extrak to excel nya di view gmn ya cara ngejalanin fungsi yang udah di buat di controllernya? terima kasih sebelumnya

  56. shanthi says:

    thanks..it works well

  57. Naved says:

    Awesome. Thank you very much.
    Works perfectly.

  58. Grzegorz says:

    I was getting frustrated about the excel file getting corrupted, the only thing i had to do was to use ob_end_clean() to clean any output buffering. Just like this:

    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename="myfile.xlsx"');
    header('Cache-Control: max-age=0');
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    $objWriter->save('php://output'); exit();

  59. Faridul Khan says:

    Thanks. Very helpful to me

  60. Alessio says:

    Simply great… saved me a lot of time

  61. ardb says:

    Hi, I got ” Fatal error: Class ‘PHPExcel_IOFactory’ not found in “. Any ideas ?

  62. iManila says:

    Good day I can’t seem to access this page http://belajarcoding.com/php/codeigniter/membuat-laporan-excel-di-php-dengan-codeigniter-dan-phpexcel.html where I get the source code for the library.. It keeps on redirecting me to http://www.hugedomains.com/ Is there another site where I can copy the source code? Thank you

    • admin says:

      you do not need to access that page, it’s dead.
      All of the code that you need is already in this post.

  63. Muhsin says:

    First thank you for the very useful post,

    Unfortunately i am getting some error only in live server

    This is my error

    Fatal error: Class ‘PHPExcel_Shared_String’ not found in C:\Inetpub\vhosts\unioninvest.org\httpdocs\admin\third_party\PHPExcel\Autoloader.php on line 36

    Please replay as soon as possible

    Thank you

  64. Paul says:

    Good stuff, works pretty well years later

  65. vignesh says:

    Thank you, you saved my day.. not tried yet, but I found myself happy because I skipped the editing of PHPExcels source code.

  66. Arthur says:

    You, sir, are awesome!

  67. Thanks u !!!!!!! :*

  68. Divya says:

    Nice Tut for codeigniter users.. helped.

  69. Kr. Sameer says:

    I m Getting These Errors Please Someone Help Me.
    I Need To Solve it as soon as possible
    A PHP Error was encountered

    Severity: Notice

    Message: Undefined offset: 0

    Filename: Cell/DefaultValueBinder.php

    Line Number: 86

    A PHP Error was encountered

    Severity: Warning

    Message: preg_match() expects parameter 2 to be string, array given

    Filename: Cell/DefaultValueBinder.php

    Line Number: 95

    A PHP Error was encountered

    Severity: Warning

    Message: iconv_substr() expects parameter 1 to be string, array given

    Filename: Shared/String.php

    Line Number: 576

    and at the file i m getting this….

    ÐÏࡱá;þÿ þÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿþÿÿÿþÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿþÿà…ŸòùOh«‘+’³Ù0¸@Hh€˜ ¤°äUntitled SpreadsheetUnknown CreatorUnknown Creator@€ Z9ëTÐ@€ Z9ëTÐþÿÕÍÕœ.“—+,ù®0¼HPXhp xŽä WorksheetFeuilles de calcul » ÌÑB°=¼%r8X"1ܐCalibri1¼Calibriàõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À à À à"È “€ÿ’â8ÿÿÿÿÿÿÿÿÿÿÿÿ€€€€€€€€€ÀÀÀ€€€™™ÿ™3fÿÿÌÌÿÿffÿ€€fÌÌÌÿ€ÿÿÿÿÿÿ€€€€€ÿÌÿÌÿÿÌÿÌÿÿ™™Ìÿÿ™ÌÌ™ÿÿÌ™3fÿ3ÌÌ™ÌÿÌÿ™ÿfff™–––3f3™f333™3™3f33™333…N CRM LeadsÁÁgæ®ü » ÌÑ*+‚€Áƒ„&ffffffæ?'ffffffæ?(è?)è?¡"dXX333333Ó?333333Ó?U}$ }$ }$ }$ }$ }$ }$ }$ }$ } $ } $ }$ }$ } $ }$ }$ }$ }$ }$ }$ }$ }$ }$ }$ }$ }$ }$ }$ }$ }$ }$ }$ } $ }!!$ }""$ }##$ }$$$ }%%$ }&&$ }''$ }(($ }))$ }**$ }++$ },,$ }--$ }..$ }//$ }00$ }11$ }22$ }33$ }44$ }55$ }66$ }77$ }88$ }99$ }::$ };;$ }<�>$ }??$ }@@$ }AA$ }BB$ }CC$ }DD$ }EE$ }FF$ }GG$ }HH$ }II$ }JJ$ }KK$ }LL$ }MM$ }NN$ }OO$ }PP$ }QQ$ }RR$ }SS$ }TT$ }UU$ }VV$ }WW$ }XX$ }YY$ }ZZ$ }[[$ }\\$ }]]$ }^^$ }__$ }$ }aa$ }bb$ }cc$ }dd$ }ee$ }ff$ }gg$ }hh$ }ii$ }jj$ }kk$ }ll$ }mm$ }nn$ }oo$ }pp$ }qq$ }rr$ }ss$ }tt$ }uu$ }vv$ }ww$ }xx$ }yy$ }zz$ }{{$ }||$ }}}$ }~~$ }$ }€€$ }$ }‚‚$ }ƒƒ$ }„„$ }……$ }††$ }‡‡$ }ˆˆ$ }‰‰$ }ŠŠ$ }‹‹$ }ŒŒ$ }$ }ŽŽ$ }$ }$ }‘‘$ }’’$ }““$ }””$ }••$ }––$ }——$ š™ ! "!#"$#%$&%'&(')(*)+*,+-,.-/.0/102132435465768798:9;:<�;==?>@?A@BACBDCEDFEGFHGIHJIKJLKMLNMONPOQPRQSRTSUTVUWVXWYXZY[Z\[]\^]_^_a`bacbdcedfegfhgihjikjlkmlnmonpoqprqsrtsutvuwvxwyxzy{z|{}|~}~€€‚ƒ‚„ƒ…„†…‡†ˆ‡‰ˆŠ‰‹ŠŒ‹ŒŽŽ‘’‘“’”“•”–•—–

  70. Vlad Dvernik says:

    Thanks for a tip! the first one i found and working fine!
    i had asyntax error, unexpected ‘class’ …
    and i fugured out that when you copy a class Excel constructor code from the top of this page … it contain some invisible for the eye characters similar to a space …
    after i deleted all the spaces manually the error has gone!

  71. Milan Soni says:

    Hi I am using codeigniter 2.2 and PHPExcel 1.8 version. and nothing seems working for me. i have followed same procedure as you mentioned in article.

    By going step by step testing found that PHPExcel.php not getting called so PHPEXCEL_ROOT is not getting defined… and problem start.

    error : parse error: syntax error, unexpected ‘class’ (T_CLASS) in D:\wamp\www\VRS\application\libraries\Excel.php on line 14

    I really appreciate your faster reply.

    I am getting stucked since last two day in this issue.


  72. sabari says:

    Thank u very much for this one.. its very helpful for me

  73. udara says:

    eeeeeeeeeehaaaaaaaaaa….nice nice nice…
    I scroll mouse wheel so many times to find comment box….:) you are great brooo…. thank you soooo much….


  1. Exporting your MySQL table data with PHPExcel + CodeIgniter | Danny Herran - [...] Most of the time my clients need to download data from their database tables. Exporting to CSV is a …
  2. Using PHPExcel class with CodeIgniter | Fally's Code and Stuff - [...] [Source] [...]
  3. Codeigniter Tutorial Pdf | Find and Get User's Manual Pdf - […] www.ahowto.net […]
  4. php: Easily integrate ezPDF (a.k.a pdf-php) into CodeIgniter Framework - […] another spare time, so, another simple tips for you. Last post I already show how to easily integrate PHPExcel …
  5. Featured Articles: Creating Ms Word Document using CodeIgniter and PHPWord - […] of my reader – Don Lafferty – told us that integrating PHPWord into CodeIgniter is also as easy as …

Leave a Reply

%d bloggers like this: