3

can somebody tell me why am I getting this error?

PHP Fatal error:  Uncaught exception 'PHPExcel_Calculation_Exception' with message 'Worksheet!E48 -> Formula Error: An unexpected error occured' in PHPExcel/1.8.0/Classes/PHPExcel/Cell.php:300
Stack trace:
#0 PHPExcel/1.8.0/Classes/PHPExcel/Writer/Excel5/Worksheet.php(460): PHPExcel_Cell->getCalculatedValue()
#1 PHPExcel/1.8.0/Classes/PHPExcel/Writer/Excel5.php(187): PHPExcel_Writer_Excel5_Worksheet->close()
#2 export/the_script.php(98): PHPExcel_Writer_Excel5->save('the_export.xls')
#3 {main}
  thrown in PHPExcel/1.8.0/Classes/PHPExcel/Cell.php on line 300

The code that generates this error:

$excel = new PHPExcel();
$excel->setActiveSheetIndex(0);
$R = $db->query("SELECT col1, col2, col3 from table1");
while($row = $R->fetch(Zend_Db::FETCH_NUM)) {
    $excel->getActiveSheet()->fromArray($row, false, 'A'.$i);
    $i++;
}
$excelWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
$excelWriter->save('the_export.xls');

As you can see, there are no formulas, no nothing... simple dumping of data from database into an excel file... Running PHP 5.3.2

1 Answer 1

4

I'm guessing that one of the values retrieved from your database begins with an = sign, in which case PHPExcel will "guess" that it's supposed to be a formula and store it as such.

If you have values that begin with an = that aren't formulae, then you need to tell PHPExcel that it is a string and that it should be stored as such.

This behaviour is defined in the default cell binder (PHPExcel/Cell/DefaultValueBinder.php).

If you want to force PHPExcel to store these values as strings, then you can use the setCellValueExplicit() method (which defaults to enforcing a string)

Or you can write a custom value binder and apply that instead of the default value binder

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.