You are here

public function PHPExcel_Cell::getCalculatedValue in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Cell.php \PHPExcel_Cell::getCalculatedValue()

* Get calculated cell value * *

Parameters

boolean $resetLog Whether the calculation engine logger should be reset or not: * @return mixed * @throws PHPExcel_Exception

Deprecated

Since version 1.7.8 for planned changes to cell for array formula handling * *

1 call to PHPExcel_Cell::getCalculatedValue()
PHPExcel_Cell::getFormattedValue in vendor/phpoffice/phpexcel/Classes/PHPExcel/Cell.php
* Get cell value with formatting * *

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Cell.php, line 270

Class

PHPExcel_Cell
PHPExcel_Cell

Code

public function getCalculatedValue($resetLog = TRUE) {

  //echo 'Cell '.$this->getCoordinate().' value is a '.$this->_dataType.' with a value of '.$this->getValue().PHP_EOL;
  if ($this->_dataType == PHPExcel_Cell_DataType::TYPE_FORMULA) {
    try {

      //echo 'Cell value for '.$this->getCoordinate().' is a formula: Calculating value'.PHP_EOL;
      $result = PHPExcel_Calculation::getInstance($this
        ->getWorksheet()
        ->getParent())
        ->calculateCellValue($this, $resetLog);

      //echo $this->getCoordinate().' calculation result is '.$result.PHP_EOL;

      //	We don't yet handle array returns
      if (is_array($result)) {
        while (is_array($result)) {
          $result = array_pop($result);
        }
      }
    } catch (PHPExcel_Exception $ex) {
      if ($ex
        ->getMessage() === 'Unable to access External Workbook' && $this->_calculatedValue !== NULL) {

        //echo 'Returning fallback value of '.$this->_calculatedValue.' for cell '.$this->getCoordinate().PHP_EOL;
        return $this->_calculatedValue;

        // Fallback for calculations referencing external files.
      }

      //echo 'Calculation Exception: '.$ex->getMessage().PHP_EOL;
      $result = '#N/A';
      throw new PHPExcel_Calculation_Exception($this
        ->getWorksheet()
        ->getTitle() . '!' . $this
        ->getCoordinate() . ' -> ' . $ex
        ->getMessage());
    }
    if ($result === '#Not Yet Implemented') {

      //echo 'Returning fallback value of '.$this->_calculatedValue.' for cell '.$this->getCoordinate().PHP_EOL;
      return $this->_calculatedValue;

      // Fallback if calculation engine does not support the formula.
    }

    //echo 'Returning calculated value of '.$result.' for cell '.$this->getCoordinate().PHP_EOL;
    return $result;
  }
  elseif ($this->_value instanceof PHPExcel_RichText) {

    //		echo 'Cell value for '.$this->getCoordinate().' is rich text: Returning data value of '.$this->_value.'<br />';
    return $this->_value
      ->getPlainText();
  }

  //		echo 'Cell value for '.$this->getCoordinate().' is not a formula: Returning data value of '.$this->_value.'<br />';
  return $this->_value;
}