Uncaught exception 'PHPExcel_Exception' with message 'Simple!P158 -> Formula Error: An unexpected error occured' in /phpexcel/Classes/PHPExcel/Cell.php:307

Topics: Developer Forum, Project Management Forum, User Forum
Nov 22, 2012 at 4:23 PM

I have this error when I download the report from a MySql DB

Uncaught exception 'PHPExcel_Exception' with message 'Simple!P158 -> Formula Error: An unexpected error occured' in /phpexcel/Classes/PHPExcel/Cell.php:307

and I don't understand where is the problem... Please any idea?

Coordinator
Nov 22, 2012 at 5:42 PM

So what's being written to cell P158 in the Simple worksheet?

Nov 22, 2012 at 6:20 PM

it is a text like " state - State = Not charge "

Nov 22, 2012 at 6:53 PM

I have been testing with different queries and it is happening with the same col because it has symbols like = , <, >, #

Is there any possibility to set the field just as text and it doesn't matter what symbol contain?

Thank you Mark

Coordinator
Nov 22, 2012 at 8:36 PM

It is possible to set the cell as text using setCellValueExplicit() but a cell that simply contains symbols should not cause any such error, unless you have an = as the very first character.

I've just run:

require_once '../Classes/PHPExcel.php';

$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1',  " state - State = Not charge ")
            ->setCellValue('A2',  "state - State = Not charge");
$objPHPExcel->getActiveSheet()->setTitle('Simple');

$objPHPExcel->setActiveSheetIndex(0);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save(str_replace('.php', '.xls', __FILE__));

without any problem

Nov 23, 2012 at 12:09 PM

Thank you Mark! I use setCellValueExplicit() and it worked without problems!

Nov 23, 2012 at 1:00 PM
MarkBaker wrote:

It is possible to set the cell as text using setCellValueExplicit() but a cell that simply contains symbols should not cause any such error, unless you have an = as the very first character.


In excel a text cell cannot begin even with "+" and "-" chars