Skip non numeric value in SUMIF

MS Excel skip non numeric values also. PhpSpreadsheet used to fail on string value with: Warning: A non-numeric value encountered.

Fixes  #618
This commit is contained in:
Scorty 2018-10-07 08:24:23 +02:00 committed by Adrien Crivelli
parent 5e5be142f6
commit ae9dd13aa0
4 changed files with 21 additions and 5 deletions

View File

@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added ### 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) - 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) - 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) - Read and write hyperlink for drawing image - [#490](https://github.com/PHPOffice/PhpSpreadsheet/pull/490)

View File

@ -1222,8 +1222,10 @@ class MathTrig
} }
$testCondition = '=' . $arg . $condition; $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]; $returnValue += $sumArgs[$key];
} }
} }

View File

@ -560,7 +560,7 @@ class MathTrigTest extends TestCase
public function testSUMIF($expectedResult, ...$args) public function testSUMIF($expectedResult, ...$args)
{ {
$result = MathTrig::SUMIF(...$args); $result = MathTrig::SUMIF(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12); self::assertEquals($expectedResult, $result, '', 1E-12);
} }
public function providerSUMIF() public function providerSUMIF()

View File

@ -40,7 +40,7 @@ return [
['"text with quotes"'], ['"text with quotes"'],
[''], [''],
], ],
'>"', // Compare to the single characater " (double quote) '>"', // Compare to the single character " (double quote)
[ [
[10], [10],
[100], [100],
@ -52,10 +52,23 @@ return [
[''], [''],
['anything'], ['anything'],
], ],
'>"', // Compare to the single characater " (double quote) '>"', // Compare to the single character " (double quote)
[ [
[10], [10],
[100], [100],
], ],
], ],
[
10,
[
[1],
[2],
],
'<>', // any content
[
['non-numeric value'], // ignored in SUM
[10],
],
],
]; ];