moveek / excel-bundle
Symfony Bundle to read or write Excel file (including pdf, xlsx, odt), using phpoffice/phpspreadsheet library (replacement of phpoffice/phpexcel, abandonned)
Installs: 2 758
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 8
Type:symfony-bundle
pkg:composer/moveek/excel-bundle
Requires
- php: >=7.1.3
 - phpoffice/phpspreadsheet: ~1.0
 - symfony/config: ^5.4
 - symfony/dependency-injection: ^5.4
 - symfony/framework-bundle: ^5.4
 - symfony/http-foundation: ^5.4
 - symfony/http-kernel: ^5.4
 
Requires (Dev)
- php: >=7.0
 - phpunit/phpunit: ~6.5
 - sensio/framework-extra-bundle: ^5.4
 - squizlabs/php_codesniffer: ~2
 
Suggests
- onurb/doctrine-yuml-bundle: Use this bundle to generate mapping graph from your entities
 
README
Installation
1  Add to composer.json to the require key
composer require onurb/excel-bundle
or manually in composer.json
..., "require": { ..., "onurb/excel-bundle": "~1.0" }, ...
2 Symfony 3 : Register the bundle in app/AppKernel.php
$bundles = array( // ... new \Onurb\Bundle\ExcelBundle\OnurbExcelBundle(), );
Symfony 4 : With symfony flex, bundle should be already automatically registered :
// config/bundles.php return [ // ... Onurb\Bundle\ExcelBundle\OnurbExcelBundle::class => ['all' => true], ];
Usage
Create a spreadsheet
$spreadsheet = $this->get('phpspreadsheet')->createSpreadsheet();
Create a spreadsheet from an existing file
$spreadsheet = $this->get('phpspreadsheet')->createSpreadsheet('file.xlsx');
Create a Excel5 and write to a file given the object:
$writer = $this->get('phpspreadsheet')->createWriter($spreadsheet, 'Xls'); $writer->save('file.xls');
Create a Excel 2007 and create a StreamedResponse:
$writer = $this->get('phpspreadsheet')->createWriter($spreadsheet, 'Xlsx'); $response = $this->get('phpspreadsheet')->createStreamedResponse($writer);
Create a Excel file with an image:
$writer = $this->get('phpspreadsheet')->createSpreadSheet(); $writer->setActiveSheetIndex(0); $activesheet = $writer->getActiveSheet(); $drawingobject = $this->get('phpspreadsheet')->createSpreadsheetWorksheetDrawing(); $drawingobject->setPath('/path/to/image') ->setName('Image name') ->setDescription('Image description') ->setHeight(60) ->setOffsetY(20) ->setCoordinates('A1') ->setWorksheet($activesheet);
Create reader
$reader = $this->get('phpspreadsheet')->createReader('Xlsx');
Supported file types
Types are case sensitive. Supported types are:
Xlsx: Excel 2007Xls: Excel 5Xml: Excel 2003 XMLSlk: Symbolic Link (SYLK)Ods: Libre Office (ODS)Csv: CSVHtml: HTML
Optional libraries can be installed for writing:
TcpdfMpdfDompdf
to install these libraries :
composer require tecnick.com/tcpdf composer require mpdf/mpdf composer require dompdf/dompdf
liuggio/Excelbundle portability
For users already using liuggio/ExcelBundle wanting to migrate to phpspreadsheet, the bundle should be directly compatible : old phpexcel file types are maintained, a compatibility factory has been added, and the phpexcel service is also redeclared.
More
See also the official PhpSpreadsheet documentation.