Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250620) (7d9030acd6e)
PhpOffice\PhpSpreadsheet\Calculation\Calculation Class Reference

Public Member Functions

 __construct (?Spreadsheet $spreadsheet=null)
 
 __clone ()
 __clone implementation.
 
 _calculateFormulaValue (string $formula, ?string $cellID=null, ?Cell $cell=null, bool $ignoreQuotePrefix=false)
 Parse a cell formula and calculate its value.
 
 calculate (?Cell $cell=null)
 Calculate cell value (using formula from a cell ID) Retained for backward compatibility.
 
 calculateCellValue (?Cell $cell=null, bool $resetLog=true)
 Calculate the value of a cell formula.
 
 calculateFormula (string $formula, ?string $cellID=null, ?Cell $cell=null)
 Calculate the value of a formula.
 
 clearCalculationCache ()
 Clear calculation cache.
 
 clearCalculationCacheForWorksheet (string $worksheetName)
 Clear calculation cache for a specified worksheet.
 
 disableBranchPruning ()
 
 disableCalculationCache ()
 Disable calculation cache.
 
 enableBranchPruning ()
 
 enableCalculationCache ()
 Enable calculation cache.
 
 extractCellRange (string &$range='A1', ?Worksheet $worksheet=null, bool $resetLog=true)
 Extract range values.
 
 extractNamedRange (string &$range='A1', ?Worksheet $worksheet=null, bool $resetLog=true)
 Extract range values.
 
 flushInstance ()
 Flush the calculation cache for any existing instance of this class but only if a Calculation instance exists.
 
 getCalculationCacheEnabled ()
 Is calculation caching enabled?
 
 getDebugLog ()
 Get the Logger for this calculation engine instance.
 
 getImplementedFunctionNames ()
 Get a list of implemented Excel function names.
 
 getInstanceArrayReturnType ()
 Return the Array Return Type (Array or Value of first element in the array).
 
 getLocale ()
 Get the currently defined locale code.
 
 getSuppressFormulaErrors ()
 
 getValueFromCache (string $cellReference, mixed &$cellValue)
 
 isImplemented (string $function)
 Is a specific function implemented?
 
 parseFormula (string $formula)
 Validate and parse a formula string.
 
 renameCalculationCacheForWorksheet (string $fromWorksheetName, string $toWorksheetName)
 Rename calculation cache for a specified worksheet.
 
 saveValueToCache (string $cellReference, mixed $cellValue)
 
 setBranchPruningEnabled (mixed $enabled)
 Enable/disable calculation cache.
 
 setCalculationCacheEnabled (bool $calculationCacheEnabled)
 Enable/disable calculation cache.
 
 setInstanceArrayReturnType (string $returnType)
 Set the Instance Array Return Type (Array or Value of first element in the array).
 
 setLocale (string $locale)
 Set the locale code.
 
 setSuppressFormulaErrors (bool $suppressFormulaErrors)
 
 translateFormulaToEnglish (string $formula)
 
 translateFormulaToLocale (string $formula)
 

Static Public Member Functions

static boolToString (mixed $operand1)
 
static checkMatrixOperands (mixed &$operand1, mixed &$operand2, int $resize=1)
 Ensure that paired matrix operands are both matrices and of the same size.
 
static getArrayReturnType ()
 Return the Array Return Type (Array or Value of first element in the array).
 
static getExcelConstants (string $key)
 
static getFALSE ()
 Return the locale-specific translation of FALSE.
 
static getFunctions ()
 Get a list of all implemented functions as an array of function objects.
 
static getInstance (?Spreadsheet $spreadsheet=null)
 Get an instance of this class.
 
static static getLocaleBoolean (string $index)
 
static getMatrixDimensions (array &$matrix)
 Read the dimensions of a matrix, and re-index it with straight numeric keys starting from row 0, column 0.
 
static getTRUE ()
 Return the locale-specific translation of TRUE.
 
