From 097d349e9c33b64ad7361b3c0f69ee68002a75a9 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Mon, 11 Sep 2017 13:41:44 +0900 Subject: [PATCH] Fix code style --- src/PhpSpreadsheet/Calculation/MathTrig.php | 36 +++++++-------------- src/PhpSpreadsheet/Cell.php | 5 +-- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/PhpSpreadsheet/Calculation/MathTrig.php b/src/PhpSpreadsheet/Calculation/MathTrig.php index 89d5b6bc..1f9942c0 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig.php @@ -1127,16 +1127,20 @@ class MathTrig return Functions::VALUE(); } - protected static function filterHiddenArgs($cellReference, $args) { - return array_filter($args, + protected static function filterHiddenArgs($cellReference, $args) + { + return array_filter( + $args, function ($index) use ($cellReference) { list(, $row, $column) = explode('.', $index); + return $cellReference->getWorksheet()->getRowDimension($row)->getVisible() && $cellReference->getWorksheet()->getColumnDimension($column)->getVisible(); }, ARRAY_FILTER_USE_KEY ); } + /** * SUBTOTAL. * @@ -1153,53 +1157,35 @@ class MathTrig $aArgs = Functions::flattenArrayIndexed($args); $cellReference = array_pop($aArgs); $subtotal = array_shift($aArgs); -// var_dump($cellReference->getValue(), $aArgs); die(); // Calculate if ((is_numeric($subtotal)) && (!is_string($subtotal))) { + if ($subtotal > 100) { + $aArgs = self::filterHiddenArgs($cellReference, $aArgs); + $subtotal = $subtotal - 100; + } + switch ($subtotal) { - case 101: - $aArgs = self::filterHiddenArgs($cellReference, $aArgs); case 1: return Statistical::AVERAGE($aArgs); - case 102: - $aArgs = self::filterHiddenArgs($cellReference, $aArgs); case 2: return Statistical::COUNT($aArgs); - case 103: - $aArgs = self::filterHiddenArgs($cellReference, $aArgs); case 3: return Statistical::COUNTA($aArgs); - case 104: - $aArgs = self::filterHiddenArgs($cellReference, $aArgs); case 4: return Statistical::MAX($aArgs); - case 105: - $aArgs = self::filterHiddenArgs($cellReference, $aArgs); case 5: return Statistical::MIN($aArgs); - case 106: - $aArgs = self::filterHiddenArgs($cellReference, $aArgs); case 6: return self::PRODUCT($aArgs); - case 107: - $aArgs = self::filterHiddenArgs($cellReference, $aArgs); case 7: return Statistical::STDEV($aArgs); - case 108: - $aArgs = self::filterHiddenArgs($cellReference, $aArgs); case 8: return Statistical::STDEVP($aArgs); - case 109: - $aArgs = self::filterHiddenArgs($cellReference, $aArgs); case 9: return self::SUM($aArgs); - case 110: - $aArgs = self::filterHiddenArgs($cellReference, $aArgs); case 10: return Statistical::VARFunc($aArgs); - case 111: - $aArgs = self::filterHiddenArgs($cellReference, $aArgs); case 11: return Statistical::VARP($aArgs); } diff --git a/src/PhpSpreadsheet/Cell.php b/src/PhpSpreadsheet/Cell.php index 60b4c826..027d7671 100644 --- a/src/PhpSpreadsheet/Cell.php +++ b/src/PhpSpreadsheet/Cell.php @@ -862,7 +862,7 @@ class Cell */ public static function stringFromColumnIndex($columnIndex) { - static $indexCache = array(); + static $indexCache = []; if (!isset($indexCache[$columnIndex])) { $indexValue = $columnIndex + 1; @@ -870,10 +870,11 @@ class Cell do { $characterValue = ($indexValue % 26) ?: 26; $indexValue = ($indexValue - $characterValue) / 26; - $base26 = chr($characterValue + 64).($base26 ?: ''); + $base26 = chr($characterValue + 64) . ($base26 ?: ''); } while ($indexValue > 0); $indexCache[$columnIndex] = $base26; } + return $indexCache[$columnIndex]; }