ruskid / yii2-excel-exporter
Helper to export Active Records to CSV
Installs: 995
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
This package is auto-updated.
Last update: 2024-10-27 09:40:39 UTC
README
This will export Active Records into Excel file
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist ruskid/yii2-excel-exporter "dev-master"
or add
"ruskid/yii2-excel-exporter": "dev-master"
to the require section of your composer.json
file.
Usage
$exporter = new CSVExporter; //Add headers A1-A3 $exporter->setCellValue('A1', 'Subcategoria'); $exporter->setCellValue('A2', 'Propietario'); $exporter->setCellValue('A3', 'Escenario'); //Apply header styles for A1-A3 for ($i = 1; $i <= 3; $i++) { $exporter->setCellStyleFromArray('A' . $i, $exporter->headerStyle); } //Set values to B1-B3 $exporter->setCellValue('B1', $model->name); $exporter->setCellValue('B2', $model->propietario); $exporter->setCellValue('B3', $model->escenario); //Set server data. start from line A11. will return next free cell index $nextCellIndex = $exporter->setCellData('A11', $model->servers, [ [ 'header' => Yii::t('app', 'HOSTNAME'), 'value' => function($array) { return $array['HOSTNAME']; } ], [ 'header' => Yii::t('app', 'DESC_CATALOGO'), 'value' => function($array) { return $array['DESC_CATALOGO']; } ], ]); //set users from next cell free cell index $users = \app\models\User::find()->all(); $exporter->setCellData($nextCellIndex, $users, [ [ 'header' => Yii::t('app', 'Login'), 'value' => function($object) { return $object->username; } ], ]); $exporter->filename = 'test'; return $exporter->export();
- You can also add styling, see style and headerStyle parameters.