static array< string, array $excelConstants=[ 'TRUE'=> static keyInExcelConstants (string $key)
 
static localeFunc (string $function)
 
static setArrayReturnType (string $returnType)
 Set the Array Return Type (Array or Value of first element in the array).
 
static translateSeparator (string $fromSeparator, string $toSeparator, string $formula, int &$inBracesLevel, string $openBrace=self::FORMULA_OPEN_FUNCTION_BRACE, string $closeBrace=self::FORMULA_CLOSE_FUNCTION_BRACE)
 
static unwrapResult (mixed $value)
 Remove quotes used as a wrapper to identify string values.
 
static wrapResult (mixed $value)
 Wrap string values in quotes.
 

Public Attributes

int $cyclicFormulaCount = 1
 Number of iterations for cyclic formulae.
 
return $falseTrueArray
 
string $formulaError = null
 Error message for any error that was raised/thrown by the calculation engine.
 
catch(Exception $e) $localeFunctions = file($functionNamesFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: []
 
const CALCULATION_REGEXP_CELLREF = '((([^\s,!&%^\/\*::+<>=:`-]*)|(::'(?:[^::']|'[^!])+?::')|(::"(?:[^::"]|"[^!])+?::"))!)?::$?::b([a-z]{1,3})::$?(::d{1,7})(?![::w.])'
 
const CALCULATION_REGEXP_CELLREF_RELATIVE = '((([^\s\(,!&%^\/\*::+<>=:`-]*)|(::'(?:[^::']|'[^!])+?::')|(::"(?:[^::"]|"[^!])+?::"))!)?(::$?::b[a-z]{1,3})(::$?::d{1,7})(?![::w.])'
 
const CALCULATION_REGEXP_CELLREF_SPILL = '/' . self::CALCULATION_REGEXP_CELLREF . '#/i'
 
const CALCULATION_REGEXP_COLUMN_RANGE = '(((([^\s\(,!&%^\/\*::+<>=:`-]*)|(::'(?:[^::']|'[^!])+?::')|(::".(?:[^::"]|"[^!])?::"))!)?(::$?[a-z]{1,3})):(?![.*])'
 
const CALCULATION_REGEXP_COLUMNRANGE_RELATIVE = '(\$?[a-z]{1,3}):(\$?[a-z]{1,3})'
 
const CALCULATION_REGEXP_DEFINEDNAME = '((([^\s,!&%^\/\*::+<>=-]*)|(::'(?:[^::']|'[^!])+?::')|(::"(?:[^::"]|"[^!])+?::"))!)?([_::p{L}][_::p{L}::p{N}::.]*)'
 
const CALCULATION_REGEXP_ERROR = '\#[A-Z][A-Z0_\/]*[!::?]?'
 
const CALCULATION_REGEXP_FUNCTION = '@?(?:_xlfn\.)?(?:_xlws\.)?([\p{L}][\p{L}\p{N}\.]*)[::s]*::('
 
file home runner work phpdoc phpdoc moodle lib phpspreadsheet phpspreadsheet src PhpSpreadsheet Calculation Calculation php const CALCULATION_REGEXP_NUMBER = '[-+]?\d*::.?::d+(e[-+]?::d+)?'
 Constants.
 
const CALCULATION_REGEXP_OPENBRACE = '\‍('
 
const CALCULATION_REGEXP_ROW_RANGE = '(((([^\s\(,!&%^\/\*::+<>=:`-]*)|(::'(?:[^::']|'[^!])+?::')|(::"(?:[^::"]|"[^!])+?::"))!)?(::$?[1-9][0-9]{0,6})):(?![.*])'
 
const CALCULATION_REGEXP_ROWRANGE_RELATIVE = '(\$?\d{1,7}):(\$?\d{1,7})'
 
const CALCULATION_REGEXP_STRING = '"(?:[^"]|"")*"'
 
const CALCULATION_REGEXP_STRIP_XLFN_XLWS = '/(_xlfn[.])?(_xlws[.])?(?=[\p{L}][\p{L}\p{N}\.]*[::s]*[(])/'
 
const CALCULATION_REGEXP_STRUCTURED_REFERENCE = '([\p{L}_\\\][\p{L}\p{N}\._]+)?(\[(?:[^\d\]+-])?)'
 
const FORMULA_CLOSE_FUNCTION_BRACE = ')'
 
const FORMULA_CLOSE_MATRIX_BRACE = '}'
 
const FORMULA_OPEN_FUNCTION_BRACE = '('
 
const FORMULA_OPEN_MATRIX_BRACE = '{'
 
const FORMULA_STRING_QUOTE = '"'
 
const RETURN_ARRAY_AS_ARRAY = 'array'
 
const RETURN_ARRAY_AS_ERROR = 'error'
 constants
 
const RETURN_ARRAY_AS_VALUE = 'value'
 

Protected Member Functions

 raiseFormulaError (string $errorMessage, int $code=0, ?Throwable $exception=null)
 Trigger an error, but nicely, if need be.
 

Member Function Documentation

◆ __clone()

PhpOffice\PhpSpreadsheet\Calculation\Calculation::__clone ( )
final

__clone implementation.

Cloning should not be allowed in a Singleton!

◆ _calculateFormulaValue()

PhpOffice\PhpSpreadsheet\Calculation\Calculation::_calculateFormulaValue ( string $formula,
?string $cellID = null,
?Cell $cell = null,
bool $ignoreQuotePrefix = false )

Parse a cell formula and calculate its value.

Parameters
string$formulaThe formula to parse and calculate
?string$cellIDThe ID (e.g. A3) of the cell that we are calculating
?Cell$cellCell to calculate
bool$ignoreQuotePrefixIf set to true, evaluate the formyla even if the referenced cell is quote prefixed

◆ calculate()

PhpOffice\PhpSpreadsheet\Calculation\Calculation::calculate ( ?Cell $cell = null)

Calculate cell value (using formula from a cell ID) Retained for backward compatibility.

Parameters
?Cell$cellCell to calculate

◆ calculateCellValue()

PhpOffice\PhpSpreadsheet\Calculation\Calculation::calculateCellValue ( ?Cell $cell = null,
bool $resetLog = true )

Calculate the value of a cell formula.

Parameters
?Cell$cellCell to calculate
bool$resetLogFlag indicating whether the debug log should be reset or not

◆ calculateFormula()

PhpOffice\PhpSpreadsheet\Calculation\Calculation::calculateFormula ( string $formula,
?string $cellID = null,
?Cell $cell = null )

Calculate the value of a formula.

Parameters
string$formulaFormula to parse
?string$cellIDAddress of the cell to calculate
?Cell$cellCell to calculate

◆ checkMatrixOperands()

static PhpOffice\PhpSpreadsheet\Calculation\Calculation::checkMatrixOperands ( mixed & $operand1,
mixed & $operand2,
int $resize = 1 )
static

Ensure that paired matrix operands are both matrices and of the same size.

Parameters
mixed$operand1First matrix operand
mixed$operand2Second matrix operand
int$resizeFlag indicating whether the matrices should be resized to match and (if so), whether the smaller dimension should grow or the larger should shrink. 0 = no resize 1 = shrink to fit 2 = extend to fit

◆ extractCellRange()

PhpOffice\PhpSpreadsheet\Calculation\Calculation::extractCellRange ( string & $range = 'A1',
?Worksheet $worksheet = null,
bool $resetLog = true )

Extract range values.

Parameters
string$rangeString based range representation
?Worksheet$worksheetWorksheet
bool$resetLogFlag indicating whether calculation log should be reset or not
Return values
arrayArray of values in range if range contains more than one element. Otherwise, a single value is returned.

◆ extractNamedRange()

PhpOffice\PhpSpreadsheet\Calculation\Calculation::extractNamedRange ( string & $range = 'A1',
?Worksheet $worksheet = null,
bool $resetLog = true )

Extract range values.

Parameters
string$rangeString based range representation
null | Worksheet$worksheetWorksheet
bool$resetLogFlag indicating whether calculation log should be reset or not
Return values
array|stringArray of values in range if range contains more than one element. Otherwise, a single value is returned.

◆ getArrayReturnType()

static PhpOffice\PhpSpreadsheet\Calculation\Calculation::getArrayReturnType ( )
static

Return the Array Return Type (Array or Value of first element in the array).

Return values
string#$returnTypeArray return type

◆ getFALSE()

static PhpOffice\PhpSpreadsheet\Calculation\Calculation::getFALSE ( )
static

Return the locale-specific translation of FALSE.

Return values
stringlocale-specific translation of FALSE

◆ getInstance()

static PhpOffice\PhpSpreadsheet\Calculation\Calculation::getInstance ( ?Spreadsheet $spreadsheet = null)
static

Get an instance of this class.

Parameters
?Spreadsheet$spreadsheetInjected spreadsheet for working with a PhpSpreadsheet Spreadsheet object, or NULL to create a standalone calculation engine

◆ getInstanceArrayReturnType()

PhpOffice\PhpSpreadsheet\Calculation\Calculation::getInstanceArrayReturnType ( )

Return the Array Return Type (Array or Value of first element in the array).

Return values
string#$returnTypeArray return type for instance if non-null, otherwise static property

◆ getMatrixDimensions()

static PhpOffice\PhpSpreadsheet\Calculation\Calculation::getMatrixDimensions ( array & $matrix)
static

Read the dimensions of a matrix, and re-index it with straight numeric keys starting from row 0, column 0.

Parameters
array$matrixmatrix operand
Return values
int[]An array comprising the number of rows, and number of columns

◆ getTRUE()

static PhpOffice\PhpSpreadsheet\Calculation\Calculation::getTRUE ( )
static

Return the locale-specific translation of TRUE.

Return values
stringlocale-specific translation of TRUE

◆ isImplemented()

PhpOffice\PhpSpreadsheet\Calculation\Calculation::isImplemented ( string $function)

Is a specific function implemented?

Parameters
string$functionFunction Name

◆ parseFormula()

PhpOffice\PhpSpreadsheet\Calculation\Calculation::parseFormula ( string $formula)

Validate and parse a formula string.

Parameters
string$formulaFormula to parse

◆ raiseFormulaError()

PhpOffice\PhpSpreadsheet\Calculation\Calculation::raiseFormulaError ( string $errorMessage,
int $code = 0,
?Throwable $exception = null )
protected

Trigger an error, but nicely, if need be.

Return values
false

◆ setArrayReturnType()

static PhpOffice\PhpSpreadsheet\Calculation\Calculation::setArrayReturnType ( string $returnType)
static

Set the Array Return Type (Array or Value of first element in the array).

Parameters
string$returnTypeArray return type
Return values
boolSuccess or failure

◆ setInstanceArrayReturnType()

PhpOffice\PhpSpreadsheet\Calculation\Calculation::setInstanceArrayReturnType ( string $returnType)

Set the Instance Array Return Type (Array or Value of first element in the array).

Parameters
string$returnTypeArray return type
Return values
boolSuccess or failure

◆ setLocale()

PhpOffice\PhpSpreadsheet\Calculation\Calculation::setLocale ( string $locale)

Set the locale code.

Parameters
string$localeThe locale to use for formula translation, eg: 'en_us'

Member Data Documentation

◆ CALCULATION_REGEXP_NUMBER

file home runner work phpdoc phpdoc moodle lib phpspreadsheet phpspreadsheet src PhpSpreadsheet Calculation Calculation php const PhpOffice\PhpSpreadsheet\Calculation\Calculation::CALCULATION_REGEXP_NUMBER = '[-+]?\d*::.?::d+(e[-+]?::d+)?'

Constants.

Regular Expressions


The documentation for this class was generated from the following file: