Professional Documents
Culture Documents
Parsing Excel by PHP
Parsing Excel by PHP
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