• Stars
    star
    374
  • Rank 114,346 (Top 3 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 13 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Excel integration in Symfony2 thanks to https://github.com/PHPOffice/PHPExcel library

Symfony2 Excel bundle

This bundle permits you to create, modify and read excel objects.

Build Status Total Downloads Latest Stable Version Latest Unstable Version

License

License

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: http://php.net/manual-lookup.php?pattern=csv&lang=en&scope=quickref

Installation

1 Add to composer.json to the require key

    $composer require liuggio/excelbundle

2 Register the bundle in app/AppKernel.php

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

TL;DR

  • 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');
$writer->save('file.xls');
  • Create a Excel5 and create a StreamedResponse:
$writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5');
$response = $this->get('phpexcel')->createStreamedResponse($writer);
  • Create a Excel file with an image:
$writer = $this->get('phpexcel')->createPHPExcelObject();
$writer->setActiveSheetIndex(0);
$activesheet = $writer->getActiveSheet();

$drawingobject = $this->get('phpexcel')->createPHPExcelWorksheetDrawing();
$drawingobject->setName('Image name');
$drawingobject->setDescription('Image description');
$drawingobject->setPath('/path/to/image');
$drawingobject->setHeight(60);
$drawingobject->setOffsetY(20);
$drawingobject->setCoordinates('A1');
$drawingobject->setWorksheet($activesheet)

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'

Example

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 https://github.com/PHPOffice/PHPExcel/tree/develop/Examples

For lazy devs

namespace YOURNAME\YOURBUNDLE\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;

class DefaultController extends Controller
{

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

       $phpExcelObject->getProperties()->setCreator("liuggio")
           ->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");
       $phpExcelObject->setActiveSheetIndex(0)
           ->setCellValue('A1', 'Hello')
           ->setCellValue('B2', 'world!');
       $phpExcelObject->getActiveSheet()->setTitle('Simple');
       // Set active sheet index to the first sheet, so Excel opens this as the first sheet
       $phpExcelObject->setActiveSheetIndex(0);

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

        return $response;        
    }
}

Contributors

the list of contributors

Contribute

  1. fork the project
  2. clone the repo
  3. get the coding standard fixer: wget http://cs.sensiolabs.org/get/php-cs-fixer.phar
  4. before the PullRequest you should run the coding standard fixer with php php-cs-fixer.phar fix -v .

More Repositories

1

fastest

Simple parallel testing execution... with some goodies for functional tests.
PHP
473
star
2

StatsDClientBundle

Easily monitor your symfony2 production env., with ready-to-use stats.
PHP
164
star
3

symfony2-rest-api-the-best-2013-way

Code for the article at:
PHP
152
star
4

statsd-php-client

Statsd (Object Oriented) client library for PHP
PHP
114
star
5

spawn

Handling concurrent PHP processes
PHP
29
star
6

DDD-dummy-blog-with-symfony2

PHP
29
star
7

HelpDeskBundle

NOT MANTAINED!!!! Open source support ticket system. (Symfony2 bundle)
JavaScript
24
star
8

sized140

Something like a framework in PHP with 6 components of 140 chars
PHP
18
star
9

liuggio.github.com

My personal blog on jekyll
HTML
8
star
10

Ultra-Lightweight-Dependency-Injector-Python

Lightweight Dependency Injector Setter Python -10 lines! Tiny DIS in Python.
8
star
11

RackspaceCloudFilesBundle

[MOVED!!!!! see tvision/RackspaceCloudFilesBundle ]Symfony2 bundle to manage Rackspace Cloud Files, This Bundle borns as fork of the escapestudios/EscapeRackspaceCloudFilesBundle, now these two bundles are very different.
PHP
8
star
12

filler-dto

Retrieve and set properties from and to a DTO.
PHP
7
star
13

godfather

[moved to PUGX] library that helps you with the Strategy Pattern
PHP
6
star
14

events

Crazy Fast Event Dispatcher for Golang - Be careful no reflection here...
Go
5
star
15

KnpMenuExtensionBundle

[USE KNP-MENU-BUNDLE THEY ADDED THE YML FUNCTIONALITY ]Extends the KnpMenu, you can configure, create or add nodes to the menu from any bundle, only adding rows in the bundle's config file
PHP
4
star
16

docker-workshop-orchestration

Container orchestration workshop
Shell
3
star
17

deBergmannizer

This is a stupid tool that removes the name of the creator from PHPUnit.
3
star
18

http

Trying to define a standard for the HttpInterface and middlewares.
PHP
3
star
19

docker-workshop

Full Day Workshop about Docker and Bashism
Shell
2
star
20

phpspec2-playground

PHPSpec2 by examples. Just a place to play as a kid, with BDD in PHP
PHP
2
star
21

UserBundle

Instance of the UserBundle read https://github.com/FriendsOfSymfony/FOSUserBundle
2
star
22

golang-stupid-microservice

just a microservice playground
Go
2
star
23

backupMysqlEnv

move database tables between the dev, test, live environment or just gzip
Shell
1
star
24

s3sync

Docker container: backup and sync folder into a Aws S3 bucket.
Shell
1
star
25

RackspaceCloudFilesStreamWrapper

MOVED TO TVISION Library to stream file for rackspace
PHP
1
star
26

git-current-branch-bashrc

Add the current git branch to bashrc
1
star
27

xwc-sandbox

OBSOLETE CODE - xwc-sanbox is an attempt to create a modular CMS running on symfony2, allowing to easily create sites from ready made components (bundles)
PHP
1
star
28

EmenseneImageTimer

< ~2008 / DEPRECATED - This simple(stupid) plug-in allows you to update (at time intervals) your emesene avatar by picking one image from the images folder.
Python
1
star