\PHPExcel_Calculation

PHPExcel_Calculation (Multiton)

Summary

Methods
Properties
Constants
__destruct()
getInstance()
unsetInstance()
flushInstance()
getDebugLog()
__clone()
getTRUE()
getFALSE()
setArrayReturnType()
getArrayReturnType()
getCalculationCacheEnabled()
setCalculationCacheEnabled()
enableCalculationCache()
disableCalculationCache()
clearCalculationCache()
clearCalculationCacheForWorksheet()
renameCalculationCacheForWorksheet()
getLocale()
setLocale()
_translateSeparator()
_translateFormulaToLocale()
_translateFormulaToEnglish()
_localeFunc()
_wrapResult()
_unwrapResult()
calculate()
calculateCellValue()
parseFormula()
calculateFormula()
getValueFromCache()
saveValueToCache()
_calculateFormulaValue()
_getMatrixDimensions()
extractCellRange()
extractNamedRange()
isImplemented()
listFunctions()
listAllFunctionNames()
listFunctionNames()
$suppressFormulaErrors
$formulaError
$cyclicFormulaCount
$_localeBoolean
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
RETURN_ARRAY_AS_VALUE
RETURN_ARRAY_AS_ARRAY
_raiseFormulaError()
No protected properties found
N/A
__construct()
_loadLocales()
_translateFormula()
_checkMatrixOperands()
_resizeMatricesShrink()
_resizeMatricesExtend()
_showValue()
_showTypeDetails()
_convertMatrixReferences()
_mkMatrix()
_parseFormula()
_dataTestReference()
_processTokenStack()
_validateBinaryOperand()
_executeBinaryComparisonOperation()
strcmpLowercaseFirst()
_executeNumericBinaryOperation()
$returnArrayAsType
$_instance
$_workbook
$_workbookSets
$_calculationCache
$_calculationCacheEnabled
$_operators
$_binaryOperators
$debugLog
$_cyclicReferenceStack
$_cyclicFormulaCount
$_cyclicFormulaCell
$_savedPrecision
$_localeLanguage
$_validLocaleLanguages
$_localeArgumentSeparator
$_localeFunctions
$_ExcelConstants
$_PHPExcelFunctions
$_controlFunctions
$functionReplaceFromExcel
$functionReplaceToLocale
$functionReplaceFromLocale
$functionReplaceToExcel
$_operatorAssociativity
$_comparisonOperators
$_operatorPrecedence
N/A

Constants

CALCULATION_REGEXP_NUMBER

CALCULATION_REGEXP_NUMBER = '[-+]?\\d*\\.?\\d+(e[-+]?\\d+)?'

Regular Expressions

CALCULATION_REGEXP_STRING

CALCULATION_REGEXP_STRING = '"(?:[^"]|"")*"'

CALCULATION_REGEXP_OPENBRACE

CALCULATION_REGEXP_OPENBRACE = '\\('

CALCULATION_REGEXP_FUNCTION

CALCULATION_REGEXP_FUNCTION = '@?([A-Z][A-Z0-9\\.]*)[\\s]*\\('

CALCULATION_REGEXP_CELLREF

CALCULATION_REGEXP_CELLREF = \CALCULATION_REGEXP_CELLREF

CALCULATION_REGEXP_NAMEDRANGE

CALCULATION_REGEXP_NAMEDRANGE = \CALCULATION_REGEXP_NAMEDRANGE

CALCULATION_REGEXP_ERROR

CALCULATION_REGEXP_ERROR = '\\#[A-Z][A-Z0_\\/]*[!\\?]?'

RETURN_ARRAY_AS_ERROR

RETURN_ARRAY_AS_ERROR = 'error'

constants

RETURN_ARRAY_AS_VALUE

RETURN_ARRAY_AS_VALUE = 'value'

RETURN_ARRAY_AS_ARRAY

RETURN_ARRAY_AS_ARRAY = 'array'

Properties

$suppressFormulaErrors

$suppressFormulaErrors : bool

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

Type

bool

$formulaError

$formulaError : string

Error message for any error that was raised/thrown by the calculation engine

Type

string

$cyclicFormulaCount

$cyclicFormulaCount : int

Number of iterations for cyclic formulae

Type

int

$_localeBoolean

$_localeBoolean : string[]

Locale-specific translations for Excel constants (True, False and Null)

Type

string[]

$returnArrayAsType

$returnArrayAsType

$_instance

$_instance : \PHPExcel_Calculation

Instance of this class

Type

PHPExcel_Calculation

$_workbook

$_workbook : \PHPExcel

Instance of the workbook this Calculation Engine is using

Type

PHPExcel

$_workbookSets

$_workbookSets : \PHPExcel_Calculation[]

List of instances of the calculation engine that we've instantiated for individual workbooks

