Merge pull request #228 from PowerKiKi/patch-sumif

Double quote support for SUMIF()
This commit is contained in:
Mark Baker 2013-10-31 07:03:07 -07:00
commit 8d51b6e90a
2 changed files with 67 additions and 1 deletions

View File

@ -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

View File

@ -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
),
);
} }
} }