Fixed parsing of conditionals in COUNTIF functions

Conditional operators in the selection parameter of COUNTIF
functions were not being parsed properly, causing evaluations
of formulae with such functions to sometimes fail.

Fixes #526
Closes #528
This commit is contained in:
Bill Blume 2018-06-01 19:34:44 -07:00 committed by Adrien Crivelli
parent ed2185417e
commit e3fb160f5f
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
4 changed files with 54 additions and 1 deletions

View File

@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Xlsx reader do not read rows and columns filtered out in readFilter at all - [#370](https://github.com/PHPOffice/PhpSpreadsheet/issues/370)
- Make newer Excel versions properly recalculate formulas on document open - [#456](https://github.com/PHPOffice/PhpSpreadsheet/issues/456)
- `Coordinate::extractAllCellReferencesInRange()` throws an exception for an invalid range [#519](https://github.com/PHPOffice/PhpSpreadsheet/issues/519)
- Fixed parsing of conditionals in COUNTIF functions - [#526](https://github.com/PHPOffice/PhpSpreadsheet/issues/526)
## [1.2.1] - 2018-04-10

View File

@ -277,7 +277,7 @@ class Functions
return '=' . $condition;
}
preg_match('/([<>=]+)(.*)/', $condition, $matches);
preg_match('/(=|<[>=]?|>=?)(.*)/', $condition, $matches);
list(, $operator, $operand) = $matches;
if (!is_numeric($operand)) {

View File

@ -307,4 +307,20 @@ class FunctionsTest extends TestCase
{
return require 'data/Calculation/Functions/ISFORMULA.php';
}
/**
* @dataProvider providerIfCondition
*
* @param mixed $expectedResult
*/
public function testIfCondition($expectedResult, ...$args)
{
$result = Functions::ifCondition(...$args);
self::assertEquals($expectedResult, $result);
}
public function providerIfCondition()
{
return require 'data/Calculation/Functions/IF_CONDITION.php';
}
}

View File

@ -0,0 +1,36 @@
<?php
return [
[
'<"A"',
'<A',
],
[
'>"A"',
'>A',
],
[
'<="A"',
'<=A',
],
[
'>"A"',
'>A',
],
[
'>="A"',
'>=A',
],
[
'<>"A"',
'<>A',
],
[
'<"<A"',
'<<A',
],
[
'<>"< PLEASE SELECT >"',
'<>< Please Select >',
],
];