Hi
When looking through the forums for a library to read excel files I came across this thread
http://ellislab.com/forums/viewthread/47299/
and after reading through it tried out the excel reader in the wiki. It seemed a bit buggy
so I read over Derek’s comments noting.
Actually, I need one to read excel. In the past I’ve used the excellent Excel reader (http://sourceforge.net/projects/phpexcelreader) but I was just hoping that someone had already taken it and coded it up as a CI library.
Thanks both.
So I Downloaded that lib and used it briefly as Derek did:
require('Spreadsheet_Excel_Reader.php');
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP1251'); // Set output Encoding.
$data->read($filename); // relative path to .xls that was uploaded earlier
for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
echo "\"".$data->sheets[0]['cells'][$i][$j]."\",";
}
echo "\n";
}but after looking over the files it seemed they could be used as a lib without much alteration. So I altered them slightly and the reader seems to be running fine as a lib.
example code usage:
public function bulk_upload()
{
$this->load->library('spreadsheet_excel_reader');
$this->spreadsheet_excel_reader->setOutputEncoding('CP1251'); // Set output Encoding.
$this->spreadsheet_excel_reader->read('uploads/outlet_participation/test.xls'); // relative path to .xls that was uploaded earlier
$rows = $this->spreadsheet_excel_reader->sheets[0]['cells'];
$row_count = count($this->spreadsheet_excel_reader->sheets[0]['cells']);
echo 'my row count is'.$row_count;
for ($i = 2; $i <= $row_count; $i++) {
var_dump($rows[$i]);
echo "
<hr>";
}
}Anyway I hope this makes life more convenient for somebody.