Developed with love by KnpLabs Hire us for your project!


by liuggio

Symfony2 Really Excel integration

Symfony2 Excel bundle

Build Status
Total Downloads
Latest Stable Version
Latest Unstable Version

This bundle permits you to create an easily modifiable excel object.

Version 2

This is the shiny new version.
There is a big BC with the 1.* version, but unit tests, functional tests, and the new factory is very simple to use.

Version 1.*

If you have installed an old version, and you are happy to use it, you could find documentation and files
in the tag v1.0.6,
browse the code.

Things to know:

CSV is faster so if you have to create simple xls file,
I encourage you to use the built-in function for csv:


1 Add to composer.json to the require key

    "require" : {
        "liuggio/excelbundle": "~2.0",

2 Register the bundle in app/AppKernel.php

    $bundles = array(
        // ...
        new Liuggio\ExcelBundle\LiuggioExcelBundle(),


  • Create an empty object:
$phpExcelObject = $this->get('phpexcel')->createPHPExcelObject();
  • Create an object from a file:
$phpExcelObject = $this->get('phpexcel')->createPHPExcelObject('file.xls');
  • Create a Excel5 and write to a file given the object:
$writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5');
  • Create a Excel5 and create a StreamedResponse:
$writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5');
$response = $writer->createStreamedResponse($writer);

Not Only 'Excel5'

The list of the types are:

  1. 'Excel5'
  2. 'Excel2007'
  3. 'Excel2003XML'
  4. 'OOCalc'
  5. 'SYLK'
  6. 'Gnumeric'
  7. 'HTML'
  8. 'CSV'


Fake Controller

The best place to start is the fake Controller at Tests/app/Controller/FakeController.php, that is a working example.

More example

You could find a lot of examples in the official PHPExcel repository

For lazy devs

namespace YOURNAME\YOURBUNDLE\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller

    public function indexAction($name)
        // ask the service for a Excel5
       $phpExcelObject = $this->get('phpexcel')->createPHPExcelObject();

           ->setLastModifiedBy("Giulio De Donato")
           ->setTitle("Office 2005 XLSX Test Document")
           ->setSubject("Office 2005 XLSX Test Document")
           ->setDescription("Test document for Office 2005 XLSX, generated using PHP classes.")
           ->setKeywords("office 2005 openxml php")
           ->setCategory("Test result file");
           ->setCellValue('A1', 'Hello')
           ->setCellValue('B2', 'world!');
       // Set active sheet index to the first sheet, so Excel opens this as the first sheet

        // create the writer
        $writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5');
        // create the response
        $response = $this->get('phpexcel')->createStreamedResponse($writer);
        // adding headers
        $response->headers->set('Content-Type', 'text/; charset=utf-8');
        $response->headers->set('Content-Disposition', 'attachment;filename=stream-file.xls');
        $response->headers->set('Pragma', 'public');
        $response->headers->set('Cache-Control', 'maxage=1');

        return $response;        


the list of contributors


  1. fork the project
  2. clone the repo
  3. get the coding standard fixer: wget
  4. before the PullRequest you should run the coding standard fixer with php php-cs-fixer.phar fix -v .
liuggio_excel:        []
  • Merge pull request #34 from Squazic/master
    By liuggio, 1 year ago
  • Change formatting of require
    By Squazic, 1 year ago
  • Remove unnecessary parts of readme, fix typos
    By Squazic, 1 year ago
  • Merge pull request #33 from jebbench/master
    By liuggio, 1 year ago
  • Update composer.json
    By jebbench, 1 year ago
  • Merge pull request #27 from Nercury/master
    By liuggio, 1 year ago