Initial implementation of SUMIFS() function

This commit is contained in:
MarkBaker 2015-11-09 21:39:35 +00:00
parent bb7b48d94c
commit 84011f8d57
3 changed files with 51 additions and 3 deletions

View File

@ -28,6 +28,7 @@ Planned for 1.9
- Bugfix: (ncrypthic) Work Item GH-570 - Ignore inlineStr type if formula element exists
- Bugfix: (MBaker) Work Item GH-554 - Whitespace after toRichTextObject()
- General: (umpirsky) Work Item GH-548 - Optimize vlookup() sort
- Feature: (MBaker) - Initial implementation of SUMIFS() function
2015-04-30 (v1.8.1):
- Bugfix: (goncons) Work Item GH-397 - Fix for Writing an Open Document cell with non-numeric formula
@ -68,7 +69,7 @@ Planned for 1.9
Reference CVE-2015-3542 - Identification of problem courtesy of Dawid Golunski (Pentest Ltd.)
2014-03-02 (v1.8.0):
2014-03-02 (v1.8.0):
- Bugfix: (MBaker) Work item CP19830 - Undefined variable: fileHandle in CSV Reader
- Bugfix: (MBaker) Work item CP19968 - Out of memory in style/supervisor.php
- Bugfix: (MBaker) - Style error with merged cells in PDF Writer

View File

@ -1807,8 +1807,8 @@ class Calculation
),
'SUMIFS' => array(
'category' => Calculation\Categories::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'Calculation\Categories::DUMMY',
'argumentCount' => '?'
'functionCall' => '\\PHPExcel\\Calculation\\MathTrig::SUMIFS',
'argumentCount' => '3+'
),
'SUMPRODUCT' => array(
'category' => Calculation\Categories::CATEGORY_MATH_AND_TRIG,

View File

@ -1212,6 +1212,53 @@ class MathTrig
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