\PHPExcel_Calculation

PHPExcel_Calculation (Multiton)

Copyright (c) 2006 - 2015 PHPExcel

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

Summary

Methods
Properties
Constants
__construct()
getInstance()
__destruct()
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()
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
loadLocales()
translateFormula()
checkMatrixOperands()
getMatrixDimensions()
resizeMatricesShrink()
resizeMatricesExtend()
showValue()
showTypeDetails()
convertMatrixReferences()
mkMatrix()
_parseFormula()
dataTestReference()
processTokenStack()
validateBinaryOperand()
executeBinaryComparisonOperation()
strcmpLowercaseFirst()
executeNumericBinaryOperation()
$returnArrayAsType
$instance
$workbook
$workbookSets
$calculationCache
$calculationCacheEnabled
$operators
$binaryOperators
$debugLog
$cyclicReferenceStack
$cellStack
$cyclicFormulaCounter
$cyclicFormulaCell
$delta
$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+)?'

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 : boolean

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

boolean

$formulaError

$formulaError : string

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

Type

string

$cyclicFormulaCount

$cyclicFormulaCount : integer

Number of iterations for cyclic formulae

Type

integer

$localeBoolean

$localeBoolean : array<mixed,string>

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

Type

array<mixed,string>

$returnArrayAsType

$returnArrayAsType : 

Type

$workbook

$workbook : \PHPExcel

Instance of the workbook this Calculation Engine is using

Type

\PHPExcel

$workbookSets

$workbookSets : array<mixed,\PHPExcel_Calculation>

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

Type

array<mixed,\PHPExcel_Calculation>

$calculationCache

$calculationCache : array

Calculation cache

Type

array

$calculationCacheEnabled

$calculationCacheEnabled : boolean

Calculation cache enabled

Type

boolean

$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

$cyclicReferenceStack

$cyclicReferenceStack : array

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

Type

array — of string

$cellStack

$cellStack : 

Type

$cyclicFormulaCounter

$cyclicFormulaCounter : integer

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

integer

$cyclicFormulaCell

$cyclicFormulaCell : 

Type

$delta

$delta : float

Epsilon Precision used for comparisons in calculations

Type

float

$localeLanguage

$localeLanguage : string

The current locale setting

Type

string

$validLocaleLanguages

$validLocaleLanguages : array<mixed,string>

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

Type

array<mixed,string>

$localeArgumentSeparator

$localeArgumentSeparator : string

Locale-specific argument separator for function arguments

Type

string

$localeFunctions

$localeFunctions : 

Type

$excelConstants

$excelConstants : array<mixed,string>

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

Type

array<mixed,string>

$PHPExcelFunctions

$PHPExcelFunctions : 

Type

$controlFunctions

$controlFunctions : 

Type

$functionReplaceFromExcel

$functionReplaceFromExcel : 

Type

$functionReplaceToLocale

$functionReplaceToLocale : 

Type

$functionReplaceFromLocale

$functionReplaceFromLocale : 

Type

$functionReplaceToExcel

$functionReplaceToExcel : 

Type

$operatorAssociativity

$operatorAssociativity : 

Type

$comparisonOperators

$comparisonOperators : 

Type

$operatorPrecedence

$operatorPrecedence : 

Type

Methods

__construct()

__construct(\PHPExcel  $workbook = null) 

Parameters

\PHPExcel $workbook

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

__destruct()

__destruct() 

Unset an instance of this class

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() 

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

Throws

\PHPExcel_Calculation_Exception

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) : boolean

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

Parameters

string $returnType

Array return type

Returns

boolean —

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() : boolean

Is calculation caching enabled?

Returns

boolean

setCalculationCacheEnabled()

setCalculationCacheEnabled(boolean  $pValue = true) 

Enable/disable calculation cache

Parameters

boolean $pValue

enableCalculationCache()

enableCalculationCache() 

Enable calculation cache

disableCalculationCache()

disableCalculationCache() 

Disable calculation cache

clearCalculationCache()

clearCalculationCache() 

Clear calculation cache

clearCalculationCacheForWorksheet()

clearCalculationCacheForWorksheet(string  $worksheetName) 

Clear calculation cache for a specified worksheet

Parameters

string $worksheetName

renameCalculationCacheForWorksheet()

renameCalculationCacheForWorksheet(string  $fromWorksheetName, string  $toWorksheetName) 

Rename calculation cache for a specified worksheet

Parameters

string $fromWorksheetName
string $toWorksheetName

