slam / php-spreadsheet-helper
PhpSpreadsheet helper to create organized data table
Fund package maintenance!
Slamdunk
paypal.me/filippotessarotto
Requires
- php: ~8.1.0
- phpoffice/phpspreadsheet: ^1.22.0
Requires (Dev)
- infection/infection: ^0.26.5
- malukenho/mcbumpface: ^1.1.5
- phpstan/phpstan: ^1.4.6
- phpstan/phpstan-phpunit: ^1.0.0
- phpunit/phpunit: ^9.5.16
- slam/php-cs-fixer-extensions: ^3.1.0
This package is auto-updated.
Last update: 2022-04-12 06:01:10 UTC
README
Installation
composer require slam/php-spreadsheet-helper
Usage
use Slam\PhpSpreadsheetHelper as ExcelHelper; require __DIR__ . '/vendor/autoload.php'; // Being an `iterable`, the data can be any dinamically generated content // for example a PDOStatement set on unbuffered query $users = [ [ 'column_1' => 'John', 'column_2' => '123.45', 'column_3' => '2017-05-08', ], [ 'column_1' => 'Mary', 'column_2' => '4321.09', 'column_3' => '2018-05-08', ], ]; $columnCollection = new ExcelHelper\ColumnCollection(...[ new ExcelHelper\Column('column_1', 'User', 10, new ExcelHelper\CellStyle\Text()), new ExcelHelper\Column('column_2', 'Amount', 15, new ExcelHelper\CellStyle\Amount()), new ExcelHelper\Column('column_3', 'Date', 15, new ExcelHelper\CellStyle\Date()), ]); $spreadsheet = new PhpOffice\PhpSpreadsheet\Spreadsheet(); $activeSheet = $spreadsheet->getActiveSheet(); $activeSheet->setTitle('My Users'); $table = new ExcelHelper\Table($activeSheet, 1, 1, 'My Heading', $users); $table->setColumnCollection($columnCollection); (new ExcelHelper\TableWriter())->writeTableToWorksheet($table); (new PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet))->save(__DIR__.'/test.xlsx');
Result: