diff --git a/CHANGELOG.md b/CHANGELOG.md index 63fa6404..8a80d3ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). ### Fixed +- IF implementation properly handles the value `#N/A` [#1165](https://github.com/PHPOffice/PhpSpreadsheet/pull/1165) - Formula Parser: Wrong line count for stuff like "MyOtherSheet!A:D" [#1215](https://github.com/PHPOffice/PhpSpreadsheet/issues/1215) - Call garbage collector after removing a column to prevent stale cached values - Trying to remove a column that doesn't exist deletes the latest column diff --git a/src/PhpSpreadsheet/Calculation/Logical.php b/src/PhpSpreadsheet/Calculation/Logical.php index c95417c8..416d119a 100644 --- a/src/PhpSpreadsheet/Calculation/Logical.php +++ b/src/PhpSpreadsheet/Calculation/Logical.php @@ -266,6 +266,10 @@ class Logical */ public static function statementIf($condition = true, $returnIfTrue = 0, $returnIfFalse = false) { + if (Functions::isError($condition)) { + return $condition; + } + $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 99f9d7a3..e665c05d 100644 --- a/tests/data/Calculation/Logical/IF.php +++ b/tests/data/Calculation/Logical/IF.php @@ -34,4 +34,10 @@ return [ 'ABC', 'XYZ', ], + [ + '#N/A', + '#N/A', + 'ABC', + 'XYZ', + ], ];