This README is AI generated for documentation purposes. This project is based on https://github.com/eightyknots/phpspreadsheet-bundle. The source code in this repository is also AI generated.
This bundle integrates PhpSpreadsheet with Symfony applications and provides a simple service-based factory for creating, reading, writing, and streaming spreadsheet files.
It is built around the latest supported PhpSpreadsheet package release in this repository and is intended for Symfony 6 and Symfony 7 applications.
Install the bundle with Composer:
composer require codyas/spreadsheet-bundle
Then enable the bundle in your Symfony application:
// config/bundles.php
return [
SpreadsheetBundle\PhpSpreadsheetBundle\PhpSpreadsheetBundle::class => ['all' => true],
];
The bundle supports a minimal configuration option for enabling Twig helpers:
# config/packages/spreadsheet_bundle.yaml
spreadsheet_bundle:
twig: true
use SpreadsheetBundle\PhpSpreadsheetBundle\Factory\SpreadsheetFactory;
use Symfony\Component\HttpFoundation\Response;
final class ExportController
{
public function __construct(private readonly SpreadsheetFactory $factory)
{
}
public function export(): Response
{
$spreadsheet = $this->factory->createSpreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello Symfony');
$sheet->setCellValue('B1', 'PhpSpreadsheet');
return $this->factory->createStreamedResponse(
$spreadsheet,
'Xlsx',
200,
[
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'Content-Disposition' => 'attachment; filename="export.xlsx"',
]
);
}
}
$spreadsheet = $this->factory->createSpreadsheet('/path/to/file.xlsx');
$reader = $this->factory->createReader('Xlsx');
$writer = $this->factory->createWriter($spreadsheet, 'Csv');
When Twig support is enabled, the bundle registers two Twig functions:
spreadsheet_create() creates a new spreadsheet instancespreadsheet_to_html() renders a spreadsheet as HTMLExample:
{% set spreadsheet = spreadsheet_create() %}
{{ spreadsheet_to_html(spreadsheet) }}
The bundle registers the following service:
spreadsheet_bundle.factoryThe factory class is:
SpreadsheetBundle\PhpSpreadsheetBundle\Factory\SpreadsheetFactoryThis package is licensed under the MIT License.
How can I help you explore Laravel packages today?