Excel Export Demo 1   Tips

Latest Stable Version Latest Unstable Version Total Downloads Monthly Downloads Daily Downloads
Thankful to Krajee!
to get more out of us.

NOTE: This extension depends on the kartik-v/yii2-krajee-base extension which in turn depends on the yiisoft/yii2-bootstrap extension. Check the composer.json for this extension's requirements and dependencies that may be updated by composer.

Auto formatting example. This example showing auto formatting of cells for excel export by setting the autoXlFormat property at the GridView widget level to true. It will use the format setting for each column to auto-derive the excel cell format. Click on export dropdown menu on top right above and select excel export.

Showing 1-5 of 8 items.

Products

CodeNameBuy DateLaunch TimeQuantityPriceAmountCreated On
0218881Product 108-Apr-20034:22 PM2,12132.5569,038.5521-Jun-15 06:34:45
0218882Product 202-Nov-20012:04 AM281,582.3544,305.8031-Dec-14 21:22:12
0218883Product 329-Feb-20041:11 AM1,97253.19104,890.6810-Nov-12 19:02:03
0218884Product 403-Mar-200110:05 PM2,11228.4760,128.6431-Mar-04 17:34:15
0218885Product 501-Nov-20092:11 PM431,222.6652,574.3831-Mar-13 00:29:12
Total   6,2762,919.22330,938.05 

echo GridView::widget([
    'dataProvider'=>$dataProvider,
    'autoXlFormat'=>true,
    'export'=>[
        'fontAwesome'=>true,
        'showConfirmAlert'=>false,
        'target'=>GridView::TARGET_BLANK
    ],
    'columns'=>[
        [
            'attribute'=>'code', 
            'format'=>'text', 
            'width'=>'100px', 
            'pageSummary'=>'Total'
        ],
        [
            'attribute'=>'name', 
            'format'=>'text', 
            'width'=>'120px'
        ],
        [
            'attribute'=>'buy_date', 
            'format'=>['date', 'php:d-M-Y'], 
            'width'=>'100px'
        ],
        [
            'attribute'=>'launch_time', 
            'format'=>['time', 'php:g:i a'], 
            'hAlign'=>'center', 
            'width'=>'100px'
        ],
        [
            'attribute'=>'quantity', 
            'format'=>'integer', 
            'hAlign'=>'right', 
            'width'=>'100px', 
            'pageSummary'=>true
        ],
        [
            'attribute'=>'price', 
            'format'=>['decimal', 2], 
            'hAlign'=>'right', 
            'width'=>'100px', 
            'pageSummary'=>true
        ],
        [
            'class'=>'kartik\grid\FormulaColumn', 
            'label'=>'Amount', 
            'format' => ['decimal', 2],
            'value'=>function ($model, $key, $index, $widget) { 
                $p = compact('model', 'key', 'index');
                return $widget->col(4, $p) * $widget->col(5, $p) ;
            }, 
            'hAlign'=>'right', 
            'width'=>'120px', 
            'pageSummary'=>true
        ],
        [
            'attribute'=>'created_on', 
            'format'=>['datetime', 'php:d-M-y H:i:s'], 
            'width'=>'140px'
        ]
    ],
    'pjax'=>true,
    'showPageSummary'=>true,
    'panel'=>[
        'type'=>'primary',
        'heading'=>'Products'
    ]
]);