diff --git a/CHANGELOG.md b/CHANGELOG.md index f37d67bc..963f01d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added +- skip non numeric value in SUMIF - [#618](https://github.com/PHPOffice/PhpSpreadsheet/pull/618) - Add excel function EXACT(value1, value2) support - [#595](https://github.com/PHPOffice/PhpSpreadsheet/pull/595) - Support workbook view attributes for Xlsx format - [#523](https://github.com/PHPOffice/PhpSpreadsheet/issues/523) - Read and write hyperlink for drawing image - [#490](https://github.com/PHPOffice/PhpSpreadsheet/pull/490) diff --git a/src/PhpSpreadsheet/Calculation/MathTrig.php b/src/PhpSpreadsheet/Calculation/MathTrig.php index 41fc0de2..e8a0397e 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig.php @@ -1222,8 +1222,10 @@ class MathTrig } $testCondition = '=' . $arg . $condition; - if (Calculation::getInstance()->_calculateFormulaValue($testCondition)) { - // Is it a value within our criteria + + if (is_numeric($sumArgs[$key]) && + Calculation::getInstance()->_calculateFormulaValue($testCondition)) { + // Is it a value within our criteria and only numeric can be added to the result $returnValue += $sumArgs[$key]; } } diff --git a/tests/PhpSpreadsheetTests/Calculation/MathTrigTest.php b/tests/PhpSpreadsheetTests/Calculation/MathTrigTest.php index fa497964..11c958fb 100644 --- a/tests/PhpSpreadsheetTests/Calculation/MathTrigTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/MathTrigTest.php @@ -560,7 +560,7 @@ class MathTrigTest extends TestCase public function testSUMIF($expectedResult, ...$args) { $result = MathTrig::SUMIF(...$args); - self::assertEquals($expectedResult, $result, null, 1E-12); + self::assertEquals($expectedResult, $result, '', 1E-12); } public function providerSUMIF() diff --git a/tests/data/Calculation/MathTrig/SUMIF.php b/tests/data/Calculation/MathTrig/SUMIF.php index 0b94701a..df542bee 100644 --- a/tests/data/Calculation/MathTrig/SUMIF.php +++ b/tests/data/Calculation/MathTrig/SUMIF.php @@ -40,7 +40,7 @@ return [ ['"text with quotes"'], [''], ], - '>"', // Compare to the single characater " (double quote) + '>"', // Compare to the single character " (double quote) [ [10], [100], @@ -52,10 +52,23 @@ return [ [''], ['anything'], ], - '>"', // Compare to the single characater " (double quote) + '>"', // Compare to the single character " (double quote) [ [10], [100], ], ], + [ + 10, + [ + [1], + [2], + ], + '<>', // any content + [ + ['non-numeric value'], // ignored in SUM + [10], + ], + ], + ];