Problem PHPExcel + CodeIgniter

Topics: Developer Forum, User Forum
Jan 18, 2009 at 5:39 PM
Anyone ever use CodeIgniter before ?
I'm trying to use PHPExcel library within my CI code and i found this strange behaviour.

I want to do this :

Create on-the-fly spreadsheet based on a template.
So i have to load a template, manipulate the content, and send it to the browser.

I have this file in my CI library :


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

class Excel  
    public $workbook;
    function __construct()
        // PHPExcel libraries have to be in your include path !
    function load()
        // Path to the template file
        $template_location = 'resources/template.xls';
        $xls_reader = PHPExcel_IOFactory::createReader('Excel5');
        $this->workbook = $xls_reader->load($template_location);
        var_dump($this->workbook); // Yea, successfully load the data
    function send()
        //So far so good, now let's create the writer
        $xls_writer = PHPExcel_IOFactory::createWriter($this->workbook, 'Excel5'); // Trouble maker
        // Stops here, no error message, output nothing
        header('Pragma: public');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Content-Type: application/force-download');
        header('Content-Type: application/octet-stream');
        header('Content-Type: application/download');
        header("Content-Disposition: attachment;filename=from-template.xls");
        header('Content-Transfer-Encoding: binary');


And i have this tester class in my controller :



class Excel_tester extends Controller
    function __construct()
    function test()

And here goes the problem :

The template was loaded successfully. I tried to var_dump'ing the workbook object, and it outputs correctly.
The code execution stops right when i call PHPExcel_IOFactory::createWriter(). No error messages displayed. It just stopped.

I tried to change the parameter,
so instead of "createWriter($this->workbook, 'Excel5')", i use "createWriter(new PHPExcel(), 'Excel5')".
No luck.

BUT, when i omit the template load code (that is, no createReader executed in my code), the "createWriter(new PHPExcel(), 'Excel5')" works like a charm, and it outputs the empty xls correcly.

Why is that, and how can i fix my problem here ?
Any helps will be appreciated. As far as i found, PHPExcel fits my needs the most, and i don't want to abandon this library.
Jan 19, 2009 at 12:45 AM
Double post: