class Calculation (View source)

Constants

CALCULATION_REGEXP_NUMBER

CALCULATION_REGEXP_STRING

CALCULATION_REGEXP_OPENBRACE

CALCULATION_REGEXP_FUNCTION

CALCULATION_REGEXP_CELLREF

CALCULATION_REGEXP_NAMEDRANGE

CALCULATION_REGEXP_ERROR

RETURN_ARRAY_AS_ERROR

constants

RETURN_ARRAY_AS_VALUE

RETURN_ARRAY_AS_ARRAY

Properties

bool $suppressFormulaErrors Flag to determine how formula errors should be handled If true, then a user error will be triggered If false, then an exception will be thrown.
string $formulaError Error message for any error that was raised/thrown by the calculation engine.
int $cyclicFormulaCount Number of iterations for cyclic formulae.
static string[] $localeBoolean Locale-specific translations for Excel constants (True, False and Null).

Methods

__construct(Spreadsheet $spreadsheet = null)

No description

static Calculation
getInstance(Spreadsheet $spreadsheet = null)

Get an instance of this class.

flushInstance()

Flush the calculation cache for any existing instance of this class but only if a Calculation instance exists.

getDebugLog()

Get the Logger for this calculation engine instance.

__clone()

__clone implementation. Cloning should not be allowed in a Singleton!

static string
getTRUE()

Return the locale-specific translation of TRUE.

static string
getFALSE()

Return the locale-specific translation of FALSE.

static bool
setArrayReturnType(string $returnType)

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

static string
getArrayReturnType()

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

bool
getCalculationCacheEnabled()

Is calculation caching enabled?

setCalculationCacheEnabled(bool $pValue)

Enable/disable calculation cache.

enableCalculationCache()

Enable calculation cache.

disableCalculationCache()

Disable calculation cache.

clearCalculationCache()

Clear calculation cache.

clearCalculationCacheForWorksheet(string $worksheetName)

Clear calculation cache for a specified worksheet.

renameCalculationCacheForWorksheet(string $fromWorksheetName, string $toWorksheetName)

Rename calculation cache for a specified worksheet.

setBranchPruningEnabled($enabled)

Enable/disable calculation cache.

enableBranchPruning()

No description

disableBranchPruning()

No description

clearBranchStore()

No description

string
getLocale()

Get the currently defined locale code.

bool
setLocale(string $locale)

Set the locale code.

static string
translateSeparator(string $fromSeparator, string $toSeparator, string $formula, bool $inBraces)

No description

_translateFormulaToLocale($formula)

No description

_translateFormulaToEnglish($formula)

No description

static 
localeFunc($function)

No description

static mixed
wrapResult(mixed $value)

Wrap string values in quotes.

static mixed
unwrapResult(mixed $value)

Remove quotes used as a wrapper to identify string values.

mixed
calculate(Cell $pCell = null)

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

mixed
calculateCellValue(Cell $pCell = null, bool $resetLog = true)

Calculate the value of a cell formula.

array|bool
parseFormula(string $formula)

Validate and parse a formula string.

mixed
calculateFormula(string $formula, string $cellID = null, Cell $pCell = null)

Calculate the value of a formula.

bool
getValueFromCache(string $cellReference, mixed $cellValue)

No description

saveValueToCache(string $cellReference, mixed $cellValue)

No description

mixed
_calculateFormulaValue(string $formula, string $cellID = null, Cell $pCell = null)

Parse a cell formula and calculate its value.

static int[]
getMatrixDimensions(array $matrix)

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

raiseFormulaError($errorMessage)

No description

mixed
extractCellRange(string $pRange = 'A1', Worksheet $pSheet = null, bool $resetLog = true)

Extract range values.

mixed
extractNamedRange(string $pRange = 'A1', Worksheet $pSheet = null, bool $resetLog = true)

Extract range values.

bool
isImplemented(string $pFunction)

Is a specific function implemented?

array
getFunctions()

Get a list of all implemented functions as an array of function objects.

array
getImplementedFunctionNames()

Get a list of implemented Excel function names.

Details

__construct(Spreadsheet $spreadsheet = null)

Parameters

Spreadsheet $spreadsheet

static Calculation getInstance(Spreadsheet $spreadsheet = null)

Get an instance of this class.

Parameters

Spreadsheet $spreadsheet Injected spreadsheet for working with a PhpSpreadsheet Spreadsheet object, or NULL to create a standalone claculation engine

Return Value

Calculation

flushInstance()

Flush the calculation cache for any existing instance of this class but only if a Calculation instance exists.

Logger getDebugLog()

Get the Logger for this calculation engine instance.

Return Value

Logger

final __clone()

__clone implementation. Cloning should not be allowed in a Singleton!

Exceptions

Exception

static string getTRUE()

