Skip to content

Commit a0da3e3

Browse files
committed
Double quote support for SUMIF() condition
SUMIF() condition can have double quote, such as '=SUMIF(A2:A4,">""",B2:B4)'. This formula purpose is to compare the character double quote ("). In our previous patch (commit f1a1f52) we wrongly assumed that PHPExcel_Calculation_MathTrig::SUMIF() expected the condition to escaped ('>""'), but this is actually not the case in real use of PHPExcel, so the unit tests were modified accordingly to use non-escaped condition ('>"').
1 parent 496b76e commit a0da3e3

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

Classes/PHPExcel/Calculation/Functions.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,12 @@ public static function _ifCondition($condition) {
316316
} else {
317317
preg_match('/([<>=]+)(.*)/',$condition,$matches);
318318
list(,$operator,$operand) = $matches;
319-
if (!is_numeric($operand)) { $operand = PHPExcel_Calculation::_wrapResult(strtoupper($operand)); }
319+
320+
if (!is_numeric($operand)) {
321+
$operand = str_replace('"', '""', $operand);
322+
$operand = PHPExcel_Calculation::_wrapResult(strtoupper($operand));
323+
}
324+
320325
return $operator.$operand;
321326
}
322327
} // function _ifCondition()

unitTests/Classes/PHPExcel/Calculation/MathTrigTest.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ public function providerSUMIF()
521521
array('"text with quotes"'),
522522
array(2),
523523
),
524-
'=""text with quotes""',
524+
'="text with quotes"',
525525
array(
526526
array(10),
527527
array(100),
@@ -533,13 +533,25 @@ public function providerSUMIF()
533533
array('"text with quotes"'),
534534
array(''),
535535
),
536-
'>""', // Compare to the single characater " (double quote)
536+
'>"', // Compare to the single characater " (double quote)
537537
array(
538538
array(10),
539539
array(100),
540540
),
541541
10
542542
),
543+
array(
544+
array(
545+
array(''),
546+
array('anything'),
547+
),
548+
'>"', // Compare to the single characater " (double quote)
549+
array(
550+
array(10),
551+
array(100),
552+
),
553+
100
554+
),
543555
);
544556
}
545557

0 commit comments

Comments
 (0)