Type

PHPExcel_Calculation[]

$_calculationCache

$_calculationCache : array

Calculation cache

Type

array

$_calculationCacheEnabled

$_calculationCacheEnabled : bool

Calculation cache enabled

Type

bool

$_operators

$_operators : array

List of operators that can be used within formulae The true/false value indicates whether it is a binary operator or a unary operator

Type

array

$_binaryOperators

$_binaryOperators : array

List of binary operators (those that expect two operands)

Type

array

$debugLog

$debugLog : \PHPExcel_CalcEngine_Logger

The debug log generated by the calculation engine

Type

PHPExcel_CalcEngine_Logger

$_cyclicReferenceStack

$_cyclicReferenceStack : array

An array of the nested cell references accessed by the calculation engine, used for the debug log

Type

array — of string

$_cyclicFormulaCount

$_cyclicFormulaCount : int

Current iteration counter for cyclic formulae If the value is 0 (or less) then cyclic formulae will throw an exception, otherwise they will iterate to the limit defined here before returning a result

Type

int

$_cyclicFormulaCell

$_cyclicFormulaCell

$_savedPrecision

$_savedPrecision : int

Precision used for calculations

Type

int

$_localeLanguage

$_localeLanguage : string

The current locale setting

Type

string

$_validLocaleLanguages

$_validLocaleLanguages : string[]

List of available locale settings Note that this is read for the locale subdirectory only when requested

Type

string[]

$_localeArgumentSeparator

$_localeArgumentSeparator : string

Locale-specific argument separator for function arguments

Type

string

$_localeFunctions

$_localeFunctions

$_ExcelConstants

$_ExcelConstants : string[]

Excel constant string translations to their PHP equivalents Constant conversion from text name/value to actual (datatyped) value

Type

string[]

$_PHPExcelFunctions

$_PHPExcelFunctions

$_controlFunctions

$_controlFunctions

$functionReplaceFromExcel

$functionReplaceFromExcel

$functionReplaceToLocale

$functionReplaceToLocale

$functionReplaceFromLocale

$functionReplaceFromLocale

$functionReplaceToExcel

$functionReplaceToExcel

$_operatorAssociativity

$_operatorAssociativity

$_comparisonOperators

$_comparisonOperators

$_operatorPrecedence

$_operatorPrecedence

Methods

__destruct()

__destruct() : mixed

Returns

mixed —

getInstance()

getInstance(\PHPExcel  $workbook = NULL) : \PHPExcel_Calculation

Get an instance of this class

Parameters

\PHPExcel $workbook

Injected workbook for working with a PHPExcel object, or NULL to create a standalone claculation engine

Returns

\PHPExcel_Calculation —

unsetInstance()

unsetInstance(\PHPExcel  $workbook = NULL) : mixed

Unset an instance of this class

Parameters

\PHPExcel $workbook

Injected workbook identifying the instance to unset

Returns

mixed —

flushInstance()

flushInstance() : null

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

Returns

null —

getDebugLog()

getDebugLog() : \PHPExcel_CalcEngine_Logger

Get the debuglog for this claculation engine instance

Returns

\PHPExcel_CalcEngine_Logger —

__clone()

__clone() : mixed

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

Throws

\PHPExcel_Calculation_Exception

Returns

mixed —

getTRUE()

getTRUE() : string

Return the locale-specific translation of TRUE

Returns

string —

locale-specific translation of TRUE

getFALSE()

getFALSE() : string

Return the locale-specific translation of FALSE

Returns

string —

locale-specific translation of FALSE

setArrayReturnType()

setArrayReturnType(string  $returnType) : bool

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

Parameters

string $returnType

Array return type

Returns

bool —

Success or failure

getArrayReturnType()

getArrayReturnType() : string

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

Returns

string —

$returnType Array return type

getCalculationCacheEnabled()

getCalculationCacheEnabled() : bool

Is calculation caching enabled?

Returns

bool —

setCalculationCacheEnabled()

setCalculationCacheEnabled(bool  $pValue = TRUE) : mixed

Enable/disable calculation cache

Parameters

bool $pValue

Returns

mixed —

enableCalculationCache()

enableCalculationCache() : mixed

Enable calculation cache

Returns

mixed —

disableCalculationCache()

disableCalculationCache() : mixed

Disable calculation cache

Returns

mixed —

clearCalculationCache()

clearCalculationCache() : mixed

Clear calculation cache

Returns

mixed —

clearCalculationCacheForWorksheet()

clearCalculationCacheForWorksheet(string  $worksheetName) : mixed

Clear calculation cache for a specified worksheet

Parameters

string $worksheetName

Returns

mixed —

renameCalculationCacheForWorksheet()

renameCalculationCacheForWorksheet(string  $fromWorksheetName, string  $toWorksheetName) : mixed

