Skip to content

Commit e3fb160

Browse files
billblumePowerKiKi
authored andcommitted
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
1 parent ed21854 commit e3fb160

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2222
- Xlsx reader do not read rows and columns filtered out in readFilter at all - [#370](https://github.com/PHPOffice/PhpSpreadsheet/issues/370)
2323
- Make newer Excel versions properly recalculate formulas on document open - [#456](https://github.com/PHPOffice/PhpSpreadsheet/issues/456)
2424
- `Coordinate::extractAllCellReferencesInRange()` throws an exception for an invalid range – [#519](https://github.com/PHPOffice/PhpSpreadsheet/issues/519)
25+
- Fixed parsing of conditionals in COUNTIF functions - [#526](https://github.com/PHPOffice/PhpSpreadsheet/issues/526)
2526

2627
## [1.2.1] - 2018-04-10
2728

src/PhpSpreadsheet/Calculation/Functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public static function ifCondition($condition)
277277

278278
return '=' . $condition;
279279
}
280-
preg_match('/([<>=]+)(.*)/', $condition, $matches);
280+
preg_match('/(=|<[>=]?|>=?)(.*)/', $condition, $matches);
281281
list(, $operator, $operand) = $matches;
282282

283283
if (!is_numeric($operand)) {

tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,20 @@ public function providerIsFormula()
307307
{
308308
return require 'data/Calculation/Functions/ISFORMULA.php';
309309
}
310+
311+
/**
312+
* @dataProvider providerIfCondition
313+
*
314+
* @param mixed $expectedResult
315+
*/
316+
public function testIfCondition($expectedResult, ...$args)
317+
{
318+
$result = Functions::ifCondition(...$args);
319+
self::assertEquals($expectedResult, $result);
320+
}
321+
322+
public function providerIfCondition()
323+
{
324+
return require 'data/Calculation/Functions/IF_CONDITION.php';
325+
}
310326
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
return [
4+
[
5+
'<"A"',
6+
'<A',
7+
],
8+
[
9+
'>"A"',
10+
'>A',
11+
],
12+
[
13+
'<="A"',
14+
'<=A',
15+
],
16+
[
17+
'>"A"',
18+
'>A',
19+
],
20+
[
21+
'>="A"',
22+
'>=A',
23+
],
24+
[
25+
'<>"A"',
26+
'<>A',
27+
],
28+
[
29+
'<"<A"',
30+
'<<A',
31+
],
32+
[
33+
'<>"< PLEASE SELECT >"',
34+
'<>< Please Select >',
35+
],
36+
];

0 commit comments

Comments
 (0)