PHPackages                             fastbolt/excel-writer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. fastbolt/excel-writer

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

fastbolt/excel-writer
=====================

A library for simple creation of excel-files

v0.9.0(1y ago)17.1k↓50%1MITPHPPHP ^8.2

Since Jan 11Pushed 1y ago2 watchersCompare

[ Source](https://github.com/fastbolt/excel-writer)[ Packagist](https://packagist.org/packages/fastbolt/excel-writer)[ Docs](https://github.com/fastbolt/ExcelWriter)[ RSS](/packages/fastbolt-excel-writer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (14)Used By (0)

Excel-Writer
============

[](#excel-writer)

This component is used for simple Excel-file generation in Symfony. You can pass either arrays of arrays, or arrays of entities to the generator class. If an entity references another entity as it's attribute, you will need to pass a callable to retrieve a specific value from that entity.

Installation
------------

[](#installation)

This package is available through Composer/Packagist:

```
$ composer require fastbolt/excel-writer
```

Table size
----------

[](#table-size)

The width of the table is set by the number of headers. The number of rows is set by the amount of data.

Columns
-------

[](#columns)

The order of columns is determined by the order of ColumnSetting instances given to ExcelGenerator::setColumns(). You need to define at least one column. The order of the content will not be changed if an array is passed to setContent().

If you are passing objects to setContent(), you will need to provide the name of the method that returns the values you want to display (like "getName").

```
    $columns = [
            new ColumnSetting('Name', ColumnSetting::FORMAT_STRING, 'getName'),
            new ColumnSetting('ID', ColumnSetting::FORMAT_INTEGER, 'getId'),
    ];

    $generator = new ExcelGenerator();
    $file = $generator
                ->setContent($data)
                ->setColumns($columns)
                ->generateSpreadsheet('../var/temp/excelwriter');
```

You can also pass closures instead of the getter.

```
    $columns = [
            new ColumnSetting('Loginname', ColumnSetting::FORMAT_STRING, static function($user) {
               return $user->getLoginname();
            })
        ];
```

\##Style Create an instance of the TableStyle class and set styles for the header row and the content. Pass the TableStyle to the generator.

```
    $headerStyle = [
        'fill' => [
            'fillType' => Fill::FILL_SOLID,
            'color' => array('rgb' => 'FF9933')
        ]
    ];
    $dataRowStyle = [
        'fill' => array(
            'fillType' => Fill::FILL_SOLID,
            'color' => array('rgb' => '66FF66')
        )
    ];

    $style = new TableStyle();
    $style
        ->setHeaderRowHeight(2)
        ->setHeaderStyle($headerStyle)
        ->setDataRowStyle($dataRowStyle);

    $file = $generator
        ->setContent($data)
        ->setColumns($columns)
        ->setStyle($style)
        ->generateSpreadsheet('../var/temp/filename');
```

To apply styles to individual columns, you can either pass the style arrays as the 5th (header style) and 6th (data style) argument to the constructor, or use the setter of the ColumnSettings class.

```
     $headerStyle = [
            'fill' => [
                'fillType' => Fill::FILL_SOLID,
                'color' => array('rgb' => 'FF6622')
            ]
    ];
    $dataStyle = [
            'fill' => array(
                'fillType' => Fill::FILL_SOLID,
                'color' => array('rgb' => '22DD33')
            )
    ];

   //using the constructor
   $column = new ColumnSetting("By Constructor", ColumnSetting::FORMAT_STRING, '', 0, $headerStyle, $dataStyle);

    //using the setters
    $column = new ColumnSetting("Styled Column", ColumnSetting::FORMAT_STRING);
    $column->setHeaderStyle($headerStyle)
           ->setDataStyle($dataStyle);
```

Autofilter
----------

[](#autofilter)

Autofilters can be set by calling the generator's setter method and passing a range:

```
    $generator->setAutoFilterRange("A1:R14");
```

Style presets
-------------

[](#style-presets)

The following styles are presets, but can be overwritten in the TableStyle class

### header

[](#header)

- borders: medium
- vertical-alignment: center
- horizontal-alignment: center
- color: FF366092 (blue)

Merging Cells
-------------

[](#merging-cells)

You can merge cells by passing an array of coordinate ranges to the generator 'mergeCells'-method. The content of the resulting cell will be centered. Calling the method multiple times will not overwrite previous merges.

```
$generator->mergeCells(['A1:B4'])
          ->mergeCells(['P4:T4', 'S1:T1'])
```

Hints
-----

[](#hints)

- Floats have a preset decimal length of 2 (0.12), but that can be configured with the 4th parameter of the ColumnSetting constructor or its method setDecimalLength().
- PHP and Excel have problems working with large numbers. Pass numbers with 16+ digits as strings to string columns to display them correctly.

Example usage
-------------

[](#example-usage)

### Using arrays

[](#using-arrays)

```
    $data = [
        [
            $users[0],            //instance of a user entity
            'Italy',
            new DateTime('NOW')
        ],
        [
            $users[1],           //instance of a user entity
            'France',
            new DateTime('NOW')
        ]
    ];

    //define columns matching the order of the data
    $columns = [
        new ColumnSetting('Login', ColumnSetting::FORMAT_INTEGER, static function($user) {
            return $user->getLoginname();
        }),
        new ColumnSetting('Country', ColumnSetting::FORMAT_STRING),
        new ColumnSetting('Date', ColumnSetting::FORMAT_DATE)
    ];

    //generate
    $generator = new ExcelGenerator();

    $file = $generator
        ->setContent($data)
        ->setColumns($columns)
        ->generateSpreadsheet('../var/temp/filename');
```

### Using objects

[](#using-objects)

```
    $repo = $this->getDoctrine()->getRepository(User::class);
    $users = $repo->findBy(['client' => 5]);

    //define columns matching the order of the data
    $columns = [
        new ColumnSetting('Login', ColumnSetting::FORMAT_INTEGER, 'getLoginName'),
        new ColumnSetting('Country', ColumnSetting::FORMAT_STRING, static function($user) {
            return $user->getCountry()->getName();
        }),
        new ColumnSetting('Created', ColumnSetting::FORMAT_DATE, 'getCreated')
    ];

    //generate
    $generator = new ExcelGenerator();

    $file = $generator
        ->setContent($users)
        ->setColumns($columns)
        ->generateSpreadsheet('../var/temp/filename');
```

### Multiple worksheets

[](#multiple-worksheets)

```
    foreach ($userGroups as $userGroup) {
        $excelGenerator
                    ->setTitle($userGroup->getName())
                    ->setContent($userGroup)
                    ->setColumns($columns)
                    ->nextWorksheet();
    }
    $excelGenerator->generateSpreadsheet('../var/temp/filename');
```

### Full example using objects and adding style

[](#full-example-using-objects-and-adding-style)

```
    $repo  = $this->getDoctrine()->getRepository(User::class);
    $users = $repo->findBy(['client' => 5]);

    //define columns
    $columns = [
        new ColumnSetting('Login', ColumnSetting::FORMAT_INTEGER, 'getLoginName'),
        new ColumnSetting('Country', ColumnSetting::FORMAT_STRING, static function($user) {
            return $user->getCountry()->getName();
        }),
        new ColumnSetting('Created', ColumnSetting::FORMAT_DATE, 'getCreated'),
        new ColumnSetting('Weight', ColumnSetting::FORMAT_FLOAT, 'getWeight', 2)
    ];

    //set style
    $headerStyle = [
        'fill' => [
            'fillType' => Fill::FILL_SOLID,
            'color' => array('rgb' => 'FF9933')
        ]
    ];
    $dataRowStyle = [
        'fill' => array(
            'fillType' => Fill::FILL_SOLID,
            'color' => array('rgb' => '66FF66')
        )
    ];

    $style = new TableStyle();
    $style
        ->setHeaderRowHeight(2)
        ->setHeaderStyle($headerStyle)
        ->setDataRowStyle($dataRowStyle);

    //generate
    $generator = new ExcelGenerator();

    $file = $generator
        ->setContent($users)
        ->setColumns($columns)
        ->setStyle($style)
        ->generateSpreadsheet('../var/temp/filename');

    //download
    $response = new BinaryFileResponse($file->getPathname());
    $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
    return $response;
```

e x c e l - w r i t e r
=======================

[](#e-x-c-e-l---w-r-i-t-e-r)

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 89.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~83 days

Recently: every ~23 days

Total

13

Last Release

593d ago

PHP version history (3 changes)v0.1.0PHP ~7.4

v0.4.1PHP ^7.4 || ^8.1

v0.7.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/d04d2a04687b8ad9bdde03c59ce18b5e627eee453efbc9a526ec6bc84a943c87?d=identicon)[dhirtzbruch](/maintainers/dhirtzbruch)

![](https://www.gravatar.com/avatar/08e403cc538787b1ce4086fae664cccd974df987985abd823ad16e09a4803653?d=identicon)[slk](/maintainers/slk)

---

Top Contributors

[![StvL97](https://avatars.githubusercontent.com/u/95848687?v=4)](https://github.com/StvL97 "StvL97 (80 commits)")[![dhirtzbruch](https://avatars.githubusercontent.com/u/426308?v=4)](https://github.com/dhirtzbruch "dhirtzbruch (9 commits)")

---

Tags

dataexcelexcel-exportexcelwriterexcel-writerfastbolt

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/fastbolt-excel-writer/health.svg)

```
[![Health](https://phpackages.com/badges/fastbolt-excel-writer/health.svg)](https://phpackages.com/packages/fastbolt-excel-writer)
```

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.7k144.3M712](/packages/maatwebsite-excel)[shuchkin/simplexlsxgen

Export data to Excel XLSx file. PHP XLSX generator.

1.1k2.2M16](/packages/shuchkin-simplexlsxgen)[faisalman/simple-excel-php

Easily parse / convert / write between Microsoft Excel XML / CSV / TSV / HTML / JSON / etc formats

582599.4k1](/packages/faisalman-simple-excel-php)[moonlandsoft/yii2-phpexcel

Exporting PHP to Excel or Importing Excel to PHP

1491.1M16](/packages/moonlandsoft-yii2-phpexcel)[yidas/phpspreadsheet-helper

PHP Excel Helper - Write and read Spreadsheet with easy way based on PhpSpreadsheet

383144.5k3](/packages/yidas-phpspreadsheet-helper)[nimmneun/onesheet

OneSheet is a fast and lightweight single/multi sheet excel/xlsx file writer for PHP 5.4+ (until v1.2.6), PHP 7 &amp; PHP 8 with styling and cell auto-sizing support.

46403.8k3](/packages/nimmneun-onesheet)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
