Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spreadsheet_Excel_Writer data output is damaged

Tags:

php

excel

xls

pear

I use Spreadsheet_Excel_Writer to generate .xls file and it works fine until I have to deal with a large amount of data. On certain stage it just writes some nonsense chars and quits filling certain columns. However some columns are field up to the end (generally numeric data)

I'm not quite sure how the xls document is formed: row by row, or col by col... Also it is obviously not an error in a string, because when i cut out some data, the error appears a little bit further.

I think there is no need in all of my code

here are some essentials

$filename = 'file.xls';
$workbook = & new Spreadsheet_Excel_Writer(); 
$workbook->setVersion(8); 
$contents =& $workbook->addWorksheet('Logistics');
$contents->setInputEncoding('UTF-8');

$workbook->send($filename);

//here is the part where I write data down
$contents->write(0, 0, 'Field A');
$contents->write(0, 1, 'Field B');
$contents->write(0, 2, 'Field C');

$ROW=1;
foreach($ordersArr as $key=>$val){
  $contents->write($ROW, 0, $val['a']);
  $contents->write($ROW, 1, $val['b']);
  $contents->write($ROW, 2, $val['c']);

  $ROW++;
}
$workbook->close(); 
like image 856
dr3w Avatar asked Apr 20 '10 11:04

dr3w


2 Answers

I had the same problem, I found this solution that works for me:

http://pear.php.net/bugs/bug.php?id=19284&edit=3

[2012-08-08 17:12 UTC] identit (Vincent Dubourg)

The solution is change in Root.php \ line 623 :

fwrite($FILE, pack("V", 1));

to

fwrite($FILE, pack("V", $num_sb_blocks));

the file is pear/OLE/PPS/Root.php in package OLE 1.0.0RC2 (beta)

like image 176
mabi Avatar answered Sep 22 '22 15:09

mabi


I know it's an old post but I had the same problem and solved it reverting to Spreadsheet_Excel_Writer 0.9.2 and OLE-1.0.0RC1.

pear uninstall Spreadsheet_Excel_Writer-0.9.3
pear uninstall OLE-1.0.0RC2

pear install OLE-1.0.0RC1
pear install Spreadsheet_Excel_Writer-0.9.2

Hope this helps someone in the future.

like image 35
ZiP Avatar answered Sep 21 '22 15:09

ZiP