deanc / excel-service-provider
A wrapper for PHPExcel usage in Silex projects
Installs: 12 685
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 2
Requires
- php: >=5.4.0
- doctrine/dbal: ^2.5
- phpoffice/phpexcel: ^1.8
- ramsey/array_column: ^1.1
- silex/silex: ~1.3
This package is not auto-updated.
Last update: 2025-01-04 20:31: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.
Installation
Require the provider using composer
:
composer require deanc/excel-service-provider
Register the provider in your application somewhere:
$app->register(new \DC\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, $results);
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');