Welcome Guest, Not a member yet? Register   Sign In
PHPExcel with CI not loading [SOLVED]
#1

[eluser]bonk[/eluser]
Hi,

I'm trying to implement PHPExcel to my CI configuration, but with no success. I searched the forum and found a couple of threads on this, but still no help. I'm currently running 1.7.3 CI and tried to implement the latest PHPExcel 1.7.6 code.

I have followed all instructions and options from these threads:

http://ellislab.com/forums/viewthread/158920/ <--Original, plugin, library etc

http://ellislab.com/forums/viewthread/161210/ <--PHPExcel as plugin

I even downloaded and installed fresh CI 2.0 and made a test drive with PHPExcel 1.7.6. Still the same result. So I have tried to load this as library, plugin and separate custom class, without a success.

I'm trying to load the PHPExcel with one of these:

Code:
$this->load->library("PHPExcel");
Code:
$this->load->plugin("phpexcel");

Rest of the code is exact copy from the threads above. Script goes on, but stops on either of these. I'm getting no errors on screen and Apache logs are empty also.

Any ideas what I'm missing out here? Something related to my Apache configuration? Both of these threads guide not to manipulate PHPExcel, should I still edit something on classes?

I'll be so thankful if someone points me to right direction.
#2

[eluser]Bruno De Barros[/eluser]
I don't know what's wrong, or what you tried to do, but personally, I used PHPExcel without loading it as a library. I created a PHPExcel folder in the libraries folder, put the PHPExcel.php and the PHPExcel folder in it, and then used the following code:

Code:
$oldIncludePath = get_include_path();
        set_include_path(APPPATH . 'libraries/PHPExcel');

        include_once 'PHPExcel.php';
        include_once 'PHPExcel/Writer/Excel2007.php';
        include_once 'PHPExcel/IOFactory.php';

        $objPHPExcel = new PHPExcel();

        # my code here, using phpexcel

        set_include_path($oldIncludePath);

I had to change the include_path because otherwise the PHPExcel files wouldn't load properly (when PHPExcel tries to autoload certain files), but then I change it back, after I'm done with PHPExcel. Note that you mightn't need Excel2007 or IOFactory, it all depends on what components of PHPExcel you're using.

Hope this helps.
#3

[eluser]bonk[/eluser]
Bruno,

I tried your guidelines, but still it gets stuck to the same line. When it's supposed to load the PHPExcel.php, only blank screen.

Code:
include_once 'PHPExcel.php';

So I have tried to load this as Plugin, Library, custom class and now your way, thus the problem must be elsewhere. Could you or someone else confirm, that you haven't edited PHPExcel classes anyway?

What am I missing here? This is what I did as a fresh install:

1) Downloaded and installed CI 2.0 (welcome screen ok)
2) Downloaded PHPExcel 1.7.6
3) Created "pxl" folder to libraries (/application/libraries/pxl)
4) Copied PHPExcel classes to this folder, both PHPExcel.php and PHPExcel-folder (/application/libraries/pxl/PHPExcel.php & /application/libraries/pxl/PHPExcel/)
5) Created pxl.php to libraries folder with this data:
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/** PHPExcel */
class Pxl
{
   function __construct()
  {
      require_once APPPATH.'/libraries/pxl/PHPExcel.php';
      require_once APPPATH.'/libraries/pxl/PHPExcel/IOFactory.php';
  }
}
6) Added function excel1 to welcome.php controller
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        $this->load->view('welcome_message');
    }
    
     function excel1()
      {

      $this->load->library("pxl");
//    $this->load->library(“pxl/PHPExcel/iofactory”);

      $objPHPExcel = new PHPExcel();
      $objPHPExcel->getProperties()->setTitle("title")
                  ->setDescription("description");

  // Assign cell values
      $objPHPExcel->setActiveSheetIndex(0);
      $objPHPExcel->getActiveSheet()->setCellValue("A1", "cell value here 111");

      $objPHPExcel->createSheet();
      $objPHPExcel->setActiveSheetIndex(1);
      $objPHPExcel->getActiveSheet()->setCellValue("A1", "cell value here 222");
   // Save it as an excel 2003 file
      $objWriter = IOFactory::createWriter($objPHPExcel, "Excel5");
      $objWriter->save("reports/nameoffile.xls");
      $this->index(); //CALL DISPLAY
      }
      
}

7) Tried to call function as http://localhost/index.php/welcome/excel1

For this the result is blank screen, with no errors from CI or to Apache logs.

This is the line that kills it:
Code:
$this->load->library("pxl");

Any ideas what I'm doing wrong? I haven't edited PHPExcel anyhow, just original files. What could cause this? Reading about different implementation methods, it seemed to be an easy task but was not. Apache related?

All ideas are extremely welcome.
#4

[eluser]Bruno De Barros[/eluser]
If you're not seeing any errors, that might be because of the server's configurations (it happened to me as well, in the past, many times). To fix it, insert the following code into your index.php, just before the comment that has "LOAD THE BOOTSTRAP FILE", as below:

Code:
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', APPPATH . 'logs/error_log.txt');                            
error_reporting(E_ALL);

/*
* --------------------------------------------------------------------
* LOAD THE BOOTSTRAP FILE
* --------------------------------------------------------------------
*
* And away we go...
*
*/

Let me know if that makes the errors show up.
#5

[eluser]bonk[/eluser]
Thanks Bruno!

This is really is the first step to make this work.

Now I'm getting this exception:

Code:
Exception: Multibyte function overloading in PHP must be disabled for string functions (2). in /var/www/localhost/application/libraries/pxl/PHPExcel/Autoloader.php on line 32

And from Autoloader.php it's this one:

Code:
if (ini_get('mbstring.func_overload') & 2) {
    throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}

So it seems to be a PHPHExcel issue, any thoughts on this?
#6

[eluser]bonk[/eluser]
Bruno,

Thanks for your help! I got it now!

If someone is struggling with the same issue, here's what I did to solve it:

1) made this change to php.ini
Code:
mbstring.func_overload = 0

After this change the actual example worked without problems, both excel file saved to file and as output to screen.




Theme © iAndrew 2016 - Forum software by © MyBB