diff --git a/CHANGELOG.md b/CHANGELOG.md index 1aed31e460..48b9d603b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). ### Fixed +- IF implementation properly handles the value `#N/A` - ... ## [1.9.0] - 2019-08-17 diff --git a/src/PhpSpreadsheet/Calculation/Logical.php b/src/PhpSpreadsheet/Calculation/Logical.php index c95417c892..a3393a0706 100644 --- a/src/PhpSpreadsheet/Calculation/Logical.php +++ b/src/PhpSpreadsheet/Calculation/Logical.php @@ -266,6 +266,10 @@ public static function NOT($logical = false) */ public static function statementIf($condition = true, $returnIfTrue = 0, $returnIfFalse = false) { + if ($condition === '#N/A') { + return '#N/A'; + } + $condition = ($condition === null) ? true : (bool) Functions::flattenSingleValue($condition); $returnIfTrue = ($returnIfTrue === null) ? 0 : Functions::flattenSingleValue($returnIfTrue); $returnIfFalse = ($returnIfFalse === null) ? false : Functions::flattenSingleValue($returnIfFalse); diff --git a/tests/data/Calculation/Logical/IF.php b/tests/data/Calculation/Logical/IF.php index 99f9d7a367..e665c05d9a 100644 --- a/tests/data/Calculation/Logical/IF.php +++ b/tests/data/Calculation/Logical/IF.php @@ -34,4 +34,10 @@ 'ABC', 'XYZ', ], + [ + '#N/A', + '#N/A', + 'ABC', + 'XYZ', + ], ];