Example #1
0
 private function calculateTopTenValue($columnID, $startRow, $endRow, $ruleType, $ruleValue)
 {
     $range = $columnID . $startRow . ':' . $columnID . $endRow;
     $dataValues = \PHPExcel\Calculation\Functions::flattenArray($this->workSheet->rangeToArray($range, null, true, false));
     $dataValues = array_filter($dataValues);
     if ($ruleType == AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_TOP) {
         rsort($dataValues);
     } else {
         sort($dataValues);
     }
     return array_pop(array_slice($dataValues, 0, $ruleValue));
 }
 public function refresh(\PHPExcel\Worksheet $worksheet, $flatten = true)
 {
     if ($this->dataSource !== null) {
         $calcEngine = \PHPExcel\Calculation::getInstance($worksheet->getParent());
         $newDataValues = \PHPExcel\Calculation::unwrapResult($calcEngine->_calculateFormulaValue('=' . $this->dataSource, null, $worksheet->getCell('A1')));
         if ($flatten) {
             $this->dataValues = \PHPExcel\Calculation\Functions::flattenArray($newDataValues);
             foreach ($this->dataValues as &$dataValue) {
                 if (!empty($dataValue) && $dataValue[0] == '#') {
                     $dataValue = 0.0;
                 }
             }
             unset($dataValue);
         } else {
             $cellRange = explode('!', $this->dataSource);
             if (count($cellRange) > 1) {
                 list(, $cellRange) = $cellRange;
             }
             $dimensions = \PHPExcel\Cell::rangeDimension(str_replace('$', '', $cellRange));
             if ($dimensions[0] == 1 || $dimensions[1] == 1) {
                 $this->dataValues = \PHPExcel\Calculation\Functions::flattenArray($newDataValues);
             } else {
                 $newArray = array_values(array_shift($newDataValues));
                 foreach ($newArray as $i => $newDataSet) {
                     $newArray[$i] = array($newDataSet);
                 }
                 foreach ($newDataValues as $newDataSet) {
                     $i = 0;
                     foreach ($newDataSet as $newDataVal) {
                         array_unshift($newArray[$i++], $newDataVal);
                     }
                 }
                 $this->dataValues = $newArray;
             }
         }
         $this->pointCount = count($this->dataValues);
     }
 }