Vendor/phpspreadsheet/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php
public function calculateFormula($formula, $cellID = null, Cell $pCell = null)
    {
        //    Initialise the logging settings
        $this->formulaError = null;
        $this->debugLog->clearLog();
        $this->cyclicReferenceStack->clear();

        if ($this->spreadsheet !== null && $cellID === null && $pCell === null) {
            $cellID = 'A1';
            $pCell = $this->spreadsheet->getActiveSheet()->getCell($cellID);
        } else {
            //    Disable calculation cacheing because it only applies to cell calculations, not straight formulae
            //    But don't actually flush any cache
            $resetCache = $this->getCalculationCacheEnabled();
            $this->calculationCacheEnabled = false;
        }

        //    Execute the calculation
        try {
            $result = self::unwrapResult($this->_calculateFormulaValue($formula, $cellID, $pCell));
        } catch (\Exception $e) {
            throw new Exception($e->getMessage());
        }

        if ($this->spreadsheet === null) {
            //    Reset calculation cacheing to its previous state
            $this->calculationCacheEnabled = $resetCache;
        }

        return $result;
    }
public function calculateFormula($formula, $cellID = null, Cell $pCell = null)
    {
        //    Initialise the logging settings
        $this->formulaError = null;
        $this->debugLog->clearLog();
        $this->cyclicReferenceStack->clear();

        if ($this->spreadsheet !== null && $cellID === null && $pCell === null) {
            $cellID = 'A1';
            $pCell = $this->spreadsheet->getActiveSheet()->getCell($cellID);
        } else {
            //    Disable calculation cacheing because it only applies to cell calculations, not straight formulae
            //    But don't actually flush any cache
            $resetCache = $this->getCalculationCacheEnabled();
            $this->calculationCacheEnabled = false;
        }

        //    Execute the calculation
        try {
            $result = self::unwrapResult($this->_calculateFormulaValue($formula, $cellID, $pCell));
        } catch (\Exception $e) {
            throw new Exception($e->getMessage());
        }

        if ($this->spreadsheet === null) {
            //    Reset calculation cacheing to its previous state
            $this->calculationCacheEnabled = $resetCache;
        }

        return $result;
    }
public function calculateFormula ( $ formula , $ cellID = null , Cell $ pCell = null ) { //    Initialise the logging settings $ this -> formulaError = null ; $ this -> debugLog -> clearLog ( ) ; $ this -> cyclicReferenceStack -> clear ( ) ; if ( $ this -> spreadsheet !== null && $ cellID === null && $ pCell === null ) { $ cellID = 'A1' ; $ pCell = $ this -> spreadsheet -> getActiveSheet ( ) -> getCell ( $ cellID ) ; } else { //    Disable calculation cacheing because it only applies to cell calculations, not straight formulae //    But don't actually flush any cache $ resetCache = $ this -> getCalculationCacheEnabled ( ) ; $ this -> calculationCacheEnabled = false ; } //    Execute the calculation try { $ result = self :: unwrapResult ( $ this -> _calculateFormulaValue ( $ formula , $ cellID , $ pCell ) ) ; } catch ( \ Exception $ e ) { throw new Exception ( $ e -> getMessage ( ) ) ; } if ( $ this -> spreadsheet === null ) { //    Reset calculation cacheing to its previous state $ this -> calculationCacheEnabled = $ resetCache ; } return $ result ; }
Calculate the value of a formula.

@param string $formula Formula to parse
@param string $cellID Address of the cell to calculate
@param Cell $pCell Cell to calculate

@throws Exception

@return mixed
Calculate the value of a formula .