denisristic / excel-service-provider
A wrapper for PHPExcel usage in Silex 2 projects
0.1.1
2016-09-21 10:58 UTC
Requires
- php: >=5.4.0
- doctrine/dbal: ^2.5
- phpoffice/phpexcel: ^1.8
- pimple/pimple: ~3.0
- ramsey/array_column: ^1.1
- silex/silex: ~2.0
This package is not auto-updated.
Last update: 2024-12-30 07:44:06 UTC
README
Introduction
This service provider for Silex allows you to quickly generate Excel (*.xls) spreadsheets. Either pass in a query result set, and a list of headers, or use the Doctrine functionality to convert a table to a spreadsheet.
This project has ben ported from https://github.com/deanc/ExcelServiceProvider
Installation
Require the provider using composer
:
composer require denisristic/excel-service-provider
Register the provider in your application somewhere:
$app->register(new \denisristic\ExcelServiceProvider\Provider\ExcelServiceProvider());
Usage
Generate a spreadsheet from a table (if you are using the DoctrineServiceProvider
):
$excel = $app['excel']->generateXLSFromTable('tableName');
Generate a spreadsheet manually:
$headers = array('ID', 'Name', 'Created'); $data = array( 0 => array('id' => 1, 'name' => 'Bill Gates', 'created' => '2015-01-01 00:00'), 1 => array('id' => 2, 'name' => 'Steve Jobs', 'created' => '2015-01-02 00:00'), 2 => array('id' => 3, 'name' => 'Bill Murray', 'created' => '2015-01-03 00:00') ); $excel = $app['excel']->generateXLS($headers, $data);
Forcing a download of the spreadsheet:
$controllers->get('/download', function () use($app) { $excel = $app['excel']->generateXLSFromTable('entry'); $xlsName = 'entries-' . date('Y-m-dhis') . '.xls'; $response = new Response($excel); $response->headers->add(array( 'Content-Type' => 'application/vns.ms-excel' ,'Content-Disposition' => 'inline; filename="' . $xlsName . '"' ,'Pragma' => 'no-cache' ,'Expired' => 0 )); return $response; })->bind('download');