2013-07-10

This is an example for how to create Excel File with PHPExcel library.This article is inspired by Wikki Article return by Antonio Ramirez and extension created by marcovtwout for PHPExcel library.

So, my sincere thanks to Antonio Ramirez and marcovtwout for their contribution and time which they have spent to fix this PHPExcel issue with the implementation in Yii.

In this Wikki Article i am trying to include few more example like inserting image in excel,Creating a new sheet, Use of Template to create new Sheet..

Here is the step by step tutorial for creating a PHP Excel file with the help of PHPExcel Library and extension created by marcovtwout

Step 1 : Download Yii-phpexcel extension

Step 2 : (As suggested on yii-phpextension extension download page)Unzip the contents of this directory to protected/extensions/phpexcel.

Step 3 : ( As suggested on yii-phpextension extension download page) Download Latest version of PHPExcel Library from this link

Step 4 : (As suggested on yii-phpextension extension download page) Unzip the contents of the folder Classes to a new folder protected/extensions/phpexcel/vendor

Step 5 : Create an Action in Controller file. with below given code

Step 6 : Now execute controller action. And That's it you will get excelsheet ready for download. :)

Create New Sheet in Current Excel File :-

To Create new Sheet in Current Excel File you can simply use below given code before exporting a document code in above above given example code for controller action.

Insert Image In ExcelSheet :-

To Insert an image in excelsheet use below given code.

Use template to create Excel Sheet :-

To Use Template to create a Excelsheet. change below given code in controller action.
use below given code

Instead of

This code will load a template

Note : Make sure that it is pointing to the correct path where a template file is placed.

For Further References and examples you can refer PHPExcel Official Example Section.

I hope this article would be helpful for few people.:)

Thanks !!

Show more