We are going to deploy the new yiiframework.com website on March 23, 2018 from 8:00 to 12:00 UTC.
Website and Yii documentation will not be available in this time frame. Check the news for more details.

Yii 1.1: eexcelview

A simple extension that exports dataprovider data to excel table.

EExcelView on github

Forum thread

This is my first extension ever :). It is a wrapper of PHPExcel that extends from CGrivView. The main idea is to easily export already defined grids to excel files. You can use the same array of parameters that the grid uses plus an aditional specific params, which are:


Document properties

  • creator - The creator of the document
  • title - Title of the excel document
  • subject, description, category

Other params

  • libPath - path to PHPExcel, defaults to 'ext.phpexcel.Classes.PHPExcel'
  • autoWidth - whether to auto extend cells for the content(default true)
  • exportType - the type of the export, all possible types of PHPExcel lib(Excel5, Excel2007,PDF, HTML)
  • disablePaging - if set to true, it will export all data (default true)
  • filename - the full path of the filename to export to. If null it will stream to the browser
  • stream - true/false stream to browser or save to file.
  • grid_mode - Whether to display grid or to export it to selected format. Possible values(grid, export)
  • grid_mode_var - defaults to 'grid_mode' GET var for the grid mode


Yii 1.1 or above and PHPExcel library


The usage is like using CGridView:

