PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » File Formats » Spreadsheet_Excel_Writer » Bug #8408

Problem with foreach loop

Details

Request #8408Problem with foreach loop
Submitted2006-08-10 12:04 UTC
Fromsoli at freemail dot it
StatusNo Feedback
PackageSpreadsheet_Excel_Writer
PHP Version5.0.2
OSWin2003 EE
Roadmaps(Not assigned)

Comments

[2006-08-10 12:04 UTC] soli at freemail dot it

Description:
------------
I'm trying to write to multiple worksheet.
First I read a text file, for each line I create a worksheet (since now no problems) than I try to write values into these worksheets (this does not work!).

Test script:
---------------
$readfile=file("file.txt");
require_once 'Spreadsheet/Excel/Writer.php';
$workbook = new Spreadsheet_Excel_Writer('test.xls');

foreach($readfile as $r){
$r=trim($r);
$worksheet =& $workbook->addWorksheet($l); //This works
$worksheet->writeString(0, 0, 'Somevalue'); //This does not work
$l="";
}
$workbook->close();

Expected result:
----------------
I expect an excel file with multiple worksheet populated with values

Actual result:
--------------
This is the error I find:
PHP Fatal error: Call to undefined method PEAR_Error::writeString() in D:\phpwebsite\excel.php on line 7

[2006-09-18 10:54 UTC] pear dot php dot net at chsc dot dk

According to the documentation, $worksheet->addWorksheet() may return a PEAR_Error. You should check the return value using PEAR::isError($worksheet) before calling $worksheet->writeString(). The PEAR_Error object contains an error message explaining what went wrong.