eexcelwriter

Simple export of dataproviders to xls files.
9 followers

EExcelWriter is a component similar to EExcelView, but uses a different library to generate the excel files, leading speed improvements of up to 10 times.

The library used is http://www.bettina-attack.de/jonny/view.php/projects/php_writeexcel/ , but with a part of it modified to work also on PHP 5.4.

The extension is a work-in-progress, for now it has basic functionality for generating the spreadsheets.

Requirements

Yii 1.1 and above.

Usage

Paste the contents of the repository in your protected directory, make sure that you load components.EExcelWriter in your configuration file. Then simply call the widget in your view files like :

$this->widget('EExcelWriter', array(
    'dataProvider' => $model->search(),
    'title'        => 'EExcelWriter',
    'stream'       => FALSE,
    'fileName'     => 'file.xls',
    'columns'      => array(
        array(
            'header' => 'id',
            'name' => 'ID',
        ),
        'column1',
        'column2',
    ),
));

Resources

As stated, the component uses http://www.bettina-attack.de/jonny/view.php/projects/php_writeexcel/ with some modifications to make it work on PHP 5.4.

Github page for the extension : https://github.com/ascendro/EExcelWriter

Total 5 comments

#18429 report it
letsjump at 2014/10/28 07:08am
cast to string

Hi, How can I cast to string a numbered value like a code with starting zeros (EG 000125)? Thanks for your work!

#18073 report it
radoo at 2014/09/04 06:04am
Exporting data to excel from DB.

To get data from database, you can simply create a dataprovider that gets data from DB. here's a short example:

in your controller action:

$sql = "select stuff from tables"; // your sql
$rawData =  Yii::app()->db->createCommand($sql)->queryAll(); // you get them in an array
$count = Yii::app()->db->createCommand('SELECT COUNT(*) FROM (' . $sql . ') as count_alias')->queryScalar(); // you need to count them for the CArrayDataProvider
$model = new CArrayDataProvider($rawData,
            array(
                'keyField' => 'YOUR_ID',
                'totalItemCount' => $count,
                'sort' => array(
                    'attributes' => array(
                        'field1', 'field2', 'field3', '*',
                    ),
                ),
                'pagination' => array(
                    'pageSize' => 5000000, // large number so you export all to excel
                ),
            )
        );
// renderpartial so you don't export with layout
        $this->renderPartial('myReportExcel', array(
            'model' => $model,
        ));

and in your "myReportExcel.php"

$this->widget('EExcelWriter', array(
    'dataProvider' => $model,
    'title' => 'EExcelWriter',
    'stream' => TRUE,
    'fileName' => 'my-file-name.xls',
    'columns' => array(
        'col1',
        'col2',
        'col3',
        'col_etc',
    ),
));
#17123 report it
Dimas Mahendra at 2014/05/05 08:29pm
dataprovider

how to get the data from database that create and insert in to the excel??

#16245 report it
Alexandru (Ascendro) at 2014/02/03 06:41am
Re: Question

Hi Alex,

It sounds like what you need is to create an xls, for that you can use one of the existing PHP libraries; in that case performance would not be that much of an issue, since you don't write lots of data, so our suggestion is that you use http://phpexcel.codeplex.com/, since it has the most features. A quick search turned out that there is a wrapper for it : http://www.yiiframework.com/extension/yiiexcel.

#16238 report it
Alex D. at 2014/02/02 04:48am
Question

Thank you for extension. Is it possible to use this extension not to just generate and export column data, but "insert" than columns in pre-created .xls file or some other type of template. That would be much easier to create ready-to-print documents. Or, maybe you can advise some other extension which would conform my needs? Thanx in advance!

Leave a comment

Please to leave your comment.

Create extension