Skip to content

Commit

Permalink
Support numeric condition in SUMIF, SUMIFS, AVERAGEIF, COUNTIF, MAXIF…
Browse files Browse the repository at this point in the history
… and MINIF

Fixes #683
Fixes #701
  • Loading branch information
Sreten Ilić authored and PowerKiKi committed Oct 28, 2018
1 parent 90bb4df commit ed6a3a0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public static function isCellValue($idx)
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], ['>', '<', '='])) {
Expand Down
25 changes: 24 additions & 1 deletion tests/data/Calculation/MathTrig/SUMIF.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,28 @@
[10],
],
],

[
100,
[
['0'],
['some text'],
],
0, // Compare integer with string
[
[100],
[1],
],
],
[
100,
[
[0],
['some text'],
],
0, // Compare integer with integer
[
[100],
[1],
],
],
];

0 comments on commit ed6a3a0

Please sign in to comment.