kreyu/sonata-exporter-phpspreadsheet-bridge

Integrates PhpSpreadsheet with Sonata Exporter package.

dev-main 2021-01-24 11:49 UTC

This package is auto-updated.

Last update: 2021-02-24 12:02:50 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();