Click to See Complete Forum and Search --> : Excel Reader Problems


adnan1983
08-27-2006, 08:34 PM
Hi,

I keep getting these errors for at least 500 lines. Not sure what
exactly is wrong? The same exact script works just fine on my other
server.

I am using excelreader http://sourceforge.net/projects/phpexcelreader

Any help would be appreciated.

"Notice: Uninitialized string offset: -512 in
/home/blah/public_html/admin/excelReader/oleread.inc on line 27

Notice: Uninitialized string offset: -511 in
/home/blah/public_html/admin/excelReader/oleread.inc on line 27

Notice: Uninitialized string offset: -510 in
/home/blah/public_html/admin/excelReader/oleread.inc on line 27

Notice: Uninitialized string offset: -509 in
/home/blah/public_html/admin/excelReader/oleread.inc on line 27

Notice: Uninitialized string offset: -508 in
/home/blah/public_html/admin/excelReader/oleread.inc on line 27

Notice: Uninitialized string offset: -507 in
/home/blah/public_html/admin/excelReader/oleread.inc on line 27"

thorpe
08-27-2006, 08:48 PM
Its just a guess without any code.

adnan1983
08-27-2006, 08:54 PM
Sorry, I just downloaded the class from sourceforge and uploaded the files. Which works on my server but not on the other.

adnan1983
08-27-2006, 08:57 PM
example.php from http://sourceforge.net/projects/phpexcelreader/


<?php


require_once 'reader.php';


// ExcelFile($filename, $encoding);
$data = new Spreadsheet_Excel_Reader();


// Set output Encoding.
$data->setOutputEncoding('CP1251');

/***
* if you want you can change 'iconv' to mb_convert_encoding:
* $data->setUTFEncoder('mb');
*
**/

/***
* By default rows & cols indeces start with 1
* For change initial index use:
* $data->setRowColOffset(0);
*
**/



/***
* Some function for formatting output.
* $data->setDefaultFormat('%.2f');
* setDefaultFormat - set format for columns with unknown formatting
*
* $data->setColumnFormat(4, '%.3f');
* setColumnFormat - set format for column (apply only to number fields)
*
**/

$data->read('jxlrwtest.xls');

/*


$data->sheets[0]['numRows'] - count rows
$data->sheets[0]['numCols'] - count columns
$data->sheets[0]['cells'][$i][$j] - data from $i-row $j-column

$data->sheets[0]['cellsInfo'][$i][$j] - extended info about cell

$data->sheets[0]['cellsInfo'][$i][$j]['type'] = "date" | "number" | "unknown"
if 'type' == "unknown" - use 'raw' value, because cell contain value with format '0.00';
$data->sheets[0]['cellsInfo'][$i][$j]['raw'] = value if cell without format
$data->sheets[0]['cellsInfo'][$i][$j]['colspan']
$data->sheets[0]['cellsInfo'][$i][$j]['rowspan']
*/

error_reporting(E_ALL & ~E_NOTICE);

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";

}

//print_r($data);
//print_r($data->formatRecords);
?>



Line 27 on oleread.inc from http://sourceforge.net/projects/phpexcelreader/


function GetInt4d($data, $pos) {
return ord($data[$pos]) | (ord($data[$pos+1]) << 8) | (ord($data[$pos+2]) << 16) | (ord($data[$pos+3]) << 24);
}

adnan1983
08-27-2006, 09:15 PM
Is there any alternate method of reading excel files? I am on a linux server.

NogDog
08-27-2006, 09:51 PM
Is there any alternate method of reading excel files? I am on a linux server.
Save it as a CSV file and use a fgetcsv() (http://www.php.net/fgetcsv) loop.

adnan1983
08-27-2006, 10:04 PM
Not sure if the client is going to be comfortable with that, but I guess that is the solution at this point.

JCBarry
08-27-2006, 10:35 PM
One server could just be suppressing the NOTICE errors on the screen.
Is the script actually failing out?

ktizupos
09-03-2006, 01:05 PM
Probably one server has a 64 bit processor. The GetInt4d bit shift doesn't work with 64 bit processors.

Andreas Rehm hacked it to ensure correct result of the <<24 block on 32 and 64bit systems, just replace the code of the GetInt4d function with the following:

$_or_24 = ord($data[$pos+3]);

if ($_or_24>=128)
$_ord_24 = -abs((256-$_or_24) << 24);
else
$_ord_24 = ($_or_24&127) << 24;

return ord($data[$pos]) | (ord($data[$pos+1]) << 8) | (ord($data[$pos+2]) << 16) | $_ord_24;