class 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

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

boolean $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
integer $cyclicFormulaCount Number of iterations for cyclic formulae
static string[] $localeBoolean Locale-specific translations for Excel constants (True, False and Null)

Methods

__construct(PHPExcel $workbook = null)

No description

getInstance(PHPExcel $workbook = null)

Get an instance of this class

__destruct()

Unset an instance of this class

null
flushInstance()

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

getDebugLog()

Get the debuglog for this claculation 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 boolean
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)

boolean
getCalculationCacheEnabled()

Is calculation caching enabled?

setCalculationCacheEnabled(boolean $pValue = true)

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

string
getLocale()

Get the currently defined locale code

boolean
setLocale(string $locale = 'en_us')

Set the locale code

static 
translateSeparator($fromSeparator, $toSeparator, $formula, $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(PHPExcel_Cell $pCell = null)

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

mixed
calculateCellValue(PHPExcel_Cell $pCell = null, Boolean $resetLog = true)

Calculate the value of a cell formula

array
parseFormula(string $formula)

Validate and parse a formula string

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

Calculate the value of a formula

getValueFromCache($cellReference, $cellValue)

No description

saveValueToCache($cellReference, $cellValue)

No description

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

Parse a cell formula and calculate its value

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

Extract range values

mixed
extractNamedRange(string $pRange = 'A1', PHPExcel_Worksheet $pSheet = null, boolean $resetLog = true)

Extract range values

boolean
isImplemented(string $pFunction = '')

Is a specific function implemented?

array
listFunctions()

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

array
listAllFunctionNames()

Get a list of all Excel function names

array
listFunctionNames()

Get a list of implemented Excel function names

Details

at line 2091
__construct(PHPExcel $workbook = null)

Parameters

PHPExcel $workbook

at line 2120
static PHPExcel_Calculation getInstance(PHPExcel $workbook = null)

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

Return Value

PHPExcel_Calculation

at line 2140
__destruct()

Unset an instance of this class

at line 2152
null flushInstance()

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

Return Value

null

at line 2164
PHPExcel_CalcEngine_Logger getDebugLog()

Get the debuglog for this claculation engine instance

at line 2175
final __clone()

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

at line 2187
static string getTRUE()

Return the locale-specific translation of TRUE

Return Value

string locale-specific translation of TRUE

at line 2198
static string getFALSE()

Return the locale-specific translation of FALSE

Return Value

string locale-specific translation of FALSE

at line 2210
static boolean 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

boolean Success or failure

at line 2228
static string getArrayReturnType()

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

Return Value

string $returnType Array return type

at line 2240
boolean getCalculationCacheEnabled()

Is calculation caching enabled?

Return Value

boolean

at line 2251
setCalculationCacheEnabled(boolean $pValue = true)

Enable/disable calculation cache

Parameters

boolean $pValue

at line 2261
enableCalculationCache()

Enable calculation cache

at line 2270
disableCalculationCache()

Disable calculation cache

at line 2279
clearCalculationCache()

Clear calculation cache

at line 2289
clearCalculationCacheForWorksheet(string $worksheetName)

Clear calculation cache for a specified worksheet

Parameters

string $worksheetName

at line 2302
renameCalculationCacheForWorksheet(string $fromWorksheetName, string $toWorksheetName)

Rename calculation cache for a specified worksheet

Parameters

string $fromWorksheetName
string $toWorksheetName

at line 2316
string getLocale()

Get the currently defined locale code

Return Value

string

at line 2328
boolean setLocale(string $locale = 'en_us')

Set the locale code

Parameters

string $locale The locale to use for formula translation

Return Value

boolean

at line 2408
static translateSeparator($fromSeparator, $toSeparator, $formula, $inBraces)

Parameters

$fromSeparator
$toSeparator
$formula
$inBraces

at line 2463
_translateFormulaToLocale($formula)

Parameters

$formula

at line 2493
_translateFormulaToEnglish($formula)

Parameters

$formula

at line 2519
static localeFunc($function)

Parameters

$function

at line 2543
static mixed wrapResult(mixed $value)

Wrap string values in quotes

Parameters

mixed $value

Return Value

mixed

at line 2568
static mixed unwrapResult(mixed $value)

Remove quotes used as a wrapper to identify string values

Parameters

mixed $value

Return Value

mixed

at line 2593
mixed calculate(PHPExcel_Cell $pCell = null)

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

Parameters

PHPExcel_Cell $pCell Cell to calculate

Return Value

mixed

Exceptions

PHPExcel_Calculation_Exception

at line 2612
mixed calculateCellValue(PHPExcel_Cell $pCell = null, Boolean $resetLog = true)

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

Return Value

mixed

Exceptions

PHPExcel_Calculation_Exception

at line 2687
array parseFormula(string $formula)

Validate and parse a formula string

Parameters

string $formula Formula to parse

Return Value

array

Exceptions

PHPExcel_Calculation_Exception

at line 2714
mixed calculateFormula(string $formula, string $cellID = null, PHPExcel_Cell $pCell = null)

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

Return Value

mixed

Exceptions

PHPExcel_Calculation_Exception

at line 2747
getValueFromCache($cellReference, $cellValue)

Parameters

$cellReference
$cellValue

at line 2761
saveValueToCache($cellReference, $cellValue)

Parameters

$cellReference
$cellValue

at line 2777
mixed _calculateFormulaValue(string $formula, string $cellID = null, PHPExcel_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
PHPExcel_Cell $pCell Cell to calculate

Return Value

mixed

Exceptions

PHPExcel_Calculation_Exception

at line 4209
mixed extractCellRange(string $pRange = 'A1', PHPExcel_Worksheet $pSheet = null, boolean $resetLog = true)

Extract range values

Parameters

string $pRange &$pRange String based range representation
PHPExcel_Worksheet $pSheet Worksheet
boolean $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.

Exceptions

PHPExcel_Calculation_Exception

at line 4267
mixed extractNamedRange(string $pRange = 'A1', PHPExcel_Worksheet $pSheet = null, boolean $resetLog = true)

Extract range values

Parameters

string $pRange &$pRange String based range representation
PHPExcel_Worksheet $pSheet Worksheet
boolean $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.

Exceptions

PHPExcel_Calculation_Exception

at line 4351
boolean isImplemented(string $pFunction = '')

Is a specific function implemented?

Parameters

string $pFunction Function Name

Return Value

boolean

at line 4367
array listFunctions()

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

Return Value

array of PHPExcelCalculationFunction

at line 4390
array listAllFunctionNames()

Get a list of all Excel function names

Return Value

array

at line 4400
array listFunctionNames()

Get a list of implemented Excel function names

Return Value

array