PHP library for parse and retrieve information from XLS files

Post

1 comment   |   PHP


It’s realy cool library, you don’t need PEAR library, or other’s files.
Now you can parse your xls to array.
Example of usage:

<?php
require_once 'reader.php';
 
$filename="test.xls";
$prod=parseExcel($filename);
echo"<pre>";
print_r($prod);
 
function parseExcel($excel_file_name_with_path)
{
	$data = new Spreadsheet_Excel_Reader();
	// Set output Encoding.
	$data->setOutputEncoding('CP1251');
	$data->read($excel_file_name_with_path);
 
	$colname=array('name','price','old_price','in_price','descr','status','sku','pos','stock','in_name','manufacturer','supplier','photo');
 
	for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
		for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
 
			$product[$i-1][$j-1]=$data->sheets[0]['cells'][$i][$j];
			$product[$i-1][$colname[$j-1]]=$data->sheets[0]['cells'][$i][$j];
		}
	}
	return $product;
}

Download PHP Excel library