codyas/spreadsheet-bundle

A Symfony bundle to integrate with PHPOffice's PhpSpreadsheet library

Maintainers

Package info

github.com/codyas-team/spreadsheet-bundle

Type:symfony-bundle

pkg:composer/codyas/spreadsheet-bundle

Transparency log

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-master 2026-07-16 14:58 UTC

This package is not auto-updated.

Last update: 2026-07-17 13:15:53 UTC


README

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.

Features

  • Provides a reusable Spreadsheet factory service
  • Creates new spreadsheets or loads existing files
  • Creates readers and writers for supported PhpSpreadsheet formats
  • Streams spreadsheet downloads as Symfony responses
  • Optional Twig integration with helper functions

Requirements

  • PHP 8.2 or higher
  • Symfony 6.0 or 7.0
  • PhpSpreadsheet ^5.9

Installation

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],
];

Configuration

The bundle supports a minimal configuration option for enabling Twig helpers:

# config/packages/spreadsheet_bundle.yaml
spreadsheet_bundle:
    twig: true

Usage

Inject the factory service

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"',
            ]
        );
    }
}

Load an existing spreadsheet

$spreadsheet = $this->factory->createSpreadsheet('/path/to/file.xlsx');

Create a reader or writer

$reader = $this->factory->createReader('Xlsx');
$writer = $this->factory->createWriter($spreadsheet, 'Csv');

Twig integration

When Twig support is enabled, the bundle registers two Twig functions:

  • spreadsheet_create() creates a new spreadsheet instance
  • spreadsheet_to_html() renders a spreadsheet as HTML

Example:

{% set spreadsheet = spreadsheet_create() %}
{{ spreadsheet_to_html(spreadsheet) }}

Service reference

The bundle registers the following service:

  • spreadsheet_bundle.factory

The factory class is:

  • SpreadsheetBundle\PhpSpreadsheetBundle\Factory\SpreadsheetFactory

License

This package is licensed under the MIT License.