Question

I need to generate Excel files, I did a search and phpexcel seems to be good and stable. I'd like to know: * how to integrate it into my project given that it's a symfony2.0 project * if I can do all what I do normally on excel file through this php library (cells colors, adding lists ...)

Thanks,

Was it helpful?

Solution

If you are using composer, and since PHPExcel is registered with Packagist, then this is simply a matter of adding PHPExcel to your composer.json config, for example:

"require": {
    "php": ">=5.3.3",
    "symfony/symfony": "~2.4",
    "doctrine/orm": "~2.2,>=2.2.3",
    ...
    "phpoffice/phpexcel": "~1.8.0",

This is from a Symfony 2.4 configuration, but should work equally well for any version of Symfony.

Run $ php composer.phar update to grab the package and it should then be autoloaded into your project. You can then use PHPExcel immediately, say in a controller:

<?php
namespace SomeProject\SomeBundle\Controller;
use PHPExcel;

Or just reference \PHPExcel directly from within your code.

Update:

Note that composer found it's way into Symfony from around version 2.0.4, and was used as an alternative to the old deps and deps.lock files until the deps approach was deprecated from 2.1.

If you're still using deps, you can append this to your deps file:

[PHPExcel]
    git=git://github.com/PHPOffice/PHPExcel.git
    target=phpexcel

and run php bin/vendors install. This will put the PHPExcel in vendors/phpexcel.

Register PHPExcel with the registerPrefixes array in app/autoload.php and it should be available to your project as described above.

$loader->registerPrefixes(array(
    'Twig_Extensions_' => __DIR__.'/../vendor/twig-extensions/lib',
    'Twig_'            => __DIR__.'/../vendor/twig/lib',
    'PHPExcel'         => __DIR__.'/../vendor/phpexcel/Classes'
));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top