Problem putting IF sentence

Topics: Developer Forum, Project Management Forum, User Forum
Sep 15, 2009 at 10:10 PM

Hello,

I tried to put in a cell this sentence:

$E->getActiveSheet()->setCellValue('L6','=IF(K6<>0;K6;IF(J6=0;I6;0))');

and always get this error:

Fatal error: Uncaught exception 'Exception' with message 'Formula Error: An unexpected error occured' in /home/dsfarmed/public_html/Control/inc/Excel/PHPExcel/Calculation.php:2860 Stack trace: #0 /home/dsfarmed/public_html/Control/inc/Excel/PHPExcel/Calculation.php(2442): PHPExcel_Calculation->_raiseFormulaError('Formula Error: ...') #1 /home/dsfarmed/public_html/Control/inc/Excel/PHPExcel/Calculation.php(1883): PHPExcel_Calculation->_parseFormula('IF(K6;K6;IF(J6=...') #2 /home/dsfarmed/public_html/Control/inc/Excel/PHPExcel/Calculation.php(1780): PHPExcel_Calculation->_calculateFormulaValue('=IF(K6;K6;IF(J6...', 'L6', Object(PHPExcel_Cell)) #3 /home/dsfarmed/public_html/Control/inc/Excel/PHPExcel/Cell.php(281): PHPExcel_Calculation->calculateCellValue(Object(PHPExcel_Cell), true) #4 /home/dsfarmed/public_html/Control/inc/Excel/PHPExcel/Writer/Excel2007/Worksheet.php(985): PHPExcel_Cell->getCalculatedValue() #5 /home/dsfarmed/public_html/Control/inc/Excel/PHPExcel/Writer/Excel2007/Worksheet.php(929): PHPExcel_Writer_Excel in /home/dsfarmed/public_html/Control/inc/Excel/PHPExcel/Calculation.php on line 2860

I dont know what is the problem. Help me please. Thanks a lot.

Developer
Sep 15, 2009 at 11:05 PM

The problem is your function argument separator. Never use localized formulas. Always use comma as argument separator and not semicolon.

Instead of this

$E->getActiveSheet()->setCellValue('L6','=IF(K6<>0;K6;IF(J6=0;I6;0))');

use this:

 

$E->getActiveSheet()->setCellValue('L6','=IF(K6<>0,K6,IF(J6=0,I6,0))');

 

Sep 15, 2009 at 11:41 PM

Thanks Very much.  It work well.

Congratulations.