Install Yii2-excelview:
Either run
php composer.phar require --prefer-dist arturoliveira/yii2-excelview "*"
or add
"arturoliveira/yii2-excelview": "*"
to the require section of your composer.json file.
In the main.php add below:
'modules' => [//add by Scott 'gridview' => [ 'class' => '\kartik\grid\Module' // enter optional module parameters below - only if you need to // use your own export download action or custom translation // message source // 'downloadAction' => 'gridview/export/download', // 'i18n' => [] ], ...
In your controller create an export function like below. Then you can export your data through link: yousite\yourcontroller\export
use arturoliveira\ExcelView; public function actionExport() { $searchModel = new CountrySearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); ExcelView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'fullExportType'=> 'xlsx', //can change to html,xls,csv and so on 'grid_mode' => 'export', 'columns' => [ ['class' => 'yii\grid\SerialColumn'], 'code', 'name', 'population', ], ]); }