views:

32

answers:

2

In short what i want to do is, create several worksheets dynamically, populated with data from a database result.

So far i'm getting:

Fatal error: Call to undefined method PEAR_Error::write() in /mnt/hgfs/workspace/CCMS-Web/reports/file-excel.php on line 113

When i'm trying to do this:

$workbook = new Spreadsheet_Excel_Writer();

// sending HTTP headers
$workbook->send('excel_filename.xls');

$ReportName = "Report Name"; 
while ($row = $Results->fetch_assoc()) {
 $worksheet_name = $row["data"];
 $$worksheet_name =& $workbook->addWorksheet($campaign_name); 
 $$worksheet_name->write($y, 0, $ReportName,$fmtTitle);
}

Have you done this before? Is this possible? If so what is the right way to do this?

A: 

you have two

$$

in there, but that should be only one.

Also, $$worksheet_name is not a sheet object but a PEAR_Error which you need to handle separately:

if (PEAR::isError($worksheet_name)) {
    var_dump($worksheet_name);
    die();
}
cweiske
i'm using a variable variable .. i.e $$worksheet_name = $row['data']
Rasiel
thanks about pear error, i should check for that.
Rasiel
A: 

To answer my own question,

it is possible to dynamically create spreadsheets.

you have to however take note not to create spreadsheets with the same name as this will cause a PEAR fatal error.

you should check for existing worksheets like below

$worksheets = $workbook->worksheets();
if (!in_array($worksheet_name,$worksheets)){
    $worksheet_name =& $workbook->addWorksheet($worksheet_name);    
}

This was what was happening to me, in the question posed above.

Rasiel