slam / openspout-helper
PhpSpreadsheet helper to create organized data table
Fund package maintenance!
Slamdunk
paypal.me/filippotessarotto
Installs: 11 200
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 4
Forks: 1
Open Issues: 1
Requires
- php: ~8.3.0 || ~8.4.0
- openspout/openspout: ^4.26.0
Requires (Dev)
- infection/infection: ^0.29.6
- phpoffice/phpspreadsheet: ^2.2.2
- phpstan/phpstan: ^1.12.4
- phpstan/phpstan-phpunit: ^1.4.0
- phpunit/phpunit: ^11.3.6
- slam/php-cs-fixer-extensions: ^3.12.0
README
Installation
composer require slam/openspout-helper
Usage
use OpenSpout\Writer\Common\Creator\WriterEntityFactory; use Slam\OpenspoutHelper 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()), ]); $XLSXWriter = WriterEntityFactory::createXLSXWriter(); $XLSXWriter->openToFile(__DIR__.'/test.xlsx'); $activeSheet = $XLSXWriter->getCurrentSheet(); $activeSheet->setName('My Users'); $table = new ExcelHelper\Table($activeSheet, 'My Heading', $users); $table->setColumnCollection($columnCollection); (new ExcelHelper\TableWriter())->writeTable($XLSXWriter, $table); $XLSXWriter->close();
Result: