gri3li / yii2-grid-file
This Yii2 extension provides ability to export data form data provider to format supported by PhpSpreadsheet
Installs: 872
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 0
Type:yii2-extension
Requires
- phpoffice/phpspreadsheet: 1.*
- yiisoft/yii2: 2.*
This package is auto-updated.
Last update: 2025-03-29 00:41:05 UTC
README
This Yii2 extension provides ability to export data form instances of yii\data\DataProviderInterface
to format supported by PhpSpreadsheet
Installation
Install the package via Composer:
composer require gri3li/yii2-grid-file
Usage
$export = new \gri3li\yii2gridfile\GridFile([ 'dataProvider' => new \yii\data\ArrayDataProvider([ 'allModels' => [ [ 'name' => 'some name', 'date' => 1538571363, ], [ 'name' => 'name 2', 'date' => 1538571363, ], ], ]), 'columns' => [ 'name', 'date:datetime', ], 'headerCellStyle' => [ 'font' => ['bold' => true], 'fill' => [ 'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, 'startColor' => ['rgb' => 'CCCCCC'], ], ], ]); $export->saveAs(\PhpOffice\PhpSpreadsheet\Writer\Xls::class, '/path/to/file.xls'); // $export->saveAs(\PhpOffice\PhpSpreadsheet\Writer\Xlsx::class, '/path/to/file.xlsx'); // $export->saveAs(\PhpOffice\PhpSpreadsheet\Writer\Ods::class, '/path/to/file.ods'); // $export->saveAs(\PhpOffice\PhpSpreadsheet\Writer\Html::class, '/path/to/file.html'); // $export->saveAs(\PhpOffice\PhpSpreadsheet\Writer\Csv::class, '/path/to/file.csv');
More info about phpspreadsheet style https://phpspreadsheet.readthedocs.io/en/latest/topics/recipes/#styles
Use case https://github.com/gri3li/yii2-grid-file/tree/master/example
For run use case:
cd vendor/gri3li/yii2-grid-file/example/
php -S 127.0.0.1:8877