Return the locale-specific translation of TRUE.

Return Value

string locale-specific translation of TRUE

static string getFALSE()

Return the locale-specific translation of FALSE.

Return Value

string locale-specific translation of FALSE

static bool setArrayReturnType(string $returnType)

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

Parameters

string $returnType Array return type

Return Value

bool Success or failure

static string getArrayReturnType()

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

Return Value

string $returnType Array return type

bool getCalculationCacheEnabled()

Is calculation caching enabled?

Return Value

bool

setCalculationCacheEnabled(bool $pValue)

Enable/disable calculation cache.

Parameters

bool $pValue

enableCalculationCache()

Enable calculation cache.

disableCalculationCache()

Disable calculation cache.

clearCalculationCache()

Clear calculation cache.

clearCalculationCacheForWorksheet(string $worksheetName)

Clear calculation cache for a specified worksheet.

Parameters

string $worksheetName

renameCalculationCacheForWorksheet(string $fromWorksheetName, string $toWorksheetName)

Rename calculation cache for a specified worksheet.

Parameters

string $fromWorksheetName
string $toWorksheetName

setBranchPruningEnabled($enabled)

Enable/disable calculation cache.

Parameters

$enabled

enableBranchPruning()

disableBranchPruning()

clearBranchStore()

string getLocale()

Get the currently defined locale code.

Return Value

string

bool setLocale(string $locale)

Set the locale code.

Parameters

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

Return Value

bool

static string translateSeparator(string $fromSeparator, string $toSeparator, string $formula, bool $inBraces)

Parameters

string $fromSeparator
string $toSeparator
string $formula
bool $inBraces

Return Value

string

_translateFormulaToLocale($formula)

Parameters

$formula

_translateFormulaToEnglish($formula)

Parameters

$formula

static localeFunc($function)

Parameters

$function

static mixed wrapResult(mixed $value)

Wrap string values in quotes.

Parameters

mixed $value

Return Value

mixed

static mixed unwrapResult(mixed $value)

Remove quotes used as a wrapper to identify string values.

Parameters

mixed $value

Return Value

mixed

mixed calculate(Cell $pCell = null)

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

Parameters

Cell $pCell Cell to calculate

Return Value

mixed

Exceptions

Exception

mixed calculateCellValue(Cell $pCell = null, bool $resetLog = true)

Calculate the value of a cell formula.

Parameters

Cell $pCell Cell to calculate
bool $resetLog Flag indicating whether the debug log should be reset or not

Return Value

mixed

Exceptions

Exception

array|bool parseFormula(string $formula)

Validate and parse a formula string.

Parameters

string $formula Formula to parse

Return Value

array|bool

mixed calculateFormula(string $formula, string $cellID = null, Cell $pCell = null)

Calculate the value of a formula.

Parameters

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

Return Value

mixed

Exceptions

Exception

bool getValueFromCache(string $cellReference, mixed $cellValue)

Parameters

string $cellReference
mixed $cellValue

Return Value

bool

saveValueToCache(string $cellReference, mixed $cellValue)

Parameters

string $cellReference
mixed $cellValue

mixed _calculateFormulaValue(string $formula, string $cellID = null, Cell $pCell = null)

Parse a cell formula and calculate its value.

Parameters

string $formula The formula to parse and calculate
string $cellID The ID (e.g. A3) of the cell that we are calculating
Cell $pCell Cell to calculate

Return Value

mixed

Exceptions

Exception

static int[] getMatrixDimensions(array $matrix)

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

Parameters

array $matrix &$matrix matrix operand

Return Value

int[] An array comprising the number of rows, and number of columns

protected raiseFormulaError($errorMessage)

Parameters

$errorMessage

mixed extractCellRange(string $pRange = 'A1', Worksheet $pSheet = null, bool $resetLog = true)

Extract range values.

Parameters

string $pRange &$pRange String based range representation
Worksheet $pSheet Worksheet
bool $resetLog Flag indicating whether calculation log should be reset or not

Return Value

mixed Array of values in range if range contains more than one element. Otherwise, a single value is returned.

mixed extractNamedRange(string $pRange = 'A1', Worksheet $pSheet = null, bool $resetLog = true)

Extract range values.

Parameters

string $pRange &$pRange String based range representation
Worksheet $pSheet Worksheet
bool $resetLog Flag indicating whether calculation log should be reset or not

Return Value

mixed Array of values in range if range contains more than one element. Otherwise, a single value is returned.

bool isImplemented(string $pFunction)

Is a specific function implemented?

Parameters

string $pFunction Function Name

Return Value

bool

array getFunctions()

Get a list of all implemented functions as an array of function objects.

Return Value

array of Category

array getImplementedFunctionNames()

Get a list of implemented Excel function names.

Return Value

array