Skip to content

Commit

Permalink
Fixed Functions->ifCondition for allowing <> and empty condition
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jorgecasas authored and PowerKiKi committed Nov 17, 2019
1 parent b20f5c1 commit 156ab36
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Calculation/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public static function ifCondition($condition)
$condition = Calculation::wrapResult(strtoupper($condition));
}

return '=' . $condition;
return str_replace('""""', '""', '=' . $condition);
}
preg_match('/(=|<[>=]?|>=?)(.*)/', $condition, $matches);
[, $operator, $operand] = $matches;
Expand All @@ -290,7 +290,7 @@ public static function ifCondition($condition)
$operand = Calculation::wrapResult(strtoupper($operand));
}

return $operator . $operand;
return str_replace('""""', '""', $operator . $operand);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/data/Calculation/Functions/IF_CONDITION.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@
'<>"< PLEASE SELECT >"',
'<>< Please Select >',
],
[
'<>""',
'<>',
],
[
'=""',
'""',
],
];

0 comments on commit 156ab36

Please sign in to comment.