getLocale()

getLocale() : string

Get the currently defined locale code

Returns

string

setLocale()

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

Set the locale code

Parameters

string $locale

The locale to use for formula translation

Returns

boolean

translateSeparator()

translateSeparator(  $fromSeparator,   $toSeparator,   $formula,   $inBraces) 

Parameters

$fromSeparator
$toSeparator
$formula
$inBraces

_translateFormulaToLocale()

_translateFormulaToLocale(  $formula) 

Parameters

$formula

_translateFormulaToEnglish()

_translateFormulaToEnglish(  $formula) 

Parameters

$formula

localeFunc()

localeFunc(  $function) 

Parameters

$function

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, Boolean  $resetLog = true) : mixed

Calculate the value of a cell formula

Parameters

\PHPExcel_Cell $pCell

Cell to calculate

Boolean $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(  $cellReference,   $cellValue) 

Parameters

$cellReference
$cellValue

saveValueToCache()

saveValueToCache(  $cellReference,   $cellValue) 

Parameters

$cellReference
$cellValue

_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

extractCellRange()

extractCellRange(  $pRange = 'A1', \PHPExcel_Worksheet  $pSheet = null, boolean  $resetLog = true) : mixed

Extract range values

Parameters

$pRange
\PHPExcel_Worksheet $pSheet

Worksheet

boolean $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(  $pRange = 'A1', \PHPExcel_Worksheet  $pSheet = null, boolean  $resetLog = true) : mixed

Extract range values

Parameters

$pRange
\PHPExcel_Worksheet $pSheet

Worksheet

boolean $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 = '') : boolean

Is a specific function implemented?

Parameters

string $pFunction

Function Name

Returns

boolean

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(  $errorMessage) 

Parameters

$errorMessage

loadLocales()

loadLocales() 

translateFormula()

translateFormula(  $from,   $to,   $formula,   $fromSeparator,   $toSeparator) 

Parameters

$from
$to
$formula
$fromSeparator
$toSeparator

checkMatrixOperands()

checkMatrixOperands(  $operand1,   $operand2, integer  $resize = 1) 

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

Parameters

$operand1
$operand2
integer $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

getMatrixDimensions()

getMatrixDimensions(  $matrix) : array

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

Parameters

$matrix

Returns

array —

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

resizeMatricesShrink()

resizeMatricesShrink(  $matrix1,   $matrix2, integer  $matrix1Rows, integer  $matrix1Columns, integer  $matrix2Rows, integer  $matrix2Columns) 

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

Parameters

$matrix1
$matrix2
integer $matrix1Rows

Row size of first matrix operand

integer $matrix1Columns

Column size of first matrix operand

integer $matrix2Rows

Row size of second matrix operand

integer $matrix2Columns

Column size of second matrix operand

resizeMatricesExtend()

resizeMatricesExtend(  $matrix1,   $matrix2, integer  $matrix1Rows, integer  $matrix1Columns, integer  $matrix2Rows, integer  $matrix2Columns) 

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

Parameters

$matrix1
$matrix2
integer $matrix1Rows

Row size of first matrix operand

integer $matrix1Columns

Column size of first matrix operand

integer $matrix2Rows

Row size of second matrix operand

integer $matrix2Columns

Column size of second matrix operand

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(  $formula) 

Parameters

$formula

mkMatrix()

mkMatrix() 

_parseFormula()

_parseFormula(  $formula, \PHPExcel_Cell  $pCell = null) 

Parameters

$formula
\PHPExcel_Cell $pCell

dataTestReference()

dataTestReference(  $operandData) 

Parameters

$operandData

processTokenStack()

processTokenStack(  $tokens,   $cellID = null, \PHPExcel_Cell  $pCell = null) 

Parameters

$tokens
$cellID
\PHPExcel_Cell $pCell

validateBinaryOperand()

validateBinaryOperand(  $cellID,   $operand,   $stack) 

Parameters

$cellID
$operand
$stack

executeBinaryComparisonOperation()

executeBinaryComparisonOperation(  $cellID,   $operand1,   $operand2,   $operation,   $stack,   $recursingArrays = false) 

Parameters

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

strcmpLowercaseFirst()

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

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

Parameters

string $str1

First string value for the comparison

string $str2

Second string value for the comparison

Returns

integer

executeNumericBinaryOperation()

executeNumericBinaryOperation(  $cellID,   $operand1,   $operand2,   $operation,   $matrixFunction,   $stack) 

Parameters

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