kreyu / sonata-exporter-phpspreadsheet-bridge
Integrates PhpSpreadsheet with Sonata Exporter package.
dev-main
2021-01-24 11:49 UTC
Requires
- php: ^7.2
- phpoffice/phpspreadsheet: ^1.16
- sonata-project/exporter: ^2.0.0
This package is auto-updated.
Last update: 2024-12-24 20:36:57 UTC
README
This package integrates PhpSpreadsheet with Sonata Exporter.
$ composer require kreyu/sonata-exporter-phpspreadsheet-bridge
Supported writer formats
- xls
- xlsx
- ods
Note: default Sonata Exporter's .xls writer generates spreadsheet with HTML, which triggers warnings about "possibly corrupted file". Use xls writer from this package to get rid of that problem.
Usage
<?php use Sonata\Exporter\Handler; use Sonata\Exporter\Source\PDOStatementSourceIterator; use Kreyu\SonataExporterPhpSpreadsheetBridge\Writer\XlsWriter; // Prepare the data source $dbh = new \PDO('sqlite:foo.db'); $stm = $dbh->prepare('SELECT id, username, email FROM user'); $stm->execute(); $source = new PDOStatementSourceIterator($stm); // Prepare the writer $writer = new XlsWriter('data.xls'); // Export the data Handler::create($source, $writer)->export();