Apply filter check on cells that already contain a subtotal calculation... will add unit tests later

This commit is contained in:
MarkBaker 2018-04-13 12:24:54 +01:00
parent 36acc37287
commit df34b15079
1 changed files with 16 additions and 0 deletions

View File

@ -1081,6 +1081,21 @@ class MathTrig
); );
} }
protected static function filterFormulaArgs($cellReference, $args)
{
return array_filter(
$args,
function ($index) use ($cellReference) {
list(, $row, $column) = explode('.', $index);
//take this cell out if it contains the SUBTOTAL formula
return strpos(strtoupper($cellReference->getWorksheet()->getCell($column . $row)->getValue()), '=SUBTOTAL(') === false;
},
ARRAY_FILTER_USE_KEY
);
}
/** /**
* SUBTOTAL. * SUBTOTAL.
* *
@ -1105,6 +1120,7 @@ class MathTrig
$subtotal = $subtotal - 100; $subtotal = $subtotal - 100;
} }
$aArgs = self::filterFormulaArgs($cellReference, $aArgs);
switch ($subtotal) { switch ($subtotal) {
case 1: case 1:
return Statistical::AVERAGE($aArgs); return Statistical::AVERAGE($aArgs);