YiiExcel /

Full commit


Yii extension wrapper for PHPExcel class autoload on Yii applications.


  • Copy yiiexcel directory to protected/extensions.
  • Download PHPExcel.
  • Create a phpexcel directory on protected/vendors.
  • Unzip PHPExcel and copy Classes directory content to protected/extensions/phpexcel.
  • Edit PHPExcel.php file and comment the autoload inclusion:
    /** PHPExcel root directory */
    /*if (!defined('PHPEXCEL_ROOT')) {
        define('PHPEXCEL_ROOT', dirname(__FILE__) . '/');
        require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
  • Edit index.php file and register the YiiExcel autoloader:
    //do not run app before register YiiExcel autoload
    $app = Yii::createWebApplication($config);

    Yii::import('ext.yiiexcel.YiiExcel', true);
    Yii::registerAutoloader(array('YiiExcel', 'autoload'), true);

    // Optional:
    //  As we always try to run the autoloader before anything else, we can use it to do a few
    //      simple checks and initialisations

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

    //Now you can run application
  • Edit main.php config file to import PHPExcel main class:
    // autoloading model and component classes


Just create a PHPExcel instance:

    $objPHPExcel = new PHPExcel();

Read the SiteController.php example file located inside example directory.