diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f8f49bd..62c95615 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] + +### Fixed + +- Support numeric condition in SUMIF, SUMIFS, AVERAGEIF, COUNTIF, MAXIF and MINIF [#683](https://github.com/PHPOffice/PhpSpreadsheet/issues/683) + ## [1.5.0] - 2018-10-21 ### Added diff --git a/src/PhpSpreadsheet/Calculation/Functions.php b/src/PhpSpreadsheet/Calculation/Functions.php index 6fa07de9..0a607c70 100644 --- a/src/PhpSpreadsheet/Calculation/Functions.php +++ b/src/PhpSpreadsheet/Calculation/Functions.php @@ -267,7 +267,7 @@ class Functions public static function ifCondition($condition) { $condition = self::flattenSingleValue($condition); - if (!isset($condition[0])) { + if (!isset($condition[0]) && !is_numeric($condition)) { $condition = '=""'; } if (!in_array($condition[0], ['>', '<', '='])) { diff --git a/tests/data/Calculation/MathTrig/SUMIF.php b/tests/data/Calculation/MathTrig/SUMIF.php index df542bee..85bec2a5 100644 --- a/tests/data/Calculation/MathTrig/SUMIF.php +++ b/tests/data/Calculation/MathTrig/SUMIF.php @@ -70,5 +70,28 @@ return [ [10], ], ], - + [ + 100, + [ + ['0'], + ['some text'], + ], + 0, // Compare integer with string + [ + [100], + [1], + ], + ], + [ + 100, + [ + [0], + ['some text'], + ], + 0, // Compare integer with integer + [ + [100], + [1], + ], + ], ];