Double quote support for SUMIF()
SUMIF() should handle double quotes properly in both criteria and cells values. This is especially useful when we need to compare string containing themselve double quote(s).
This commit is contained in:
parent
2dcff606f7
commit
f1a1f525ea
|
@ -1164,7 +1164,11 @@ class PHPExcel_Calculation_MathTrig {
|
||||||
$condition = PHPExcel_Calculation_Functions::_ifCondition($condition);
|
$condition = PHPExcel_Calculation_Functions::_ifCondition($condition);
|
||||||
// Loop through arguments
|
// Loop through arguments
|
||||||
foreach ($aArgs as $key => $arg) {
|
foreach ($aArgs as $key => $arg) {
|
||||||
if (!is_numeric($arg)) { $arg = PHPExcel_Calculation::_wrapResult(strtoupper($arg)); }
|
if (!is_numeric($arg)) {
|
||||||
|
$arg = str_replace('"', '""', $arg);
|
||||||
|
$arg = PHPExcel_Calculation::_wrapResult(strtoupper($arg));
|
||||||
|
}
|
||||||
|
|
||||||
$testCondition = '='.$arg.$condition;
|
$testCondition = '='.$arg.$condition;
|
||||||
if (PHPExcel_Calculation::getInstance()->_calculateFormulaValue($testCondition)) {
|
if (PHPExcel_Calculation::getInstance()->_calculateFormulaValue($testCondition)) {
|
||||||
// Is it a value within our criteria
|
// Is it a value within our criteria
|
||||||
|
|
|
@ -479,6 +479,68 @@ class MathTrigTest extends PHPUnit_Framework_TestCase
|
||||||
public function providerSQRTPI()
|
public function providerSQRTPI()
|
||||||
{
|
{
|
||||||
return new testDataFileIterator('rawTestData/Calculation/MathTrig/SQRTPI.data');
|
return new testDataFileIterator('rawTestData/Calculation/MathTrig/SQRTPI.data');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerSUMIF
|
||||||
|
*/
|
||||||
|
public function testSUMIF()
|
||||||
|
{
|
||||||
|
$args = func_get_args();
|
||||||
|
$expectedResult = array_pop($args);
|
||||||
|
$result = call_user_func_array(array('PHPExcel_Calculation_MathTrig', 'SUMIF'), $args);
|
||||||
|
$this->assertEquals($expectedResult, $result, NULL, 1E-12);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerSUMIF()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
array(1),
|
||||||
|
array(5),
|
||||||
|
array(10),
|
||||||
|
),
|
||||||
|
'>=5',
|
||||||
|
15,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
array('text'),
|
||||||
|
array(2),
|
||||||
|
),
|
||||||
|
'=text',
|
||||||
|
array(
|
||||||
|
array(10),
|
||||||
|
array(100),
|
||||||
|
),
|
||||||
|
10,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
array('"text with quotes"'),
|
||||||
|
array(2),
|
||||||
|
),
|
||||||
|
'=""text with quotes""',
|
||||||
|
array(
|
||||||
|
array(10),
|
||||||
|
array(100),
|
||||||
|
),
|
||||||
|
10,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
array('"text with quotes"'),
|
||||||
|
array(''),
|
||||||
|
),
|
||||||
|
'>""', // Compare to the single characater " (double quote)
|
||||||
|
array(
|
||||||
|
array(10),
|
||||||
|
array(100),
|
||||||
|
),
|
||||||
|
10
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue