You are on page 1of 2

Parsing Excel files by PHP

You might be wondering whether is it really possible to parse excel


files by PHP or not ! the answer is a straight yes and is available for
free too ! . This is a nice tool for reading Microsoft Excel files called
PHPExcelReader in PHP. It works with .xls files up to Excel version
2003, which are based on the BIFF format . It is written in native PHP
and does not require any third-party libraries or the MS Office
package. The utility consist of two small files oleread.php and
reader.php. It actually reread the excel cells' content into 'BIFF' format
which is finally parse by the PHP parser engine.

The utility is available at this location


http://downloads.sourceforge.net/phpexcelreader/phpExcelReader.zip?
modtime=1183691654&big_mirror=0

Download the zip file and then extract it in your web server's
documentroot directory and then try this simple php script to read
excel file “test.xls”.

<?php
require_once 'Excel/reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP1251');
$data->read("test.xls");
$page = 0;
error_reporting(E_ALL ^ E_NOTICE);
for ($i = 1; $i <= $data->sheets[$page]['numRows']; $i++) {
for ($j = 1; $j <= $data->sheets[$page]['numCols']; $j++) {
if($data->sheets[0]['cells'][$i][$j] != NULL)
echo $i.','.$j.':=>'.$data-
>sheets[$page]['cells'][$i][$j].'<br>';
}
}
?>

This will display the entire cell addresses and cell contents onto your
screen. Every cell is now put into buffer array $data with sheet,and
cell distinction . Therefore now it is very easy to select & transfer
these data into any database of choice.
The later versions of .xls files use OOXML which cannot be read by this
utility. However with this utility I have transfered lots of excel files
upto size (less than 2 MB) into various databases on my several linux
systems. Slightly bigger files are giving errors and the transfer is not
successful . Upto 2MB size this utility works perfectly and most of the
small excel files are less than 2MB size . Isn't it ?

S. Bera
India

You might also like