Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Spreadsheet Bundle Laravel Package

codyas/spreadsheet-bundle

View on GitHub
Deep Wiki
Context7

PhpSpreadsheet Bundle for Symfony

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.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums
rlacerda83/query-parser
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings