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); } }