From 156ab360fe191ab235361b16cf0b6d0edf88754f Mon Sep 17 00:00:00 2001 From: Jorge Casas Date: Tue, 15 Oct 2019 13:11:43 +0200 Subject: [PATCH] Fixed Functions->ifCondition for allowing <> and empty condition In cells with formulas containing conditions like `=IFSUM(A1:A3;"";B1:B3)` to sum cells from range A1:A3 with empty value in range B1:B3, the function `Functions::ifCondition()` create in this case the code `=""""` instead of `=""`, so it didn't work. Closes #1206 --- CHANGELOG.md | 1 + src/PhpSpreadsheet/Calculation/Functions.php | 4 ++-- tests/data/Calculation/Functions/IF_CONDITION.php | 8 ++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7c2ceff..3d8cbad3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Keep big integer as integer instead of lossely casting to float [#874](https://github.com/PHPOffice/PhpSpreadsheet/pull/874) - Fix branch pruning handling of non boolean conditions [#1167](https://github.com/PHPOffice/PhpSpreadsheet/pull/1167) - Fix ODS Reader when no DC namespace are defined [#1182](https://github.com/PHPOffice/PhpSpreadsheet/pull/1182) +- Fixed Functions->ifCondition for allowing <> and empty condition [#1206](https://github.com/PHPOffice/PhpSpreadsheet/pull/1206) ## [1.9.0] - 2019-08-17 diff --git a/src/PhpSpreadsheet/Calculation/Functions.php b/src/PhpSpreadsheet/Calculation/Functions.php index 40e7d964..38bd87c6 100644 --- a/src/PhpSpreadsheet/Calculation/Functions.php +++ b/src/PhpSpreadsheet/Calculation/Functions.php @@ -278,7 +278,7 @@ class Functions $condition = Calculation::wrapResult(strtoupper($condition)); } - return '=' . $condition; + return str_replace('""""', '""', '=' . $condition); } preg_match('/(=|<[>=]?|>=?)(.*)/', $condition, $matches); [, $operator, $operand] = $matches; @@ -290,7 +290,7 @@ class Functions $operand = Calculation::wrapResult(strtoupper($operand)); } - return $operator . $operand; + return str_replace('""""', '""', $operator . $operand); } /** diff --git a/tests/data/Calculation/Functions/IF_CONDITION.php b/tests/data/Calculation/Functions/IF_CONDITION.php index 0b510ed9..0ac81d5d 100644 --- a/tests/data/Calculation/Functions/IF_CONDITION.php +++ b/tests/data/Calculation/Functions/IF_CONDITION.php @@ -33,4 +33,12 @@ return [ '<>"< PLEASE SELECT >"', '<>< Please Select >', ], + [ + '<>""', + '<>', + ], + [ + '=""', + '""', + ], ];