Uncategorized

Using PHP with PEAR to export an Excel File

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

Using PHP with PEAR to export an Excel File
First, you should install PEAR.
Open the Terminal and type

sudo apt-get install php-pear

To install PEAR and its relative package.

Using PHP with PEAR to export an Excel File
Open the Terminal and type

sudo gedit /etc/php5/apache2/php.ini

Using PHP with PEAR to export an Excel File
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)

Using PHP with PEAR to export an Excel File
Open the Terminal and type

sudo service apache2 restart

To restart Apache2

Using PHP with PEAR to export an Excel File
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

Using PHP with PEAR to export an Excel File
Visit http://pear.php.net/package/Spreadsheet_Excel_Writer/download and http://pear.php.net/package/OLE/download
to download Spreadsheet_Excel_Writer and OLE package.
You can download and move them to specific locations manually.
or
Copy the PEAR Install Command and paste them to Terminal to install them automatically.

Using PHP with PEAR to export an Excel File
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

Using PHP with PEAR to export an Excel File
Make sure Spreadsheet_Excel_Writer and OLE directories are included if you want to use them.

Using PHP with PEAR to export an Excel File
Create a simple PHP file for exporting Excel file.

Using PHP with PEAR to export an Excel File
Open a browser to browse the PHP file for exporting Excel file.

Using PHP with PEAR to export an Excel File
Using PHP with PEAR to export an Excel File
Here is a simple result.

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