Initial implementation of SUMIFS() function
This commit is contained in:
parent
bb7b48d94c
commit
84011f8d57
|
@ -28,6 +28,7 @@ Planned for 1.9
|
||||||
- Bugfix: (ncrypthic) Work Item GH-570 - Ignore inlineStr type if formula element exists
|
- Bugfix: (ncrypthic) Work Item GH-570 - Ignore inlineStr type if formula element exists
|
||||||
- Bugfix: (MBaker) Work Item GH-554 - Whitespace after toRichTextObject()
|
- Bugfix: (MBaker) Work Item GH-554 - Whitespace after toRichTextObject()
|
||||||
- General: (umpirsky) Work Item GH-548 - Optimize vlookup() sort
|
- General: (umpirsky) Work Item GH-548 - Optimize vlookup() sort
|
||||||
|
- Feature: (MBaker) - Initial implementation of SUMIFS() function
|
||||||
|
|
||||||
2015-04-30 (v1.8.1):
|
2015-04-30 (v1.8.1):
|
||||||
- Bugfix: (goncons) Work Item GH-397 - Fix for Writing an Open Document cell with non-numeric formula
|
- Bugfix: (goncons) Work Item GH-397 - Fix for Writing an Open Document cell with non-numeric formula
|
||||||
|
|
|
@ -1807,8 +1807,8 @@ class Calculation
|
||||||
),
|
),
|
||||||
'SUMIFS' => array(
|
'SUMIFS' => array(
|
||||||
'category' => Calculation\Categories::CATEGORY_MATH_AND_TRIG,
|
'category' => Calculation\Categories::CATEGORY_MATH_AND_TRIG,
|
||||||
'functionCall' => 'Calculation\Categories::DUMMY',
|
'functionCall' => '\\PHPExcel\\Calculation\\MathTrig::SUMIFS',
|
||||||
'argumentCount' => '?'
|
'argumentCount' => '3+'
|
||||||
),
|
),
|
||||||
'SUMPRODUCT' => array(
|
'SUMPRODUCT' => array(
|
||||||
'category' => Calculation\Categories::CATEGORY_MATH_AND_TRIG,
|
'category' => Calculation\Categories::CATEGORY_MATH_AND_TRIG,
|
||||||
|
|
|
@ -1212,6 +1212,53 @@ class MathTrig
|
||||||
return $returnValue;
|
return $returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SUMIFS
|
||||||
|
*
|
||||||
|
* Counts the number of cells that contain numbers within the list of arguments
|
||||||
|
*
|
||||||
|
* Excel Function:
|
||||||
|
* SUMIFS(value1[,value2[, ...]],condition)
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @category Mathematical and Trigonometric Functions
|
||||||
|
* @param mixed $arg,... Data values
|
||||||
|
* @param string $condition The criteria that defines which cells will be summed.
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
public static function SUMIFS() {
|
||||||
|
$arrayList = func_get_args();
|
||||||
|
|
||||||
|
// Return value
|
||||||
|
$returnValue = 0;
|
||||||
|
|
||||||
|
$sumArgs = Functions::flattenArray(array_shift($arrayList));
|
||||||
|
|
||||||
|
while (count($arrayList) > 0) {
|
||||||
|
$aArgsArray[] = Functions::flattenArray(array_shift($arrayList));
|
||||||
|
$conditions[] = Functions::ifCondition(array_shift($arrayList));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through each set of arguments and conditions
|
||||||
|
foreach ($conditions as $index => $condition) {
|
||||||
|
$aArgs = $aArgsArray[$index];
|
||||||
|
|
||||||
|
// Loop through arguments
|
||||||
|
foreach ($aArgs as $key => $arg) {
|
||||||
|
if (!is_numeric($arg)) {
|
||||||
|
$arg = \PHPExcel\Calculation::wrapResult(strtoupper($arg));
|
||||||
|
}
|
||||||
|
$testCondition = '='.$arg.$condition;
|
||||||
|
if (\PHPExcel\Calculation::getInstance()->_calculateFormulaValue($testCondition)) {
|
||||||
|
// Is it a value within our criteria
|
||||||
|
$returnValue += $sumArgs[$key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return
|
||||||
|
return $returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SUMPRODUCT
|
* SUMPRODUCT
|
||||||
|
|
Loading…
Reference in New Issue