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:
parent
5e5be142f6
commit
ae9dd13aa0
|
@ -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)
|
||||||
|
|
|
@ -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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue