Sep 25, 2010

Using PHP with PEAR to export an Excel File

Some people like to tell us "Use COM object to create an Excel File".
It is a general answer, if you are using Windows OSs and installed Microsoft Office with Excel Application.
So, how do we can create an Excel File without using any Microsoft / Windows components ?

PEAR is one of best way for us to complete this mission.
PEAR Official Website
PEAR @ Wiki

First, you should install PEAR.
Open the Terminal and type
sudo apt-get install php-pear

To install PEAR and its relative package.

Open the Terminal and type
sudo gedit /etc/php5/apache2/php.ini

Open php.ini
find include_path after UNIX
uncomment include_path and edit the string of included path to .:/usr/share/php:/usr/share/php/PEAR
(Note: The included path base on which path you would like to include, you can add more included path separated by a colon)

Open the Terminal and type
sudo service apache2 restart

To restart Apache2

Create a PHP in your web directory and type <?php phpinfo(); ?> to get information of Apache2.
Make sure the include_path is included .:/usr/share/php:/usr/share/php/PEAR

Visit and
to download Spreadsheet_Excel_Writer and OLE package.
You can download and move them to specific locations manually.
Copy the PEAR Install Command and paste them to Terminal to install them automatically.

We suggest you use PEAR Install Command.
You should super user or root account to install them.
sudo pear install Spreadsheet_Excel_Writer-0.9.2
sudo pear install OLE-1.0.0RC1

Make sure Spreadsheet_Excel_Writer and OLE directories are included if you want to use them.

Create a simple PHP file for exporting Excel file.

Open a browser to browse the PHP file for exporting Excel file.

Here is a simple result.

You can visit Spreadsheet Excel Writer APIs to get more information for exporting.


weight said...

i can has cheeseburger?

sell this domain at sedo said...

Great post! STICK WITH IT!

Ikhsan said...

Here is another example with PEAR Spreadsheet

suvathi said...

wow great Article, the details you have provided are much clear, easy to understand, if you post some more Article, it will be very much useful for me.
PHP Training in Chennai

Post a Comment

Twitter Delicious Facebook Digg Google Favorites More

Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Best Hostgator Coupon Code