Search code examples
phpyiiphpexcel

Autoload PHPExcel library with Yii (include(PHPExcel_Worksheet_Drawing.php): failed to open stream: No such file or directory)


I'm using Yii framework , and I have to load PHPExcel classes.

in my main.php I set the configuration as

'import'=>array(
        'application.models.*',
        'application.components.*',
                'application.extensions.*',
                'ext.PHPExcel.PHPExcel',            
    ),

in I was edit the Register function inside Autoloader.php as follow

public static function Register() {
        $functions = spl_autoload_functions();

          foreach($functions as $function)
            spl_autoload_unregister($function);
          $functions=array_merge(array(array('PHPExcel_Autoloader', 'Load')), $functions);

          foreach($functions as $function)
            $x = spl_autoload_register($function);
          return $x;
  }

when I call $objPHPExcel =new PHPExcel(); it's working well,

but when I call $objDrawing = new PHPExcel_Worksheet_Drawing(); its return

include(PHPExcel_Worksheet_Drawing.php): failed to open stream: No such file or directory

my directory structure is :

extensions
    -----PHPExcel
          -------PHPExcel
    ------ PHPExcel.php

Thanks for help


Solution

  • Try this code out if it works, notice there are dual *

    Yii::import('ext.PHPExcel.**', true); 
    
    $objDrawing = new PHPExcel_Worksheet_Drawing();
    var_dump($objDrawing);
    

    [Tested in Yii version: 1.1.13]