Install the library

This guide will walk you through installing Derafu Spreadsheet and its dependencies.

Basic Installation

The simplest way to install Derafu Spreadsheet is through Composer:

composer require derafu/spreadsheet

This installs the core package. Out of the box, only works with JSON and XML. Depending on which file formats you want to work with, you may need to install additional dependencies.

Format-Specific Dependencies

Derafu Spreadsheet supports multiple formats through different handlers. Each format may require additional dependencies:

CSV Support

For CSV support, you can choose between two handlers:

# Recommended: League CSV (faster, more memory efficient).
composer require league/csv

# Alternative: PhpSpreadsheet CSV handling.
composer require phpoffice/phpspreadsheet

Excel and OpenDocument Support

For XLSX, XLS, and ODS support:

composer require phpoffice/phpspreadsheet

YAML Support

For YAML support:

composer require symfony/yaml

PDF Support

For PDF export:

# Base requirement.
composer require phpoffice/phpspreadsheet

# Choose one PDF library:
composer require mpdf/mpdf        # For MpdfWriter (recommended).
# OR
composer require dompdf/dompdf    # For DompdfWriter.
# OR
composer require tecnickcom/tcpdf # For TcpdfWriter.

HTTP Response Support

For PSR-7 HTTP response integration:

composer require nyholm/psr7

If you don’t want to use nyholm/psr7, you can use any PSR-7 compatible library implementing by your own SpreadsheetHttpResponseGeneratorInterface.

Complete Installation (All Formats)

If you want to support all formats, with the default handlers, you can install all dependencies at once:

composer require derafu/spreadsheet league/csv phpoffice/phpspreadsheet \
    symfony/yaml mpdf/mpdf nyholm/psr7

Installation in Frameworks

Symfony

To use Derafu Spreadsheet in Symfony, install the package:

composer require derafu/spreadsheet

Then define services in your services.yaml:

services:
    Derafu\Spreadsheet\Contract\SpreadsheetFactoryInterface:
        class: Derafu\Spreadsheet\Factory

    Derafu\Spreadsheet\Contract\SpreadsheetCasterInterface:
        class: Derafu\Spreadsheet\Caster

    Derafu\Spreadsheet\Contract\SpreadsheetLoaderInterface:
        class: Derafu\Spreadsheet\Loader
        arguments:
            - '@Derafu\Spreadsheet\Factory'
            - '@Derafu\Spreadsheet\Caster'

    Derafu\Spreadsheet\Contract\SpreadsheetDumperInterface:
        class: Derafu\Spreadsheet\Dumper
        arguments:
            - '@Derafu\Spreadsheet\Factory'
            - '@Derafu\Spreadsheet\Caster'

Check the constructors of the classes to see what arguments they expect. You can configure them as you want, for example change the delimiter for CSV.