$this->widget('EExcelView', array(
     'dataProvider'=> $dataprovider,
      ..... other options 


The path of the PHPExcel library is hardcoded to: application.extensions.phpexcel.Classes.PHPExcel

Asuming that you have extracted the lib under extensions folder. I will change that later.

ver 0.32

  • Fixed the CButtonColumn bug "Property "CButtonColumn"."name" is not defined"...
  • Fixed the issues with multiple level of buffering(le top)
  • Fixed export buttons column bug(le top)
  • Added documetation of all properties in the extension page.

ver 0.31

Mainly bug fix release. I also modified the extension to be able to run in console mode(although its a widget). I realy needed something to send me reports in xls. Here is the code snippet:

$factory = new CWidgetFactory();    
        $widget = $factory->createWidget($this, 'EExcelView', array(

ver 0.3

Major change EExceView now can fully replace CGridView. There is an optional parameter 'gridmode'(default "grid") and when not set it acts just like normal grid. If gridmode="export" it exports the grid in the selected "exportType"(default "Excel5"). The path to PHPExcel can now be customized via "libPath" variable. If the lib is not found a warning is generated and export is disabled.

  • Added: "gridmode" possible values(grid, export). When set to grid acts like normal grid.
  • Added: "libPath" property, defaults to "application.extensions.phpexcel.Classes.PHPExcel". The location of PHP Excel lib.
  • Added: "grid_mode_var" the GET variable name which can be used to change the grid mode. defaults to "grid_mode"
  • Added: new template item "exportbuttons" which renders export links. Example: .... 'template'=>"{summary}\n{items}\n{exportbuttons}\n{pager}" ....
  • Added: config for export buttons. "exportButtonsCSS"(default="summary") css class for the div which wraps the buttons. "exportButtons" - array of exportTypes, for each item it renders link which exports the grid. If you specify an array you can customize the caption of the link. All export type have default captions. Example: array('Excel5'=>array('caption'=>'*.xls'), PDF). Property exportText which defines the text before the links, deault = "Export to: ".
  • Added: renders CLinkColumns. Just the text of the links.
  • Added: support for footer, just like normal footer.
  • Added: callback functions called after processing of the cell.$cell is the php excel cell object. Refer to php excel documentation for help. $data is the same var the grids uses for expressions. $value is the text the extension had put in the cell :
    1. onRenderHeaderCell(PHPExcel_Cell $cell, string $value)
    2. onRenderDataCell(PHPExcel_Cell $cell, $data, string $value)
    3. onRenderFooterCell(PHPExcel_Cell $cell, string $value)

Thanks to all who have written me with ideas how to extend this extension. Sorry by I've been realy busy lately so I didnt have time to bring this earlier. I have tested the extension but if you find any bug or something you'd like me to add, feel free to write. Happy yiister :)

ver 0.2

  • Fixed: Error when saving to filename.
  • Fixed: bug in column indexing when > 26
  • Added: support for CSV
  • Added: new param "stream"(default true) when set to true streams to browser else save to local filename
  • Added: get real column headers
  • Added: get title from page title when not specified

Total 20 comments

#19654 report it
le_top at 2015/11/05 08:27am
Array / Dataprovider

You can use 'CArrayDataProvider' to adapt the array to the required interface.

#19652 report it
Befree Nishant at 2015/11/05 01:22am
instead of dataprovider can we pass array or model->findAll data?

can we pass array data OR model->findAll() data as dataprovider instead of data provider.

please advice,

#19214 report it
josterricardo at 2015/04/16 10:56am
datetime field


array( 'name' => 'fecha', 'type' => 'datetime' ),

#19213 report it
le_top at 2015/04/16 10:54am
Datetime (2)

Did you replace 'posCreditValidDate' by the actual name of your field?

#19212 report it
josterricardo at 2015/04/16 10:29am
datetime field

when use

                        'name' => 'posCreditValidDate',
                        'type' => 'datetime'

The result is this in all records :(

01 Jan, 1970 01:01:00 am

#19207 report it
le_top at 2015/04/15 07:23pm
datetime field


I specify a datetime field like this and the export is fine in my case:

                        'name' => 'posCreditValidDate',
                        'type' => 'datetime'
#19206 report it
josterricardo at 2015/04/15 06:33pm
Problem with datetime field

When I export the data you change the format datetime fields. The result of a date is as follows: 13 05: 20: 7/4/2015 and right must be 04/13/2015 5:20:07.

As resulevo this ??

#19070 report it
zabaleta10 at 2015/03/09 12:40am

how to create custom row ? or create specific row

#19061 report it
letsjump at 2015/03/06 12:09pm

I've tried to activate PHPExcel framework cache by inserting this code in "EExcelView.php":

public function init()
    Yii::import($this->libPath, true);
    // CACHING 
    $cacheMethod   = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
    $cacheSettings = array('memoryCacheSize' => '32MB');
    if (!PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings)) {
    die($cacheMethod . " caching method is not available" . EOL);
    $this->objPHPExcel = new PHPExcel();

But it doesn't work. After a day of debug, I found out that by calling "$this->dataProvider->getData()" anywhere in the script, the caching framework stops working.

$this->dataProvider->getData() is called in two required methods renderRow() and renderBody()

Anyone has found a solution?

Thanks in advance!

#18717 report it
neophyte at 2014/12/17 04:23am
Multiple export button on same page

I have multiple grid and each has separate export buttons but when I click on export button of any grid it always exports the data of the grid which comes first in the view.. Can anyone help me solve this problem..

#18695 report it
phreak at 2014/12/13 08:50am
large dataset problem

@hendrey this is most probably due to high memory usage. Try to increase the memory with memory_limit e.g. ini_set('memory_limit', '1G') and try again. The version of PHPExcel this extension uses is really using a lot of memory.

#18549 report it
hendrey at 2014/11/14 05:37am
Export Large Dataset


I have a problem exporting large dataset, 20000 plus rows with 36 columns. It does work with few thousands of rows but goes blank with larger dataset.

There is no specific error that the plugin produces or any errors in the application log.

Did you guy ever experienced this problem with the plugin?


#18530 report it
pramkimpam at 2014/11/11 01:23pm
Problem there is a space after row export

After I export from database to excel there is an empty field row after row that field with data.. For example I have 1000 data and I export to excel, at row 1001 there is empty field but it fill with something null.. So when I want the excel file to import again to database, there is an empty input after 1000 data imported, it is like row 1001 but it is null or "" How to clear that??

thnks for help

#18493 report it
gallego123 at 2014/11/06 09:18am
setting TCPDF


In order to export to PDF, you must configure the path to tcpdf. To do this you must change ext.PHPExcel/Classes/PHPExcel/Settings.php adding

/ ** PATH_TCPDF root directory. ext.tcpdf * /
if (! defined ('PATH_TCPDF')) {
     / **
      * /
     define ('PATH_TCPDF', dirname (__ FILE__) '/../../../tcpdf'.);

and setting

private static $_pdfRendererName = self::PDF_RENDERER_TCPDF;
private static $_pdfRendererPath = PATH_TCPDF;
#18338 report it
Artur Oliveira at 2014/10/18 12:24pm
Port to Yii2


I recently published a port of your extension to Yii2

Hope you have the time to test it and give some feedback

#16945 report it
phreak at 2014/04/15 01:42pm
try this

Amjad Khan try to set grid_mode to 'grid' and see if the grid is rendered normally. Do you have any errors in the log.

#16828 report it
Amjad Khan at 2014/04/01 08:25am
I can get the downloaded file in Excel

I use the following action in my controller

public function actionExcel() {
        $model = new News('search');
        $factory = new CWidgetFactory();
        $widget = $factory->createWidget($this, 'EExcelView', array(
            'dataProvider' => $model->search(),
            'grid_mode' => 'export',
            'title' => 'Title',
            'filename' => 'report.xlsx',
            'stream' => false,
            'exportType' => 'Excel2007',
            'columns' => array(
                    'header' => 'News Paper Name',
                    'name' => 'fknewspaperid',
                    'value' => '$data->Newspapername->newspapername',
                    'header' => 'Date',
                    'name' => 'reportdate',
                    'header' => 'News Analyst',
                    'name' => 'fkuserid',
                    'value' => '$data->User->username',
                    'class' => 'bootstrap.widgets.TbButtonColumn',

I got the blank html page, i want to get Excel sheet, please help

#14911 report it
semprul at 2013/09/20 04:10am

i used CAvtiveDataProvider as data provider..

#14899 report it
albertski at 2013/09/19 09:20am

Just tried this and it worked:


I am using a DataProvider and it seems like you are not. I think you will need to use a DataProvider or if you are look if there is an issue there.

#14894 report it
semprul at 2013/09/18 11:44pm

this is what i mean: i want to add collumn that contain row number. the ++$row not working as the cgridview does...

                    'value'=>'++$row', ////// ---> this not work 

Leave a comment

Please to leave your comment.

Create extension