Skip to content

Commit

Permalink
Fix IF implementation to comply with Excel behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
frantzmiccoli committed Oct 15, 2019
1 parent 9d6736d commit 71be8f5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/PhpSpreadsheet/Calculation/Logical.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ public static function NOT($logical = false)
*/
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);
Expand Down
6 changes: 6 additions & 0 deletions tests/data/Calculation/Logical/IF.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@
'ABC',
'XYZ',
],
[
'#N/A',
'#N/A',
'ABC',
'XYZ',
],
];

0 comments on commit 71be8f5

Please sign in to comment.