PHPackages                             denisok94/symfony-export-xlsx - 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. denisok94/symfony-export-xlsx

ActiveSymfony-bundle

denisok94/symfony-export-xlsx
=============================

Symfony export for excel(.xlsx)

0.0.8(1y ago)17.6k↓25%1MITPHP

Since Aug 11Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/Denisok94/symfony-export-xlsx)[ Packagist](https://packagist.org/packages/denisok94/symfony-export-xlsx)[ RSS](/packages/denisok94-symfony-export-xlsx/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (10)Used By (1)

Symfony export xlsx
===================

[](#symfony-export-xlsx)

The main idea is taken from [XlsxWriter.php](https://gist.github.com/kunicmarko20/e0292280344761efbc7ff376f7080fec).

Except:

- PHPOffice\\PHPExcel has been replaced with PHPOffice\\PhpSpreadsheet;
- The class is used as a service to be able to use it anywhere and make changes to the file.
- The `XlsxService` class is completely independent and can be used outside of Symfony.

[![license-MIT-green](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)

1. [Install](#install)
2. [Use Service](#use-service)
3. [Customization](#customization)
4. [Use in SonataAdmin Export](#use-in-sonataadmin-export)
5. [Errors](#errors)

Install
-------

[](#install)

Run:

```
composer require --prefer-dist denisok94/symfony-export-xlsx
# or
php composer.phar require --prefer-dist denisok94/symfony-export-xlsx
```

or add to the `require` section of your `composer.json` file:

```
"denisok94/symfony-export-xlsx": "*"
```

```
composer update
# or
php composer.phar update
```

Use XlsxService
---------------

[](#use-xlsxservice)

MethodParametersReturnDescriptionsetFile()stringselfsetDateTimeFormat()stringselfopen()--write()array-close()--```
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use \Denisok94\SymfonyExportXlsxBundle\Service\XlsxService;

class ExportController extends AbstractController
{
    /** @var XlsxService */
    private $export;
    /**
     * @param XlsxService $export
     */
    public function __construct(XlsxService $export)
    {
        $this->export = $export;
    }
    /**
     * @return Response
     */
    public function index(): Response
    {
        $fileName = 'my_first_excel.xlsx';
        $temp_file = tempnam(sys_get_temp_dir(), $fileName);
        $this->export->setFile($temp_file)->open();
        $test = [
            ['header1' => 'value1', 'header2' => 'value2', 'header3' => 'value3'],
            ['header1' => 'value4', 'header2' => 'value5', 'header3' => 'value6']
        ];
        foreach ($test as $line) {
            $this->export->write($line);
        }
        $this->export->close();
        return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
    }
}
```

[![Example of a result](doc/0000.PNG)](doc/0000.PNG)

Customization
-------------

[](#customization)

MethodReturnOfficial DocumentationgetProperties()Class PropertiesgetSpreadsheet()Class SpreadsheetgetActiveSheet()Class Worksheet```
use \Denisok94\SymfonyExportXlsxBundle\Service\XlsxService;
/** @var XlsxService */
private $export;
/**
 * @param XlsxService $export
 */
public function __construct(XlsxService $export)
{
    $this->export = $export;
}
/**
 * @return Response
 */
public function index(): Response
{
    $fileName = 'my_first_excel.xlsx';
    $temp_file = tempnam(sys_get_temp_dir(), $fileName);
    $this->export->setFile($temp_file)->open();

    //
    $this->export->getProperties()
        ->setCreator('Denis')
        ->setLastModifiedBy('Denis')
        ->setSubject('my_first_excel')
        ->setTitle('my_first_excel');

    $test = [
        ['header1' => 'value1', 'header2' => 'value2', 'header3' => 'value3'],
        ['header1' => '4', 'header2' => '5', 'header3' => '=A3+B3']
    ];
    // header1 (A1) / header2 (B1) / header3 (C1)
    // value1 (A2) / value2 (B2) / value3 (C2)
    // 4 (A3) / 5 (B3) / =A3+B3 (C3)
    foreach ($test as $line) {
        $this->export->write($line);
    }

    // https://phpoffice.github.io/PhpSpreadsheet/classes/PhpOffice-PhpSpreadsheet-Worksheet-Worksheet.html#method_mergeCells
    $this->export->getActiveSheet()->mergeCells('B2:C2');

    // https://phpoffice.github.io/PhpSpreadsheet/classes/PhpOffice-PhpSpreadsheet-Style-Borders.html
    $this->export->getActiveSheet()
        ->getStyle('A2:C3')->getBorders()->applyFromArray(['allBorders' => ['borderStyle' => 'thin', 'color' => ['rgb' => '000000']]]);

    // https://phpoffice.github.io/PhpSpreadsheet/classes/PhpOffice-PhpSpreadsheet-Style-Color.html
    $this->export->getActiveSheet()
        ->getStyle('C3')->getFont()->getColor()->applyFromArray(['rgb' => 'FF0000FF']);

    $this->export->close();

    return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
}
```

[![Example of a result](doc/0001.PNG)](doc/0001.PNG)

### Table class

[](#table-class)

```
use Denisok94\SymfonyExportXlsxBundle\DBAL\Table as T;
$worksheet = $this->export->getActiveSheet();
//
$value = $worksheet->getCell([T::A, 1])->getValue(); // A:1
$worksheet->getCell([T::B, 2])->setValue($value); // B:2
//
$x = T::B;
while ($x getCell([$x, $y])->setValue($value);
    } catch (\Throwable $th) {
        throw new \RuntimeException('error set "' . T::getLetter($x) . ':' . $y . '":' . $th->getMassage());
    }
    $x++;
}
```

Use in SonataAdmin Export
-------------------------

[](#use-in-sonataadmin-export)

Install if missing `SonataExporterBundle`

```
composer require sonata-project/exporter
```

Minimum version **`doctrine/orm`: 2.8**

add in `config`:

```
# ~config/packages/sonata_exporter.yaml
services:
  sonata.exporter.writer.xlsx:
    class: Denisok94\SymfonyExportXlsxBundle\Writer\XlsxWriter
    arguments: ["php://output"]
    tags:
      - { name: sonata.exporter.writer }
```

add in `YourAdmin` class [according to the documentation](https://docs.sonata-project.org/projects/SonataAdminBundle/en/4.x/reference/action_export/):

```
public function getExportFormats(): array
{
    return ['xlsx'];
}
```

and if you need to configure the fields and their translation

```
protected function configureExportFields(): array
{
    // example:
    return [
        $this->trans('export.title') => 'title',
        $this->trans('export.anons') => 'text',
        $this->trans('export.date') => 'date'
    ];
}
```

Errors
------

[](#errors)

If you see the error:

```
Attempted to call an undefined method named "toIterable" of class "Doctrine\ORM\Query"

```

Then make sure that the **`doctrine/orm`** version is **`2.8`** or **higher**.

You may need to update:

- sonata-project/admin-bundle: ~`3.*`
- sonata-project/doctrine-orm-admin-bundle: ~`3.*`
- doctrine/doctrine-bundle: ~`^2.3`

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance56

Moderate activity, may be stable

Popularity25

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~143 days

Recently: every ~211 days

Total

8

Last Release

373d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/59793012?v=4)[Денис](/maintainers/Denisok94)[@Denisok94](https://github.com/Denisok94)

---

Top Contributors

[![Denisok94](https://avatars.githubusercontent.com/u/59793012?v=4)](https://github.com/Denisok94 "Denisok94 (5 commits)")

---

Tags

export-excelexport-to-excelphp-excelphp-export-excelphp-xlsxsymfony-bundlesymfony4xlsx-exportsymfony exportsymfony export excelsymfony export xlsxexport xlsxsymfony xlsxSonataAdmin export excelSonataAdmin export xlsxSonataAdmin xlsx

### Embed Badge

![Health badge](/badges/denisok94-symfony-export-xlsx/health.svg)

```
[![Health](https://phpackages.com/badges/denisok94-symfony-export-xlsx/health.svg)](https://phpackages.com/packages/denisok94-symfony-export-xlsx)
```

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.7k144.3M712](/packages/maatwebsite-excel)[craftcms/cms

Craft CMS

3.6k3.6M2.6k](/packages/craftcms-cms)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[kimai/kimai

Kimai - Time Tracking

4.6k7.4k1](/packages/kimai-kimai)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[in2code/powermail

Powermail is a well-known, editor-friendly, powerful and easy to use mailform extension for TYPO3 with a lots of features

982.5M38](/packages/in2code-powermail)

PHPackages © 2026

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