Reputation: 35
I'm trying to match if condition through phpexcel library but formula returns me every time true condition, here is my code
$condition = "B2-300=0"; // if enter 1 instead of zero then formula still return zero. I have 300 integer value in B2 cell.
echo $ajaxFinalValue = PHPExcel_Calculation_Logical::STATEMENT_IF($condition, $objPHPExcel->getActiveSheet()->getCell('B6'), $objPHPExcel->getActiveSheet()->getCell('C6')); i B6 value is answer but when i false the condition then also return B6
please advise what to do.
Thanks Adil
Upvotes: 0
Views: 2599
Reputation: 212522
The STATEMENT_IF() method expects the boolean result of a condition, not the condition itself.
If you want to evaluate the condition itself, then you need to call the calculation engine to handle the evaluation, not the functions that it calls:
There is a slight difference between PHPExcel version 1.7.9 and earlier versions
PHPExcel version 1.7.9
$ifFormula = '=IF(B2-300=0,B6,C6)';
$formulaResult = PHPExcel_Calculation::getInstance($objPHPExcel)
->calculateFormula(
$ifFormula,
'A1',
$objPHPExcel->getActiveSheet()->getCell('A1')
);
var_dump($formulaResult);
earlier versions
$ifFormula = '=IF(B2-300=0,B6,C6)';
$formulaResult = PHPExcel_Calculation::getInstance()
->calculateFormula(
$ifFormula,
'A1',
$objPHPExcel->getActiveSheet()->getCell('A1')
);
var_dump($formulaResult);
Upvotes: 0