IF formula not working with parenthesis

Feb 24, 2015 at 11:16 PM
There is a problem with parenthesis in formulas.

=IF(A1="GOLD" , B1+C1 , 0)

=IF(A1="GOLD (2)" , B1+C1 , 0)

The first one works. But the second one doesn't work because of "(2)"

How can I avoid this problem? $objWriter->setPreCalculateFormulas(false); doesn't help.
Coordinator
Feb 25, 2015 at 11:37 AM
Unable to replicate any problem
$workbook = new PHPExcel();
$worksheet = $workbook->getActiveSheet();

$worksheet->setCellValue('A1', 'GOLD')
    ->setCellValue('B1', 1)
    ->setCellValue('C1', 2);
$worksheet->setCellValue('A2', 'SILVER')
    ->setCellValue('B2', 3)
    ->setCellValue('C2', 4);

$worksheet->setCellValue('A3', 'GOLD (2)')
    ->setCellValue('B3', 5)
    ->setCellValue('C3', 6);
$worksheet->setCellValue('A4', 'SILVER')
    ->setCellValue('B4', 7)
    ->setCellValue('C4', 8);

$worksheet->setCellValue('D1', '=IF(A1="GOLD" , B1+C1 , 0)');
$worksheet->setCellValue('D2', '=IF(A2="GOLD" , B2+C2 , 0)');

$worksheet->setCellValue('D3', '=IF(A3="GOLD (2)" , B3+C3 , 0)');
$worksheet->setCellValue('D4', '=IF(A4="GOLD (2)" , B4+C4 , 0)');

for($row = 1; $row <= 4; ++$row) {
    echo $worksheet->getCell('D'.$row)->getCalculatedValue(), PHP_EOL;
}

PHPExcel_IOFactory::createWriter($workbook, 'Excel2007')->save('test.xlsx');
works exactly as expected, outputting
3
0
11
0
And correctly saving test.xlsx which contains the correct formulae and the correct results


Can you please provide a working example of code that demonstrates your problem