Rename calculation cache for a specified worksheet

Parameters

string $fromWorksheetName
string $toWorksheetName

Returns

mixed —

getLocale()

getLocale() : string

Get the currently defined locale code

Returns

string —

setLocale()

setLocale(string  $locale = 'en_us') : bool

Set the locale code

Parameters

string $locale

The locale to use for formula translation

Returns

bool —

_translateSeparator()

_translateSeparator(mixed  $fromSeparator, mixed  $toSeparator, mixed  $formula, mixed  $inBraces) : mixed

Parameters

mixed $fromSeparator
mixed $toSeparator
mixed $formula
mixed $inBraces

Returns

mixed —

_translateFormulaToLocale()

_translateFormulaToLocale(mixed  $formula) : mixed

Parameters

mixed $formula

Returns

mixed —

_translateFormulaToEnglish()

_translateFormulaToEnglish(mixed  $formula) : mixed

Parameters

mixed $formula

Returns

mixed —

_localeFunc()

_localeFunc(mixed  $function) : mixed

Parameters

mixed $function

Returns

mixed —

_wrapResult()

_wrapResult(mixed  $value) : mixed

Wrap string values in quotes

Parameters

mixed $value

Returns

mixed —

_unwrapResult()

_unwrapResult(mixed  $value) : mixed

Remove quotes used as a wrapper to identify string values

Parameters

mixed $value

Returns

mixed —

calculate()

calculate(\PHPExcel_Cell  $pCell = NULL) : mixed

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

Parameters

\PHPExcel_Cell $pCell

Cell to calculate

Throws

\PHPExcel_Calculation_Exception

Returns

mixed —

calculateCellValue()

calculateCellValue(\PHPExcel_Cell  $pCell = NULL, bool  $resetLog = TRUE) : mixed

Calculate the value of a cell formula

Parameters

\PHPExcel_Cell $pCell

Cell to calculate

bool $resetLog

Flag indicating whether the debug log should be reset or not

Throws

\PHPExcel_Calculation_Exception

Returns

mixed —

parseFormula()

parseFormula(string  $formula) : array

Validate and parse a formula string

Parameters

string $formula

Formula to parse

Throws

\PHPExcel_Calculation_Exception

Returns

array —

calculateFormula()

calculateFormula(string  $formula, string  $cellID = NULL, \PHPExcel_Cell  $pCell = NULL) : mixed

Calculate the value of a formula

Parameters

string $formula

Formula to parse

string $cellID

Address of the cell to calculate

\PHPExcel_Cell $pCell

Cell to calculate

Throws

\PHPExcel_Calculation_Exception

Returns

mixed —

getValueFromCache()

getValueFromCache(mixed  $worksheetName, mixed  $cellID, mixed  $cellValue) : mixed

Parameters

mixed $worksheetName
mixed $cellID
mixed $cellValue

Returns

mixed —

saveValueToCache()

saveValueToCache(mixed  $worksheetName, mixed  $cellID, mixed  $cellValue) : mixed

Parameters

mixed $worksheetName
mixed $cellID
mixed $cellValue

Returns

mixed —

_calculateFormulaValue()

_calculateFormulaValue(string  $formula, string  $cellID = null, \PHPExcel_Cell  $pCell = null) : mixed

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

\PHPExcel_Cell $pCell

Cell to calculate

Throws

\PHPExcel_Calculation_Exception

Returns

mixed —

_getMatrixDimensions()

_getMatrixDimensions(mixed  $matrix) : array

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

Parameters

mixed $matrix

matrix operand

Returns

array —

An array comprising the number of rows, and number of columns

extractCellRange()

extractCellRange(string  $pRange = 'A1', \PHPExcel_Worksheet  $pSheet = NULL, bool  $resetLog = TRUE) : mixed

Extract range values

Parameters

string $pRange

String based range representation

\PHPExcel_Worksheet $pSheet

Worksheet

bool $resetLog

Flag indicating whether calculation log should be reset or not

Throws

\PHPExcel_Calculation_Exception

Returns

mixed —

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

extractNamedRange()

extractNamedRange(string  $pRange = 'A1', \PHPExcel_Worksheet  $pSheet = NULL, bool  $resetLog = TRUE) : mixed

Extract range values

Parameters

string $pRange

String based range representation

\PHPExcel_Worksheet $pSheet

Worksheet

bool $resetLog

Flag indicating whether calculation log should be reset or not

Throws

\PHPExcel_Calculation_Exception

Returns

mixed —

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

isImplemented()

isImplemented(string  $pFunction = '') : bool

Is a specific function implemented?

Parameters

string $pFunction

Function Name

Returns

bool —

listFunctions()

listFunctions() : array

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

Returns

array —

of PHPExcel_Calculation_Function

