yiiexcel Wrapper for PHPExcel

  1. Requirements
  2. Installation
  3. Usage
  4. Resources

This is a class with an autoloader and few steps for use PHPExcel inside a Yii application.

Requirements

  • Yii 1.1 or above
  • PHPExcel 1.7.8

Installation

  • 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:
require_once($yii);
    //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
    PHPExcel_Shared_ZipStreamWrapper::register();
    
    if (ini_get('mbstring.func_overload') & 2) {
        throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
    }
    PHPExcel_Shared_String::buildCharacterSets();
    
    //Now you can run application
    $app->run();
  • Edit main.php config file to import PHPExcel main class:
// autoloading model and component classes
    'import'=>array(
        ...
        'application.vendors.phpexcel.PHPExcel',
        ...
    ),

Usage

Just create a PHPExcel instance:

$objPHPExcel = new PHPExcel();

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

Resources

3 3
17 followers
5 716 downloads
Yii Version: 1.1
License: GPL-2.0
Category: Others
Developed by: Yeye
Created on: Jan 23, 2013
Last updated: 11 years ago

Downloads

show all

Related Extensions