public function PHPExcel_Calculation::calculateCellValue in Loft Data Grids 6.2
Same name and namespace in other branches
- 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation.php \PHPExcel_Calculation::calculateCellValue()
* Calculate the value of a cell formula * * @access public *
Parameters
PHPExcel_Cell $pCell Cell to calculate: * @param Boolean $resetLog Flag indicating whether the debug log should be reset or not * @return mixed * @throws PHPExcel_Calculation_Exception
1 call to PHPExcel_Calculation::calculateCellValue()
- PHPExcel_Calculation::calculate in vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Calculation.php - * Calculate cell value (using formula from a cell ID) * Retained for backward compatibility * * @access public *
File
- vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Calculation.php, line 2229
Class
- PHPExcel_Calculation
- PHPExcel_Calculation (Multiton)
Code
public function calculateCellValue(PHPExcel_Cell $pCell = NULL, $resetLog = TRUE) {
if ($pCell === NULL) {
return NULL;
}
$returnArrayAsType = self::$returnArrayAsType;
if ($resetLog) {
// Initialise the logging settings if requested
$this->formulaError = null;
$this->_debugLog
->clearLog();
$this->_cyclicReferenceStack
->clear();
$this->_cyclicFormulaCount = 1;
self::$returnArrayAsType = self::RETURN_ARRAY_AS_ARRAY;
}
// Execute the calculation for the cell formula
$this->_cellStack[] = array(
'sheet' => $pCell
->getWorksheet()
->getTitle(),
'cell' => $pCell
->getCoordinate(),
);
try {
$result = self::_unwrapResult($this
->_calculateFormulaValue($pCell
->getValue(), $pCell
->getCoordinate(), $pCell));
$cellAddress = array_pop($this->_cellStack);
$this->_workbook
->getSheetByName($cellAddress['sheet'])
->getCell($cellAddress['cell']);
} catch (PHPExcel_Exception $e) {
$cellAddress = array_pop($this->_cellStack);
$this->_workbook
->getSheetByName($cellAddress['sheet'])
->getCell($cellAddress['cell']);
throw new PHPExcel_Calculation_Exception($e
->getMessage());
}
if (is_array($result) && self::$returnArrayAsType != self::RETURN_ARRAY_AS_ARRAY) {
self::$returnArrayAsType = $returnArrayAsType;
$testResult = PHPExcel_Calculation_Functions::flattenArray($result);
if (self::$returnArrayAsType == self::RETURN_ARRAY_AS_ERROR) {
return PHPExcel_Calculation_Functions::VALUE();
}
// If there's only a single cell in the array, then we allow it
if (count($testResult) != 1) {
// If keys are numeric, then it's a matrix result rather than a cell range result, so we permit it
$r = array_keys($result);
$r = array_shift($r);
if (!is_numeric($r)) {
return PHPExcel_Calculation_Functions::VALUE();
}
if (is_array($result[$r])) {
$c = array_keys($result[$r]);
$c = array_shift($c);
if (!is_numeric($c)) {
return PHPExcel_Calculation_Functions::VALUE();
}
}
}
$result = array_shift($testResult);
}
self::$returnArrayAsType = $returnArrayAsType;
if ($result === NULL) {
return 0;
}
elseif (is_float($result) && (is_nan($result) || is_infinite($result))) {
return PHPExcel_Calculation_Functions::NaN();
}
return $result;
}