listAllFunctionNames()

listAllFunctionNames() : array

Get a list of all Excel function names

Returns

array —

listFunctionNames()

listFunctionNames() : array

Get a list of implemented Excel function names

Returns

array —

_raiseFormulaError()

_raiseFormulaError(mixed  $errorMessage) : mixed

Parameters

mixed $errorMessage

Returns

mixed —

__construct()

__construct(\PHPExcel  $workbook = NULL) : mixed

Parameters

\PHPExcel $workbook

Returns

mixed —

_loadLocales()

_loadLocales() : mixed

Returns

mixed —

_translateFormula()

_translateFormula(mixed  $from, mixed  $to, mixed  $formula, mixed  $fromSeparator, mixed  $toSeparator) : mixed

Parameters

mixed $from
mixed $to
mixed $formula
mixed $fromSeparator
mixed $toSeparator

Returns

mixed —

_checkMatrixOperands()

_checkMatrixOperands(mixed  $operand1, mixed  $operand2, int  $resize = 1) : mixed

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

Parameters

mixed $operand1

First matrix operand

mixed $operand2

Second matrix operand

int $resize

Flag 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

Returns

mixed —

_resizeMatricesShrink()

_resizeMatricesShrink(mixed  $matrix1, mixed  $matrix2, int  $matrix1Rows, int  $matrix1Columns, int  $matrix2Rows, int  $matrix2Columns) : mixed

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

Parameters

mixed $matrix1

First matrix operand

mixed $matrix2

Second matrix operand

int $matrix1Rows

Row size of first matrix operand

int $matrix1Columns

Column size of first matrix operand

int $matrix2Rows

Row size of second matrix operand

int $matrix2Columns

Column size of second matrix operand

Returns

mixed —

_resizeMatricesExtend()

_resizeMatricesExtend(mixed  $matrix1, mixed  $matrix2, int  $matrix1Rows, int  $matrix1Columns, int  $matrix2Rows, int  $matrix2Columns) : mixed

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

Parameters

mixed $matrix1

First matrix operand

mixed $matrix2

Second matrix operand

int $matrix1Rows

Row size of first matrix operand

int $matrix1Columns

Column size of first matrix operand

int $matrix2Rows

Row size of second matrix operand

int $matrix2Columns

Column size of second matrix operand

Returns

mixed —

_showValue()

_showValue(mixed  $value) : mixed

Format details of an operand for display in the log (based on operand type)

Parameters

mixed $value

First matrix operand

Returns

mixed —

_showTypeDetails()

_showTypeDetails(mixed  $value) : mixed

Format type and details of an operand for display in the log (based on operand type)

Parameters

mixed $value

First matrix operand

Returns

mixed —

_convertMatrixReferences()

_convertMatrixReferences(mixed  $formula) : mixed

Parameters

mixed $formula

Returns

mixed —

_mkMatrix()

_mkMatrix() : mixed

Returns

mixed —

_parseFormula()

_parseFormula(mixed  $formula, \PHPExcel_Cell  $pCell = NULL) : mixed

Parameters

mixed $formula
\PHPExcel_Cell $pCell

Returns

mixed —

_dataTestReference()

_dataTestReference(mixed  $operandData) : mixed

Parameters

mixed $operandData

Returns

mixed —

_processTokenStack()

_processTokenStack(mixed  $tokens, mixed  $cellID = NULL, \PHPExcel_Cell  $pCell = NULL) : mixed

Parameters

mixed $tokens
mixed $cellID
\PHPExcel_Cell $pCell

Returns

mixed —

_validateBinaryOperand()

_validateBinaryOperand(mixed  $cellID, mixed  $operand, mixed  $stack) : mixed

Parameters

mixed $cellID
mixed $operand
mixed $stack

Returns

mixed —

_executeBinaryComparisonOperation()

_executeBinaryComparisonOperation(mixed  $cellID, mixed  $operand1, mixed  $operand2, mixed  $operation, mixed  $stack, mixed  $recursingArrays = FALSE) : mixed

Parameters

mixed $cellID
mixed $operand1
mixed $operand2
mixed $operation
mixed $stack
mixed $recursingArrays

Returns

mixed —

strcmpLowercaseFirst()

strcmpLowercaseFirst(string  $str1, string  $str2) : int

Compare two strings in the same way as strcmp() except that lowercase come before uppercase letters

Parameters

string $str1
string $str2

Returns

int —

_executeNumericBinaryOperation()

_executeNumericBinaryOperation(mixed  $cellID, mixed  $operand1, mixed  $operand2, mixed  $operation, mixed  $matrixFunction, mixed  $stack) : mixed

Parameters

mixed $cellID
mixed $operand1
mixed $operand2
mixed $operation
mixed $matrixFunction
mixed $stack

Returns

mixed —