From ed6a3a01484023df7c400a1603b716f4f9919f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sreten=20Ili=C4=87?= Date: Tue, 2 Oct 2018 14:51:51 +0200 Subject: [PATCH] Support numeric condition in SUMIF, SUMIFS, AVERAGEIF, COUNTIF, MAXIF and MINIF Fixes #683 Fixes #701 --- CHANGELOG.md | 6 +++++ src/PhpSpreadsheet/Calculation/Functions.php | 2 +- tests/data/Calculation/MathTrig/SUMIF.php | 25 +++++++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) 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], + ], + ], ];