Source for file Calculation.php
Documentation is available at Calculation.php
* Copyright (c) 2006 - 2011 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
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.6, 2011-02-27
/** PHPExcel root directory */
define('PHPEXCEL_ROOT', dirname(__FILE__ ) . '/../');
require (PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
if (!defined('CALCULATION_REGEXP_CELLREF')) {
// Test for support of \P (multibyte options) in PCRE
if(defined('PREG_BAD_UTF8_ERROR')) {
// Cell reference (cell or range of cells, with or without a sheet reference)
define('CALCULATION_REGEXP_CELLREF','((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?([a-z]{1,3})\$?(\d{1,7})');
define('CALCULATION_REGEXP_NAMEDRANGE','((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?([_A-Z][_A-Z0-9\.]*)');
// Cell reference (cell or range of cells, with or without a sheet reference)
define('CALCULATION_REGEXP_CELLREF','(((\w*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?([a-z]{1,3})\$?(\d+)');
define('CALCULATION_REGEXP_NAMEDRANGE','(((\w*)|(\'.*\')|(\".*\"))!)?([_A-Z][_A-Z0-9\.]*)');
* PHPExcel_Calculation (Singleton)
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
const CALCULATION_REGEXP_NUMBER = '[-+]?\d*\.?\d+(e[-+]?\d+)?';
const CALCULATION_REGEXP_STRING = '"(?:[^"]|"")*"';
const CALCULATION_REGEXP_OPENBRACE = '\(';
// Function (allow for the old @ symbol that could be used to prefix a function, but we'll ignore it)
const CALCULATION_REGEXP_FUNCTION = '@?([A-Z][A-Z0-9\.]*)[\s]*\(';
// Cell reference (cell or range of cells, with or without a sheet reference)
const CALCULATION_REGEXP_CELLREF = CALCULATION_REGEXP_CELLREF;
const CALCULATION_REGEXP_NAMEDRANGE = CALCULATION_REGEXP_NAMEDRANGE;
const CALCULATION_REGEXP_ERROR = '\#[A-Z][A-Z0_\/]*[!\?]?';
const RETURN_ARRAY_AS_ERROR = 'error';
const RETURN_ARRAY_AS_VALUE = 'value';
const RETURN_ARRAY_AS_ARRAY = 'array';
private static $returnArrayAsType = self::RETURN_ARRAY_AS_VALUE;
* @var PHPExcel_Calculation
private static $_instance;
private static $_calculationCache = array ();
* Calculation cache enabled
private static $_calculationCacheEnabled = true;
* Calculation cache expiration time
private static $_calculationCacheExpirationTime = 15;
* List of operators that can be used within formulae
* The true/false value indicates whether it is a binary operator or a unary operator
private static $_operators = array('+' => true, '-' => true, '*' => true, '/' => true,
'^' => true, '&' => true, '%' => false, '~' => false,
'>' => true, '<' => true, '=' => true, '>=' => true,
'<=' => true, '<>' => true, '|' => true, ':' => true
* List of binary operators (those that expect two operands)
private static $_binaryOperators = array('+' => true, '-' => true, '*' => true, '/' => true,
'^' => true, '&' => true, '>' => true, '<' => true,
'=' => true, '>=' => true, '<=' => true, '<>' => true,
* 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
* Error message for any error that was raised/thrown by the calculation engine
* Flag to determine whether a debug log should be generated by the calculation engine
* If true, then a debug log will be generated
* If false, then a debug log will not be generated
* Flag to determine whether a debug log should be echoed by the calculation engine
* If true, then a debug log will be echoed
* If false, then a debug log will not be echoed
* A debug log can only be echoed if it is generated
* An array of the nested cell references accessed by the calculation engine, used for the debug log
private $debugLogStack = array();
* The debug log generated by the calculation engine
private $_cyclicFormulaCount = 0;
private $_cyclicFormulaCell = '';
private $_savedPrecision = 12;
private static $_localeLanguage = 'en_us'; // US English (default locale)
private static $_validLocaleLanguages = array( 'en' // English (default language)
private static $_localeArgumentSeparator = ',';
private static $_localeFunctions = array();
public static $_localeBoolean = array( 'TRUE' => 'TRUE',
// Constant conversion from text name/value to actual (datatyped) value
private static $_ExcelConstants = array('TRUE' => true,
private static $_PHPExcelFunctions = array( // PHPExcel functions
'ABS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'ACCRINT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::ACCRINT',
'ACCRINTM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::ACCRINTM',
'ACOS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'acos',
'ACOSH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'acosh',
'ADDRESS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_LookupRef::CELL_ADDRESS',
'AMORDEGRC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::AMORDEGRC',
'AMORLINC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::AMORLINC',
'AND' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
'functionCall' => 'PHPExcel_Calculation_Logical::LOGICAL_AND',
'AREAS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'ASC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'ASIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'asin',
'ASINH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'asinh',
'ATAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'atan',
'ATAN2' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::ATAN2',
'ATANH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'atanh',
'AVEDEV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::AVEDEV',
'AVERAGE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::AVERAGE',
'AVERAGEA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::AVERAGEA',
'AVERAGEIF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::AVERAGEIF',
'AVERAGEIFS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'BAHTTEXT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'BESSELI' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::BESSELI',
'BESSELJ' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::BESSELJ',
'BESSELK' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::BESSELK',
'BESSELY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::BESSELY',
'BETADIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::BETADIST',
'BETAINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::BETAINV',
'BIN2DEC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::BINTODEC',
'BIN2HEX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::BINTOHEX',
'BIN2OCT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::BINTOOCT',
'BINOMDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::BINOMDIST',
'CEILING' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::CEILING',
'CELL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'CHAR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::CHARACTER',
'CHIDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::CHIDIST',
'CHIINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::CHIINV',
'CHITEST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'CHOOSE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_LookupRef::CHOOSE',
'CLEAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::TRIMNONPRINTABLE',
'CODE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::ASCIICODE',
'COLUMN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_LookupRef::COLUMN',
'passByReference' => array(true)
'COLUMNS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_LookupRef::COLUMNS',
'COMBIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::COMBIN',
'COMPLEX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::COMPLEX',
'CONCATENATE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::CONCATENATE',
'CONFIDENCE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::CONFIDENCE',
'CONVERT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::CONVERTUOM',
'CORREL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::CORREL',
'COS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'COSH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'cosh',
'COUNT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::COUNT',
'COUNTA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::COUNTA',
'COUNTBLANK' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::COUNTBLANK',
'COUNTIF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::COUNTIF',
'COUNTIFS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'COUPDAYBS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::COUPDAYBS',
'COUPDAYS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::COUPDAYS',
'COUPDAYSNC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::COUPDAYSNC',
'COUPNCD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::COUPNCD',
'COUPNUM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::COUPNUM',
'COUPPCD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::COUPPCD',
'COVAR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::COVAR',
'CRITBINOM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::CRITBINOM',
'CUBEKPIMEMBER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'CUBEMEMBER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'CUBEMEMBERPROPERTY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'CUBERANKEDMEMBER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'CUBESET' => array('category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'CUBESETCOUNT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'CUBEVALUE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'CUMIPMT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::CUMIPMT',
'CUMPRINC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::CUMPRINC',
'DATE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::DATE',
'DATEDIF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::DATEDIF',
'DATEVALUE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::DATEVALUE',
'DAVERAGE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'DAY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::DAYOFMONTH',
'DAYS360' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::DAYS360',
'DB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::DB',
'DCOUNT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Database::DCOUNT',
'DCOUNTA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Database::DCOUNTA',
'DDB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::DDB',
'DEC2BIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::DECTOBIN',
'DEC2HEX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::DECTOHEX',
'DEC2OCT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::DECTOOCT',
'DEGREES' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'rad2deg',
'DELTA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::DELTA',
'DEVSQ' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::DEVSQ',
'DGET' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Database::DGET',
'DISC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::DISC',
'DMAX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Database::DMAX',
'DMIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Database::DMIN',
'DOLLAR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::DOLLAR',
'DOLLARDE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::DOLLARDE',
'DOLLARFR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::DOLLARFR',
'DPRODUCT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Database::DPRODUCT',
'DSTDEV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Database::DSTDEV',
'DSTDEVP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Database::DSTDEVP',
'DSUM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Database::DSUM',
'DURATION' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'DVAR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Database::DVAR',
'DVARP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Database::DVARP',
'EDATE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::EDATE',
'EFFECT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::EFFECT',
'EOMONTH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::EOMONTH',
'ERF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::ERF',
'ERFC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::ERFC',
'ERROR.TYPE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
'functionCall' => 'PHPExcel_Calculation_Functions::ERROR_TYPE',
'EVEN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::EVEN',
'EXACT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'EXP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'EXPONDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::EXPONDIST',
'FACT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::FACT',
'FACTDOUBLE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::FACTDOUBLE',
'FALSE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
'functionCall' => 'PHPExcel_Calculation_Logical::FALSE',
'FDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'FIND' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::SEARCHSENSITIVE',
'FINDB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::SEARCHSENSITIVE',
'FINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'FISHER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::FISHER',
'FISHERINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::FISHERINV',
'FIXED' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::FIXEDFORMAT',
'FLOOR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::FLOOR',
'FORECAST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::FORECAST',
'FREQUENCY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'FTEST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'FV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::FV',
'FVSCHEDULE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::FVSCHEDULE',
'GAMMADIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::GAMMADIST',
'GAMMAINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::GAMMAINV',
'GAMMALN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::GAMMALN',
'GCD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::GCD',
'GEOMEAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::GEOMEAN',
'GESTEP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::GESTEP',
'GETPIVOTDATA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'GROWTH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::GROWTH',
'HARMEAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::HARMEAN',
'HEX2BIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::HEXTOBIN',
'HEX2DEC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::HEXTODEC',
'HEX2OCT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::HEXTOOCT',
'HLOOKUP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'HOUR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::HOUROFDAY',
'HYPERLINK' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_LookupRef::HYPERLINK',
'argumentCount' => '1,2',
'passCellReference'=> true
'HYPGEOMDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::HYPGEOMDIST',
'IF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
'functionCall' => 'PHPExcel_Calculation_Logical::STATEMENT_IF',
'IFERROR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
'functionCall' => 'PHPExcel_Calculation_Logical::IFERROR',
'IMABS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::IMABS',
'IMAGINARY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::IMAGINARY',
'IMARGUMENT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::IMARGUMENT',
'IMCONJUGATE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::IMCONJUGATE',
'IMCOS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::IMCOS',
'IMDIV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::IMDIV',
'IMEXP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::IMEXP',
'IMLN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::IMLN',
'IMLOG10' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::IMLOG10',
'IMLOG2' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::IMLOG2',
'IMPOWER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::IMPOWER',
'IMPRODUCT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::IMPRODUCT',
'IMREAL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::IMREAL',
'IMSIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::IMSIN',
'IMSQRT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::IMSQRT',
'IMSUB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::IMSUB',
'IMSUM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::IMSUM',
'INDEX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_LookupRef::INDEX',
'INDIRECT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_LookupRef::INDIRECT',
'argumentCount' => '1,2',
'passCellReference'=> true
'INFO' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'INT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::INT',
'INTERCEPT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::INTERCEPT',
'INTRATE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::INTRATE',
'IPMT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::IPMT',
'IRR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::IRR',
'ISBLANK' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
'functionCall' => 'PHPExcel_Calculation_Functions::IS_BLANK',
'ISERR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
'functionCall' => 'PHPExcel_Calculation_Functions::IS_ERR',
'ISERROR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
'functionCall' => 'PHPExcel_Calculation_Functions::IS_ERROR',
'ISEVEN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
'functionCall' => 'PHPExcel_Calculation_Functions::IS_EVEN',
'ISLOGICAL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
'functionCall' => 'PHPExcel_Calculation_Functions::IS_LOGICAL',
'ISNA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
'functionCall' => 'PHPExcel_Calculation_Functions::IS_NA',
'ISNONTEXT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
'functionCall' => 'PHPExcel_Calculation_Functions::IS_NONTEXT',
'ISNUMBER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
'functionCall' => 'PHPExcel_Calculation_Functions::IS_NUMBER',
'ISODD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
'functionCall' => 'PHPExcel_Calculation_Functions::IS_ODD',
'ISPMT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::ISPMT',
'ISREF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'ISTEXT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
'functionCall' => 'PHPExcel_Calculation_Functions::IS_TEXT',
'JIS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'KURT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::KURT',
'LARGE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::LARGE',
'LCM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::LCM',
'LEFT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::LEFT',
'LEFTB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::LEFT',
'LEN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::STRINGLENGTH',
'LENB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::STRINGLENGTH',
'LINEST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::LINEST',
'LN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'LOG' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::LOG_BASE',
'LOG10' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'log10',
'LOGEST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::LOGEST',
'LOGINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::LOGINV',
'LOGNORMDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::LOGNORMDIST',
'LOOKUP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_LookupRef::LOOKUP',
'LOWER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::LOWERCASE',
'MATCH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_LookupRef::MATCH',
'MAX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::MAX',
'MAXA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::MAXA',
'MAXIF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::MAXIF',
'MDETERM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::MDETERM',
'MDURATION' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'MEDIAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::MEDIAN',
'MEDIANIF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'MID' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::MID',
'MIDB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::MID',
'MIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::MIN',
'MINA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::MINA',
'MINIF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::MINIF',
'MINUTE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::MINUTEOFHOUR',
'MINVERSE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::MINVERSE',
'MIRR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::MIRR',
'MMULT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::MMULT',
'MOD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::MOD',
'MODE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::MODE',
'MONTH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::MONTHOFYEAR',
'MROUND' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::MROUND',
'MULTINOMIAL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::MULTINOMIAL',
'N' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
'functionCall' => 'PHPExcel_Calculation_Functions::N',
'NA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
'functionCall' => 'PHPExcel_Calculation_Functions::NA',
'NEGBINOMDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::NEGBINOMDIST',
'NETWORKDAYS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::NETWORKDAYS',
'NOMINAL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::NOMINAL',
'NORMDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::NORMDIST',
'NORMINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::NORMINV',
'NORMSDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::NORMSDIST',
'NORMSINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::NORMSINV',
'NOT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
'functionCall' => 'PHPExcel_Calculation_Logical::NOT',
'NOW' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::DATETIMENOW',
'NPER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::NPER',
'NPV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::NPV',
'OCT2BIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::OCTTOBIN',
'OCT2DEC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::OCTTODEC',
'OCT2HEX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Engineering::OCTTOHEX',
'ODD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::ODD',
'ODDFPRICE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'ODDFYIELD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'ODDLPRICE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'ODDLYIELD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'OFFSET' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_LookupRef::OFFSET',
'argumentCount' => '3,5',
'passCellReference'=> true,
'passByReference' => array(true)
'OR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
'functionCall' => 'PHPExcel_Calculation_Logical::LOGICAL_OR',
'PEARSON' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::CORREL',
'PERCENTILE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::PERCENTILE',
'PERCENTRANK' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::PERCENTRANK',
'PERMUT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::PERMUT',
'PHONETIC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'PI' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'PMT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::PMT',
'POISSON' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::POISSON',
'POWER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::POWER',
'PPMT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::PPMT',
'PRICE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::PRICE',
'PRICEDISC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::PRICEDISC',
'PRICEMAT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::PRICEMAT',
'PROB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'PRODUCT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::PRODUCT',
'PROPER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::PROPERCASE',
'PV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::PV',
'QUARTILE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::QUARTILE',
'QUOTIENT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::QUOTIENT',
'RADIANS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'deg2rad',
'RAND' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::RAND',
'RANDBETWEEN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::RAND',
'RANK' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::RANK',
'RATE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::RATE',
'RECEIVED' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::RECEIVED',
'REPLACE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::REPLACE',
'REPLACEB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::REPLACE',
'REPT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'str_repeat',
'RIGHT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::RIGHT',
'RIGHTB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::RIGHT',
'ROMAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::ROMAN',
'ROUND' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'round',
'ROUNDDOWN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::ROUNDDOWN',
'ROUNDUP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::ROUNDUP',
'ROW' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_LookupRef::ROW',
'passByReference' => array(true)
'ROWS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_LookupRef::ROWS',
'RSQ' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::RSQ',
'RTD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'SEARCH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::SEARCHINSENSITIVE',
'SEARCHB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::SEARCHINSENSITIVE',
'SECOND' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::SECONDOFMINUTE',
'SERIESSUM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::SERIESSUM',
'SIGN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::SIGN',
'SIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'SINH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'sinh',
'SKEW' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::SKEW',
'SLN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::SLN',
'SLOPE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::SLOPE',
'SMALL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::SMALL',
'SQRT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'sqrt',
'SQRTPI' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::SQRTPI',
'STANDARDIZE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::STANDARDIZE',
'STDEV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::STDEV',
'STDEVA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::STDEVA',
'STDEVP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::STDEVP',
'STDEVPA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::STDEVPA',
'STEYX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::STEYX',
'SUBSTITUTE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::SUBSTITUTE',
'SUBTOTAL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::SUBTOTAL',
'SUM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::SUM',
'SUMIF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::SUMIF',
'SUMIFS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'SUMPRODUCT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::SUMPRODUCT',
'SUMSQ' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::SUMSQ',
'SUMX2MY2' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::SUMX2MY2',
'SUMX2PY2' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::SUMX2PY2',
'SUMXMY2' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::SUMXMY2',
'SYD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::SYD',
'T' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::RETURNSTRING',
'TAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'TANH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'tanh',
'TBILLEQ' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::TBILLEQ',
'TBILLPRICE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::TBILLPRICE',
'TBILLYIELD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::TBILLYIELD',
'TDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::TDIST',
'TEXT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::TEXTFORMAT',
'TIME' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::TIME',
'TIMEVALUE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::TIMEVALUE',
'TINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::TINV',
'TODAY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::DATENOW',
'TRANSPOSE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_LookupRef::TRANSPOSE',
'TREND' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::TREND',
'TRIM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::TRIMSPACES',
'TRIMMEAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::TRIMMEAN',
'TRUE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
'functionCall' => 'PHPExcel_Calculation_Logical::TRUE',
'TRUNC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_MathTrig::TRUNC',
'TTEST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'TYPE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
'functionCall' => 'PHPExcel_Calculation_Functions::TYPE',
'UPPER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_TextData::UPPERCASE',
'USDOLLAR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'VALUE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'VAR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::VARFunc',
'VARA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::VARA',
'VARP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::VARP',
'VARPA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::VARPA',
'VDB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'VERSION' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
'functionCall' => 'PHPExcel_Calculation_Functions::VERSION',
'VLOOKUP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_LookupRef::VLOOKUP',
'WEEKDAY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::DAYOFWEEK',
'WEEKNUM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::WEEKOFYEAR',
'WEIBULL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::WEIBULL',
'WORKDAY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::WORKDAY',
'XIRR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::XIRR',
'XNPV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::XNPV',
'YEAR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::YEAR',
'YEARFRAC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_DateTime::YEARFRAC',
'YIELD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'YIELDDISC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::YIELDDISC',
'YIELDMAT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Financial::YIELDMAT',
'ZTEST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Statistical::ZTEST',
// Internal functions used for special control purposes
private static $_controlFunctions = array(
'MKMATRIX' => array('argumentCount' => '*',
'functionCall' => 'self::_mkMatrix'
private function __construct() {
foreach (glob($localeFileDirectory. '/*',GLOB_ONLYDIR) as $filename) {
$filename = substr($filename,strlen($localeFileDirectory)+ 1);
self::$_validLocaleLanguages[] = $filename;
$setPrecision = (PHP_INT_SIZE == 4) ? 12 : 16;
$this->_savedPrecision = ini_get('precision');
if ($this->_savedPrecision < $setPrecision) {
ini_set('precision',$setPrecision);
} // function __construct()
ini_set('precision',$this->_savedPrecision);
* Get an instance of this class
* @return PHPExcel_Calculation
if (!isset (self::$_instance) || is_null(self::$_instance)) {
self::$_instance = new PHPExcel_Calculation();
} // function getInstance()
* Flush the calculation cache for any existing instance of this class
* but only if a PHPExcel_Calculation instance exists
if (isset (self::$_instance) && !is_null(self::$_instance)) {
self::$_instance->clearCalculationCache();
} // function flushInstance()
* __clone implementation. Cloning should not be allowed in a Singleton!
throw new Exception ('Cloning a Singleton is not allowed!');
* Return the locale-specific translation of TRUE
* @return string locale-specific translation of TRUE
return self::$_localeBoolean['TRUE'];
* Return the locale-specific translation of FALSE
* @return string locale-specific translation of FALSE
return self::$_localeBoolean['FALSE'];
* Set the Array Return Type (Array or Value of first element in the array)
* @param string $returnType Array return type
* @return boolean Success or failure
if (($returnType == self::RETURN_ARRAY_AS_VALUE) ||
($returnType == self::RETURN_ARRAY_AS_ERROR) ||
($returnType == self::RETURN_ARRAY_AS_ARRAY)) {
self::$returnArrayAsType = $returnType;
} // function setExcelCalendar()
* Return the Array Return Type (Array or Value of first element in the array)
* @return string $returnType Array return type
return self::$returnArrayAsType;
} // function getExcelCalendar()
* Is calculation caching enabled?
return self::$_calculationCacheEnabled;
} // function getCalculationCacheEnabled()
* Enable/disable calculation cache
self::$_calculationCacheEnabled = $pValue;
} // function setCalculationCacheEnabled()
* Enable calculation cache
} // function enableCalculationCache()
* Disable calculation cache
} // function disableCalculationCache()
* Clear calculation cache
self::$_calculationCache = array();
} // function clearCalculationCache()
* Get calculation cache expiration time
return self::$_calculationCacheExpirationTime;
} // getCalculationCacheExpirationTime()
* Set calculation cache expiration time
self::$_calculationCacheExpirationTime = $pValue;
} // function setCalculationCacheExpirationTime()
* Get the currently defined locale code
return self::$_localeLanguage;
} // function getLocale()
// Identify our locale and language
$language = $locale = strtolower($locale);
if (strpos($locale,'_') !== false) {
list ($language) = explode('_',$locale);
// Test whether we have any language data for this language (any locale)
if (in_array($language,self::$_validLocaleLanguages)) {
// initialise language/locale settings
self::$_localeFunctions = array();
self::$_localeArgumentSeparator = ',';
self::$_localeBoolean = array('TRUE' => 'TRUE', 'FALSE' => 'FALSE', 'NULL' => 'NULL');
// Default is English, if user isn't requesting english, then read the necessary data from the locale files
if ($locale != 'en_us') {
// Search for a file with a list of function names for locale
$functionNamesFile = PHPEXCEL_ROOT . 'PHPExcel/locale/'. str_replace('_','/',$locale). '/functions';
// If there isn't a locale specific function file, look for a language specific function file
$functionNamesFile = PHPEXCEL_ROOT . 'PHPExcel/locale/'. $language. '/functions';
// Retrieve the list of locale or language specific function names
$localeFunctions = file($functionNamesFile,FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($localeFunctions as $localeFunction) {
list ($localeFunction) = explode('##',$localeFunction); // Strip out comments
if (strpos($localeFunction,'=') !== false) {
list ($fName,$lfName) = explode('=',$localeFunction);
if ((isset (self::$_PHPExcelFunctions[$fName])) && ($lfName != '') && ($fName != $lfName)) {
self::$_localeFunctions[$fName] = $lfName;
// Default the TRUE and FALSE constants to the locale names of the TRUE() and FALSE() functions
if (isset (self::$_localeFunctions['TRUE'])) { self::$_localeBoolean['TRUE'] = self::$_localeFunctions['TRUE']; }
if (isset (self::$_localeFunctions['FALSE'])) { self::$_localeBoolean['FALSE'] = self::$_localeFunctions['FALSE']; }
$configFile = PHPEXCEL_ROOT . 'PHPExcel/locale/'. str_replace('_','/',$locale). '/config';
$configFile = PHPEXCEL_ROOT . 'PHPExcel/locale/'. $language. '/config';
$localeSettings = file($configFile,FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($localeSettings as $localeSetting) {
list ($localeSetting) = explode('##',$localeSetting); // Strip out comments
if (strpos($localeSetting,'=') !== false) {
list ($settingName,$settingValue) = explode('=',$localeSetting);
case 'ARGUMENTSEPARATOR' :
self::$_localeArgumentSeparator = trim($settingValue);
self::$functionReplaceFromExcel = self::$functionReplaceToExcel =
self::$functionReplaceFromLocale = self::$functionReplaceToLocale = null;
self::$_localeLanguage = $locale;
} // function setLocale()
for ($i = 0; $i < $strlen; ++ $i) {
case '{' : $inBraces = true;
case '}' : $inBraces = false;
private static function _translateFormula($from,$to,$formula,$fromSeparator,$toSeparator) {
// Convert any Excel function names to the required language
if (self::$_localeLanguage !== 'en_us') {
// If there is the possibility of braces within a quoted string, then we don't treat those as matrix indicators
if (strpos($formula,'"') !== false) {
// So instead we skip replacing in any quoted strings by only replacing in every other array element after we've exploded
foreach($temp as &$value) {
// Only count/replace in alternating array entries
$value = self::_translateSeparator($fromSeparator,$toSeparator,$value,$inBraces);
// Then rebuild the formula string
// If there's no quoted strings, then we do a simple count/replace
$formula = self::_translateSeparator($fromSeparator,$toSeparator,$formula,$inBraces);
private static $functionReplaceFromExcel = null;
private static $functionReplaceToLocale = null;
if (is_null(self::$functionReplaceFromExcel)) {
self::$functionReplaceFromExcel = array();
foreach(array_keys(self::$_localeFunctions) as $excelFunctionName) {
self::$functionReplaceFromExcel[] = '/(@?[^\w\.])'. preg_quote($excelFunctionName). '([\s]*\()/Ui';
foreach(array_keys(self::$_localeBoolean) as $excelBoolean) {
self::$functionReplaceFromExcel[] = '/(@?[^\w\.])'. preg_quote($excelBoolean). '([^\w\.])/Ui';
if (is_null(self::$functionReplaceToLocale)) {
self::$functionReplaceToLocale = array();
foreach(array_values(self::$_localeFunctions) as $localeFunctionName) {
self::$functionReplaceToLocale[] = '$1'. trim($localeFunctionName). '$2';
foreach(array_values(self::$_localeBoolean) as $localeBoolean) {
self::$functionReplaceToLocale[] = '$1'. trim($localeBoolean). '$2';
return self::_translateFormula(self::$functionReplaceFromExcel,self::$functionReplaceToLocale,$formula,',',self::$_localeArgumentSeparator);
} // function _translateFormulaToLocale()
private static $functionReplaceFromLocale = null;
private static $functionReplaceToExcel = null;
if (is_null(self::$functionReplaceFromLocale)) {
self::$functionReplaceFromLocale = array();
foreach(array_values(self::$_localeFunctions) as $localeFunctionName) {
self::$functionReplaceFromLocale[] = '/(@?[^\w\.])'. preg_quote($localeFunctionName). '([\s]*\()/Ui';
foreach(array_values(self::$_localeBoolean) as $excelBoolean) {
self::$functionReplaceFromLocale[] = '/(@?[^\w\.])'. preg_quote($excelBoolean). '([^\w\.])/Ui';
if (is_null(self::$functionReplaceToExcel)) {
self::$functionReplaceToExcel = array();
foreach(array_keys(self::$_localeFunctions) as $excelFunctionName) {
self::$functionReplaceToExcel[] = '$1'. trim($excelFunctionName). '$2';
foreach(array_keys(self::$_localeBoolean) as $excelBoolean) {
self::$functionReplaceToExcel[] = '$1'. trim($excelBoolean). '$2';
return self::_translateFormula(self::$functionReplaceFromLocale,self::$functionReplaceToExcel,$formula,self::$_localeArgumentSeparator,',');
} // function _translateFormulaToEnglish()
if (self::$_localeLanguage !== 'en_us') {
$functionName = trim($function,'(');
if (isset (self::$_localeFunctions[$functionName])) {
$brace = ($functionName != $function);
$function = self::$_localeFunctions[$functionName];
if ($brace) { $function .= '('; }
* Wrap string values in quotes
// Error values cannot be "wrapped"
if (preg_match('/^'. self::CALCULATION_REGEXP_ERROR. '$/i', $value, $match)) {
// Return Excel errors "as is"
// Return strings wrapped in quotes
// Convert numeric errors to NaN error
} // function _wrapResult()
* Remove quotes used as a wrapper to identify string values
if ((isset ($value{0})) && ($value{0} == '"') && (substr($value,- 1) == '"')) {
// Convert numeric errors to NaN error
} // function _unwrapResult()
* Calculate cell value (using formula from a cell ID)
* Retained for backward compatibility
* @param PHPExcel_Cell $pCell Cell to calculate
public function calculate(PHPExcel_Cell $pCell = null) {
throw (new Exception($e->getMessage()));
} // function calculate()
* Calculate the value of a cell formula
* @param PHPExcel_Cell $pCell Cell to calculate
* @param Boolean $resetLog Flag indicating whether the debug log should be reset or not
// Initialise the logging settings if requested
$this->debugLog = $this->debugLogStack = array();
$this->_cyclicFormulaCount = 1;
$returnArrayAsType = self::$returnArrayAsType;
self::$returnArrayAsType = self::RETURN_ARRAY_AS_ARRAY;
// Read the formula from the cell
self::$returnArrayAsType = $returnArrayAsType;
// Execute the calculation for the cell formula
$result = self::_unwrapResult($this->_calculateFormulaValue($pCell->getValue(), $pCell->getCoordinate(), $pCell));
throw (new Exception($e->getMessage()));
if ((is_array($result)) && (self::$returnArrayAsType != self::RETURN_ARRAY_AS_ARRAY)) {
if (self::$returnArrayAsType == self::RETURN_ARRAY_AS_ERROR) {
// If there's only a single cell in the array, then we allow it
if (count($testResult) != 1) {
// If keys are numeric, then it's a matrix result rather than a cell range result, so we permit it
} // function calculateCellValue(
* Validate and parse a formula string
* @param string $formula Formula to parse
// Basic validation that this is indeed a formula
// We return an empty array if not
$formula = trim($formula);
if ((!isset ($formula{0})) || ($formula{0} != '=')) return array();
if (!isset ($formula{0})) return array();
// Parse the formula and return the token stack
return $this->_parseFormula($formula);
} // function parseFormula()
* Calculate the value of a formula
* @param string $formula Formula to parse
public function calculateFormula($formula, $cellID= null, PHPExcel_Cell $pCell = null) {
// Initialise the logging settings
$this->debugLog = $this->debugLogStack = array();
// Disable calculation cacheing because it only applies to cell calculations, not straight formulae
// But don't actually flush any cache
self::$_calculationCacheEnabled = false;
// Execute the calculation
throw (new Exception($e->getMessage()));
// Reset calculation cacheing to its previous state
self::$_calculationCacheEnabled = $resetCache;
} // function calculateFormula()
* Parse a cell formula and calculate its value
* @param string $formula The formula to parse and calculate
* @param string $cellID The ID (e.g. A3) of the cell that we are calculating
* @param PHPExcel_Cell $pCell Cell to calculate
// echo '<b>'.$cellID.'</b><br />';
// Basic validation that this is indeed a formula
// We simply return the "cell value" (formula) if not
$formula = trim($formula);
if ($formula{0} != '=') return self::_wrapResult($formula);
if (!isset ($formula{0})) return self::_wrapResult($formula);
$pCellParent = $pCell->getParent();
$wsTitle = $pCellParent->getTitle();
// Is calculation cacheing enabled?
if (self::$_calculationCacheEnabled) {
// Is the value present in calculation cache?
// echo 'Testing cache value<br />';
if (isset (self::$_calculationCache[$wsTitle][$cellID])) {
// echo 'Value is in cache<br />';
$this->_writeDebug('Testing cache value for cell '. $cellID);
if ((microtime(true) - self::$_calculationCache[$wsTitle][$cellID]['time']) < self::$_calculationCacheExpirationTime) {
// echo 'Cache time is still valid<br />';
$this->_writeDebug('Retrieving value for '. $cellID. ' from cache');
// Return the cached result
$returnValue = self::$_calculationCache[$wsTitle][$cellID]['data'];
// echo 'Retrieving data value of '.$returnValue.' for '.$cellID.' from cache<br />';
if (is_array($returnValue)) {
// echo 'Cache has expired<br />';
$this->_writeDebug('Cache value for '. $cellID. ' has expired');
// Clear the cache if it's no longer valid
unset (self::$_calculationCache[$wsTitle][$cellID]);
if ((in_array($wsTitle. '!'. $cellID,$this->debugLogStack)) && ($wsTitle != "\x00Wrk")) {
($this->_cyclicFormulaCell == $wsTitle. '!'. $cellID)) {
} elseif ($this->_cyclicFormulaCell == $wsTitle. '!'. $cellID) {
++ $this->_cyclicFormulaCount;
} elseif ($this->_cyclicFormulaCell == '') {
$this->_cyclicFormulaCell = $wsTitle. '!'. $cellID;
$this->debugLogStack[] = $wsTitle. '!'. $cellID;
// Parse the formula onto the token stack and calculate the value
$cellValue = $this->_processTokenStack($this->_parseFormula($formula, $pCell), $cellID, $pCell);
// Save to calculation cache
if (self::$_calculationCacheEnabled) {
self::$_calculationCache[$wsTitle][$cellID]['time'] = microtime(true);
self::$_calculationCache[$wsTitle][$cellID]['data'] = $cellValue;
// Return the calculated value
} // function _calculateFormulaValue()
* Ensure that paired matrix operands are both matrices and of the same size
* @param mixed &$operand1 First matrix operand
* @param mixed &$operand2 Second matrix operand
* @param integer $resize Flag indicating whether the matrices should be resized to match
* and (if so), whether the smaller dimension should grow or the
private static function _checkMatrixOperands(&$operand1,&$operand2,$resize = 1) {
// Examine each of the two operands, and turn them into an array if they aren't one already
// Note that this function should only be called if one or both of the operand is already an array
if (!is_array($operand1)) {
list ($matrixRows,$matrixColumns) = self::_getMatrixDimensions($operand2);
list ($matrixRows,$matrixColumns) = self::_getMatrixDimensions($operand1);
list ($matrix1Rows,$matrix1Columns) = self::_getMatrixDimensions($operand1);
list ($matrix2Rows,$matrix2Columns) = self::_getMatrixDimensions($operand2);
if (($matrix1Rows == $matrix2Columns) && ($matrix2Rows == $matrix1Columns)) {
// Given two matrices of (potentially) unequal size, convert the smaller in each dimension to match the larger
self::_resizeMatricesExtend($operand1,$operand2,$matrix1Rows,$matrix1Columns,$matrix2Rows,$matrix2Columns);
} elseif ($resize == 1) {
// Given two matrices of (potentially) unequal size, convert the larger in each dimension to match the smaller
self::_resizeMatricesShrink($operand1,$operand2,$matrix1Rows,$matrix1Columns,$matrix2Rows,$matrix2Columns);
return array( $matrix1Rows,$matrix1Columns,$matrix2Rows,$matrix2Columns);
} // function _checkMatrixOperands()
* Read the dimensions of a matrix, and re-index it with straight numeric keys starting from row 0, column 0
* @param mixed &$matrix matrix operand
* @return array An array comprising the number of rows, and number of columns
$matrixRows = count($matrix);
foreach($matrix as $rowKey => $rowValue) {
$matrixColumns = max(count($rowValue),$matrixColumns);
$matrix[$rowKey] = array($rowValue);
return array($matrixRows,$matrixColumns);
} // function _getMatrixDimensions()
* Ensure that paired matrix operands are both matrices of the same size
* @param mixed &$matrix1 First matrix operand
* @param mixed &$matrix2 Second matrix operand
private static function _resizeMatricesShrink(&$matrix1,&$matrix2,$matrix1Rows,$matrix1Columns,$matrix2Rows,$matrix2Columns) {
if (($matrix2Columns < $matrix1Columns) || ($matrix2Rows < $matrix1Rows)) {
if ($matrix2Columns < $matrix1Columns) {
for ($i = 0; $i < $matrix1Rows; ++ $i) {
for ($j = $matrix2Columns; $j < $matrix1Columns; ++ $j) {
if ($matrix2Rows < $matrix1Rows) {
for ($i = $matrix2Rows; $i < $matrix1Rows; ++ $i) {
if (($matrix1Columns < $matrix2Columns) || ($matrix1Rows < $matrix2Rows)) {
if ($matrix1Columns < $matrix2Columns) {
for ($i = 0; $i < $matrix2Rows; ++ $i) {
for ($j = $matrix1Columns; $j < $matrix2Columns; ++ $j) {
if ($matrix1Rows < $matrix2Rows) {
for ($i = $matrix1Rows; $i < $matrix2Rows; ++ $i) {
} // function _resizeMatricesShrink()
* Ensure that paired matrix operands are both matrices of the same size
* @param mixed &$matrix1 First matrix operand
* @param mixed &$matrix2 Second matrix operand
private static function _resizeMatricesExtend(&$matrix1,&$matrix2,$matrix1Rows,$matrix1Columns,$matrix2Rows,$matrix2Columns) {
if (($matrix2Columns < $matrix1Columns) || ($matrix2Rows < $matrix1Rows)) {
if ($matrix2Columns < $matrix1Columns) {
for ($i = 0; $i < $matrix2Rows; ++ $i) {
$x = $matrix2[$i][$matrix2Columns- 1];
for ($j = $matrix2Columns; $j < $matrix1Columns; ++ $j) {
if ($matrix2Rows < $matrix1Rows) {
$x = $matrix2[$matrix2Rows- 1];
for ($i = 0; $i < $matrix1Rows; ++ $i) {
if (($matrix1Columns < $matrix2Columns) || ($matrix1Rows < $matrix2Rows)) {
if ($matrix1Columns < $matrix2Columns) {
for ($i = 0; $i < $matrix1Rows; ++ $i) {
$x = $matrix1[$i][$matrix1Columns- 1];
for ($j = $matrix1Columns; $j < $matrix2Columns; ++ $j) {
if ($matrix1Rows < $matrix2Rows) {
$x = $matrix1[$matrix1Rows- 1];
for ($i = 0; $i < $matrix2Rows; ++ $i) {
} // function _resizeMatricesExtend()
* Format details of an operand for display in the log (based on operand type)
* @param mixed $value First matrix operand
private function _showValue($value) {
if (count($testArray) == 1) {
foreach($value as $row) {
$returnMatrix[] = implode($pad,$row);
return '{ '. implode($rpad,$returnMatrix). ' }';
return ($value) ? self::$_localeBoolean['TRUE'] : self::$_localeBoolean['FALSE'];
} // function _showValue()
* Format type and details of an operand for display in the log (based on operand type)
* @param mixed $value First matrix operand
private function _showTypeDetails($value) {
$testArray = PHPExcel_Calculation_Functions::flattenArray($value);
if (count($testArray) == 1) {
$typeString = 'a floating point number';
$typeString = 'an integer number';
$typeString = 'a boolean';
$typeString = 'a matrix';
return 'an empty string';
} elseif ($value{0} == '#') {
return 'a '. $value. ' error';
$typeString = 'a string';
return $typeString. ' with a value of '. $this->_showValue($value);
} // function _showTypeDetails()
private static function _convertMatrixReferences($formula) {
static $matrixReplaceFrom = array('{',';','}');
static $matrixReplaceTo = array('MKMATRIX(MKMATRIX(','),MKMATRIX(','))');
// Convert any Excel matrix references to the MKMATRIX() function
if (strpos($formula,'{') !== false) {
// If there is the possibility of braces within a quoted string, then we don't treat those as matrix indicators
if (strpos($formula,'"') !== false) {
// So instead we skip replacing in any quoted strings by only replacing in every other array element after we've exploded
$temp = explode('"',$formula);
// Open and Closed counts used for trapping mismatched braces in the formula
$openCount = $closeCount = 0;
foreach($temp as &$value) {
// Only count/replace in alternating array entries
$value = str_replace($matrixReplaceFrom,$matrixReplaceTo,$value);
// Then rebuild the formula string
// If there's no quoted strings, then we do a simple count/replace
$openCount = substr_count($formula,'{');
$closeCount = substr_count($formula,'}');
$formula = str_replace($matrixReplaceFrom,$matrixReplaceTo,$formula);
// Trap for mismatched braces and trigger an appropriate error
if ($openCount < $closeCount) {
} elseif ($openCount > $closeCount) {
} // function _convertMatrixReferences()
private static function _mkMatrix() {
} // function _mkMatrix()
// Convert infix to postfix notation
private function _parseFormula($formula, PHPExcel_Cell $pCell = null) {
if (($formula = self::_convertMatrixReferences(trim($formula))) === false) {
// If we're using cell caching, then $pCell may well be flushed back to the cache (which detaches the parent worksheet),
// so we store the parent worksheet so that we can re-attach it when necessary
$pCellParent = (!is_null($pCell)) ? $pCell->getParent() : null;
// These operators always work on two values
// Array key is the operator, the value indicates whether this is a left or right associative operator
$operatorAssociativity = array('^' => 0, // Exponentiation
'*' => 0, '/' => 0, // Multiplication and Division
'+' => 0, '-' => 0, // Addition and Subtraction
'&' => 0, // Concatenation
'|' => 0, ':' => 0, // Intersect and Range
'>' => 0, '<' => 0, '=' => 0, '>=' => 0, '<=' => 0, '<>' => 0 // Comparison
// Comparison (Boolean) Operators
// These operators work on two values, but always return a boolean result
$comparisonOperators = array('>' => true, '<' => true, '=' => true, '>=' => true, '<=' => true, '<>' => true);
// This list includes all valid operators, whether binary (including boolean) or unary (such as %)
// Array key is the operator, the value is its precedence
$operatorPrecedence = array(':' => 8, // Range
'^' => 4, // Exponentiation
'*' => 3, '/' => 3, // Multiplication and Division
'+' => 2, '-' => 2, // Addition and Subtraction
'&' => 1, // Concatenation
'>' => 0, '<' => 0, '=' => 0, '>=' => 0, '<=' => 0, '<>' => 0 // Comparison
$regexpMatchString = '/^('. self::CALCULATION_REGEXP_FUNCTION.
'|'. self::CALCULATION_REGEXP_NUMBER.
'|'. self::CALCULATION_REGEXP_STRING.
'|'. self::CALCULATION_REGEXP_OPENBRACE.
'|'. self::CALCULATION_REGEXP_CELLREF.
'|'. self::CALCULATION_REGEXP_NAMEDRANGE.
'|'. self::CALCULATION_REGEXP_ERROR.
// Start with initialisation
$expectingOperator = false; // We use this test in syntax-checking the expression to determine when a
// - is a negation or + is a positive operator rather than an operation
$expectingOperand = false; // We use this test in syntax-checking the expression to determine whether an operand
// should be null in a function call
// The guts of the lexical parser
// Loop through the formula extracting each operator and operand in turn
// echo 'Assessing Expression <b>'.substr($formula, $index).'</b><br />';
$opCharacter = $formula{$index}; // Get the first character of the value at the current index position
// echo 'Initial character of expression block is '.$opCharacter.'<br />';
if ((isset ($comparisonOperators[$opCharacter])) && (strlen($formula) > $index) && (isset ($comparisonOperators[$formula{$index+ 1}]))) {
$opCharacter .= $formula{++ $index};
// echo 'Initial character of expression block is comparison operator '.$opCharacter.'<br />';
// Find out if we're currently at the beginning of a number, variable, cell reference, function, parenthesis or operand
$isOperandOrFunction = preg_match($regexpMatchString, substr($formula, $index), $match);
// echo '$isOperandOrFunction is '.(($isOperandOrFunction) ? 'True' : 'False').'<br />';
if ($opCharacter == '-' && !$expectingOperator) { // Is it a negation instead of a minus?
// echo 'Element is a Negation operator<br />';
$stack->push('Unary Operator','~'); // Put a negation on the stack
++ $index; // and drop the negation symbol
} elseif ($opCharacter == '%' && $expectingOperator) {
// echo 'Element is a Percentage operator<br />';
$stack->push('Unary Operator','%'); // Put a percentage on the stack
} elseif ($opCharacter == '+' && !$expectingOperator) { // Positive (unary plus rather than binary operator plus) can be discarded?
// echo 'Element is a Positive number, not Plus operator<br />';
++ $index; // Drop the redundant plus symbol
} elseif ((($opCharacter == '~') || ($opCharacter == '|')) && (!$isOperandOrFunction)) { // We have to explicitly deny a tilde or pipe, because they are legal
return $this->_raiseFormulaError("Formula Error: Illegal character '~'"); // on the stack but not in the input expression
} elseif ((isset (self::$_operators[$opCharacter]) or $isOperandOrFunction) && $expectingOperator) { // Are we putting an operator on the stack?
// echo 'Element with value '.$opCharacter.' is an Operator<br />';
while($stack->count() > 0 &&
($o2 = $stack->last()) &&
isset (self::$_operators[$o2['value']]) &&
@($operatorAssociativity[$opCharacter] ? $operatorPrecedence[$opCharacter] < $operatorPrecedence[$o2['value']] : $operatorPrecedence[$opCharacter] <= $operatorPrecedence[$o2['value']])) {
$output[] = $stack->pop(); // Swap operands and higher precedence operators from the stack to the output
$stack->push('Binary Operator',$opCharacter); // Finally put our current operator onto the stack
$expectingOperator = false;
} elseif ($opCharacter == ')' && $expectingOperator) { // Are we expecting to close a parenthesis?
// echo 'Element is a Closing bracket<br />';
$expectingOperand = false;
while (($o2 = $stack->pop()) && $o2['value'] != '(') { // Pop off the stack back to the last (
if (preg_match('/^'. self::CALCULATION_REGEXP_FUNCTION. '$/i', $d['value'], $matches)) { // Did this parenthesis just close a function?
$functionName = $matches[1]; // Get the function name
// echo 'Closed Function is '.$functionName.'<br />';
$argumentCount = $d['value']; // See how many arguments there were (argument count is the next value stored on the stack)
// if ($argumentCount == 0) {
// echo 'With no arguments<br />';
// } elseif ($argumentCount == 1) {
// echo 'With 1 argument<br />';
// echo 'With '.$argumentCount.' arguments<br />';
$output[] = $d; // Dump the argument count on the output
$output[] = $stack->pop(); // Pop the function and push onto the output
if (isset (self::$_controlFunctions[$functionName])) {
// echo 'Built-in function '.$functionName.'<br />';
$expectedArgumentCount = self::$_controlFunctions[$functionName]['argumentCount'];
$functionCall = self::$_controlFunctions[$functionName]['functionCall'];
} elseif (isset (self::$_PHPExcelFunctions[$functionName])) {
// echo 'PHPExcel function '.$functionName.'<br />';
$expectedArgumentCount = self::$_PHPExcelFunctions[$functionName]['argumentCount'];
$functionCall = self::$_PHPExcelFunctions[$functionName]['functionCall'];
} else { // did we somehow push a non-function on the stack? this should never happen
return $this->_raiseFormulaError("Formula Error: Internal error, non-function on stack");
// Check the argument count
$argumentCountError = false;
if ($expectedArgumentCount < 0) {
// echo '$expectedArgumentCount is between 0 and '.abs($expectedArgumentCount).'<br />';
if ($argumentCount > abs($expectedArgumentCount)) {
$argumentCountError = true;
$expectedArgumentCountString = 'no more than '. abs($expectedArgumentCount);
// echo '$expectedArgumentCount is numeric '.$expectedArgumentCount.'<br />';
if ($argumentCount != $expectedArgumentCount) {
$argumentCountError = true;
$expectedArgumentCountString = $expectedArgumentCount;
} elseif ($expectedArgumentCount != '*') {
$isOperandOrFunction = preg_match('/(\d*)([-+,])(\d*)/',$expectedArgumentCount,$argMatch);
if ($argumentCount < $argMatch[1]) {
$argumentCountError = true;
$expectedArgumentCountString = $argMatch[1]. ' or more ';
if (($argumentCount < $argMatch[1]) || ($argumentCount > $argMatch[3])) {
$argumentCountError = true;
$expectedArgumentCountString = 'between '. $argMatch[1]. ' and '. $argMatch[3];
if (($argumentCount != $argMatch[1]) && ($argumentCount != $argMatch[3])) {
$argumentCountError = true;
$expectedArgumentCountString = 'either '. $argMatch[1]. ' or '. $argMatch[3];
if ($argumentCountError) {
return $this->_raiseFormulaError("Formula Error: Wrong number of arguments for $functionName() function: $argumentCount given, ". $expectedArgumentCountString. " expected");
} elseif ($opCharacter == ',') { // Is this the separator for function arguments?
// echo 'Element is a Function argument separator<br />';
while (($o2 = $stack->pop()) && $o2['value'] != '(') { // Pop off the stack back to the last (
else $output[] = $o2; // pop the argument expression stuff and push onto the output
// If we've a comma when we're expecting an operand, then what we actually have is a null operand;
// so push a null onto the stack
if (($expectingOperand) || (!$expectingOperator)) {
$output[] = array('type' => 'NULL Value', 'value' => self::$_ExcelConstants['NULL'], 'reference' => null);
// make sure there was a function
if (!preg_match('/^'. self::CALCULATION_REGEXP_FUNCTION. '$/i', $d['value'], $matches))
$stack->push($d['type'],++ $d['value'],$d['reference']); // increment the argument count
$stack->push('Brace', '('); // put the ( back on, we'll need to pop back to it again
$expectingOperator = false;
$expectingOperand = true;
} elseif ($opCharacter == '(' && !$expectingOperator) {
// echo 'Element is an Opening Bracket<br />';
$stack->push('Brace', '(');
} elseif ($isOperandOrFunction && !$expectingOperator) { // do we now have a function/variable/number?
$expectingOperator = true;
$expectingOperand = false;
// echo 'Element with value '.$val.' is an Operand, Variable, Constant, String, Number, Cell Reference or Function<br />';
if (preg_match('/^'. self::CALCULATION_REGEXP_FUNCTION. '$/i', $val, $matches)) {
// echo 'Element '.$val.' is a Function<br />';
if (isset (self::$_PHPExcelFunctions[strtoupper($matches[1])]) || isset (self::$_controlFunctions[strtoupper($matches[1])])) { // it's a function
$stack->push('Operand Count for Function '. self::_localeFunc(strtoupper($val)). ')', 0);
$expectingOperator = true;
$stack->push('Operand Count for Function '. self::_localeFunc(strtoupper($val)). ')', 1);
$expectingOperator = false;
$stack->push('Brace', '(');
} else { // it's a var w/ implicit multiplication
$output[] = array('type' => 'Value', 'value' => $matches[1], 'reference' => null);
} elseif (preg_match('/^'. self::CALCULATION_REGEXP_CELLREF. '$/i', $val, $matches)) {
// echo 'Element '.$val.' is a Cell reference<br />';
// Watch for this case-change when modifying to allow cell references in different worksheets...
// Should only be applied to the actual cell column, not the worksheet name
// If the last entry on the stack was a : operator, then we have a cell range reference
$testPrevOp = $stack->last(1);
if ($testPrevOp['value'] == ':') {
// If we have a worksheet reference, then we're playing with a 3D reference
// Otherwise, we 'inherit' the worksheet reference from the start cell reference
// The start of the cell range reference should be the last entry in $output
$startCellRef = $output[count($output)- 1]['value'];
preg_match('/^'. self::CALCULATION_REGEXP_CELLREF. '$/i', $startCellRef, $startMatches);
if ($startMatches[2] > '') {
$val = $startMatches[2]. '!'. $val;
$output[] = array('type' => 'Cell Reference', 'value' => $val, 'reference' => $val);
// $expectingOperator = false;
} else { // it's a variable, constant, string, number or boolean
// echo 'Element is a Variable, Constant, String, Number or Boolean<br />';
// If the last entry on the stack was a : operator, then we may have a row or column range reference
$testPrevOp = $stack->last(1);
if ($testPrevOp['value'] == ':') {
$startRowColRef = $output[count($output)- 1]['value'];
if (strpos('!',$startRowColRef) !== false) {
list ($rangeWS1,$startRowColRef) = explode('!',$startRowColRef);
if ($rangeWS1 != '') $rangeWS1 .= '!';
if (strpos('!',$val) !== false) {
list ($rangeWS2,$val) = explode('!',$val);
if ($rangeWS2 != '') $rangeWS2 .= '!';
($startRowColRef <= 1048576) && ($val <= 1048576)) {
$endRowColRef = (!is_null($pCellParent)) ? $pCellParent->getHighestColumn() : 'XFD'; // Max 16,384 columns for Excel2007
$output[count($output)- 1]['value'] = $rangeWS1. 'A'. $startRowColRef;
$val = $rangeWS2. $endRowColRef. $val;
$endRowColRef = (!is_null($pCellParent)) ? $pCellParent->getHighestRow() : 1048576; // Max 1,048,576 rows for Excel2007
$output[count($output)- 1]['value'] = $rangeWS1. strtoupper($startRowColRef). '1';
$val = $rangeWS2. $val. $endRowColRef;
if ($opCharacter == '"') {
// echo 'Element is a String<br />';
// UnEscape any quotes within the string
$val = self::_wrapResult(str_replace('""','"',self::_unwrapResult($val)));
// echo 'Element is a Number<br />';
if ((strpos($val,'.') !== false) || (stripos($val,'e') !== false) || ($val > PHP_INT_MAX) || ($val < - PHP_INT_MAX)) {
// echo 'Casting '.$val.' to float<br />';
// echo 'Casting '.$val.' to integer<br />';
} elseif (isset (self::$_ExcelConstants[trim(strtoupper($val))])) {
// echo 'Element '.$excelConstant.' is an Excel Constant<br />';
$val = self::$_ExcelConstants[$excelConstant];
} elseif (($localeConstant = array_search(trim(strtoupper($val)), self::$_localeBoolean)) !== false) {
// echo 'Element '.$localeConstant.' is an Excel Constant<br />';
$val = self::$_ExcelConstants[$localeConstant];
$details = array('type' => 'Value', 'value' => $val, 'reference' => null);
if ($localeConstant) { $details['localeValue'] = $localeConstant; }
} elseif ($opCharacter == '$') { // absolute row or column range
} elseif ($opCharacter == ')') { // miscellaneous error checking
$output[] = array('type' => 'Null Value', 'value' => self::$_ExcelConstants['NULL'], 'reference' => null);
$expectingOperand = false;
$expectingOperator = true;
} elseif (isset (self::$_operators[$opCharacter]) && !$expectingOperator) {
return $this->_raiseFormulaError("Formula Error: Unexpected operator '$opCharacter'");
} else { // I don't even want to know what you did to get here
// Test for end of formula string
if ($index == strlen($formula)) {
// Did we end with an operator?.
// Only valid for the % unary operator
if ((isset (self::$_operators[$opCharacter])) && ($opCharacter != '%')) {
return $this->_raiseFormulaError("Formula Error: Operator '$opCharacter' has no operands");
while (($formula{$index} == "\n") || ($formula{$index} == "\r")) {
if ($formula{$index} == ' ') {
while ($formula{$index} == ' ') {
// If we're expecting an operator, but only have a space between the previous and next operands (and both are
// Cell References) then we have an INTERSECTION operator
// echo 'Possible Intersect Operator<br />';
if (($expectingOperator) && (preg_match('/^'. self::CALCULATION_REGEXP_CELLREF. '.*/Ui', substr($formula, $index), $match)) &&
($output[count($output)- 1]['type'] == 'Cell Reference')) {
// echo 'Element is an Intersect Operator<br />';
while($stack->count() > 0 &&
($o2 = $stack->last()) &&
isset (self::$_operators[$o2['value']]) &&
@($operatorAssociativity[$opCharacter] ? $operatorPrecedence[$opCharacter] < $operatorPrecedence[$o2['value']] : $operatorPrecedence[$opCharacter] <= $operatorPrecedence[$o2['value']])) {
$output[] = $stack->pop(); // Swap operands and higher precedence operators from the stack to the output
$stack->push('Binary Operator','|'); // Put an Intersect Operator on the stack
$expectingOperator = false;
while (!is_null($op = $stack->pop())) { // pop everything off the stack and push onto output
if ($opCharacter['value'] == '(') return $this->_raiseFormulaError("Formula Error: Expecting ')'"); // if there are any opening braces on the stack, then braces were unbalanced
} // function _parseFormula()
// evaluate postfix notation
private function _processTokenStack($tokens, $cellID = null, PHPExcel_Cell $pCell = null) {
if ($tokens == false) return false;
// If we're using cell caching, then $pCell may well be flushed back to the cache (which detaches the parent worksheet),
// so we store the parent worksheet so that we can re-attach it when necessary
$pCellParent = (!is_null($pCell)) ? $pCell->getParent() : null;
// Loop through each token in turn
foreach ($tokens as $tokenData) {
$token = $tokenData['value'];
// echo '<b>Token is '.$token.'</b><br />';
// if the token is a binary operator, pop the top two values off the stack, do the operation, and push the result back on the stack
if (isset (self::$_binaryOperators[$token])) {
// echo 'Token is a binary operator<br />';
// We must have two operands, error if we don't
if (is_null($operand2Data = $stack->pop())) return $this->_raiseFormulaError('Internal error - Operand value missing from stack');
if (is_null($operand1Data = $stack->pop())) return $this->_raiseFormulaError('Internal error - Operand value missing from stack');
$operand1 = $operand1Data['value'];
$operand2 = $operand2Data['value'];
$this->_writeDebug('Evaluating Range '. $this->_showValue($operand1Data['reference']). $token. $this->_showValue($operand2Data['reference']));
$this->_writeDebug('Evaluating '. $this->_showValue($operand1). ' '. $token. ' '. $this->_showValue($operand2));
// Process the operation in the appropriate manner
// Comparison (Boolean) Operators
case '>' : // Greater than
case '>=' : // Greater than or Equal to
case '<=' : // Less than or Equal to
case '<>' : // Inequality
$this->_executeBinaryComparisonOperation($cellID,$operand1,$operand2,$token,$stack);
if (strpos($operand1Data['reference'],'!') !== false) {
list ($sheet1,$operand1Data['reference']) = explode('!',$operand1Data['reference']);
$sheet1 = (!is_null($pCellParent)) ? $pCellParent->getTitle() : '';
if (strpos($operand2Data['reference'],'!') !== false) {
list ($sheet2,$operand2Data['reference']) = explode('!',$operand2Data['reference']);
if ($sheet1 == $sheet2) {
if (is_null($operand1Data['reference'])) {
if ((trim($operand1Data['value']) != '') && (is_numeric($operand1Data['value']))) {
$operand1Data['reference'] = $pCell->getColumn(). $operand1Data['value'];
} elseif (trim($operand1Data['reference']) == '') {
$operand1Data['reference'] = $pCell->getCoordinate();
$operand1Data['reference'] = $operand1Data['value']. $pCell->getRow();
if (is_null($operand2Data['reference'])) {
if ((trim($operand2Data['value']) != '') && (is_numeric($operand2Data['value']))) {
$operand2Data['reference'] = $pCell->getColumn(). $operand2Data['value'];
} elseif (trim($operand2Data['reference']) == '') {
$operand2Data['reference'] = $pCell->getCoordinate();
$operand2Data['reference'] = $operand2Data['value']. $pCell->getRow();
foreach($oData as $oDatum) {
$cellValue = $this->extractCellRange($cellRef, $pCellParent->getParent()->getSheetByName($sheet1), false);
$stack->push('Cell Reference',$cellValue,$cellRef);
$this->_executeNumericBinaryOperation($cellID,$operand1,$operand2,$token,'plusEquals',$stack);
case '-' : // Subtraction
$this->_executeNumericBinaryOperation($cellID,$operand1,$operand2,$token,'minusEquals',$stack);
case '*' : // Multiplication
$this->_executeNumericBinaryOperation($cellID,$operand1,$operand2,$token,'arrayTimesEquals',$stack);
$this->_executeNumericBinaryOperation($cellID,$operand1,$operand2,$token,'arrayRightDivide',$stack);
case '^' : // Exponential
$this->_executeNumericBinaryOperation($cellID,$operand1,$operand2,$token,'power',$stack);
case '&' : // Concatenation
// If either of the operands is a matrix, we need to treat them both as matrices
// (converting the other operand to a matrix if need be); then perform the required
$operand1 = ($operand1) ? self::$_localeBoolean['TRUE'] : self::$_localeBoolean['FALSE'];
if (is_bool($operand2)) {
$operand2 = ($operand2) ? self::$_localeBoolean['TRUE'] : self::$_localeBoolean['FALSE'];
if ((is_array($operand1)) || (is_array($operand2))) {
// Ensure that both operands are arrays/matrices
self::_checkMatrixOperands($operand1,$operand2,2);
// Convert operand 1 from a PHP array to a matrix
// Perform the required operation against the operand 1 matrix, passing in operand 2
$matrixResult = $matrix->concat($operand2);
$result = $matrixResult->getArray();
} catch (Exception $ex) {
$this->_writeDebug('JAMA Matrix Exception: '. $ex->getMessage());
$result = '"'. str_replace('""','"',self::_unwrapResult($operand1,'"'). self::_unwrapResult($operand2,'"')). '"';
$this->_writeDebug('Evaluation Result is '. $this->_showTypeDetails($result));
$stack->push('Value',$result);
$cellIntersect = $oCol = $oRow = array();
foreach($rowIntersect[$row] as $col => $data) {
$this->_writeDebug('Evaluation Result is '. $this->_showTypeDetails($cellIntersect));
$stack->push('Value',$cellIntersect,$cellRef);
// if the token is a unary operator, pop one value off the stack, do the operation, and push it back on
} elseif (($token === '~') || ($token === '%')) {
// echo 'Token is a unary operator<br />';
// echo 'Token is a negation operator<br />';
$this->_writeDebug('Evaluating Negation of '. $this->_showValue($arg));
// echo 'Token is a percentile operator<br />';
$this->_writeDebug('Evaluating Percentile of '. $this->_showValue($arg));
self::_checkMatrixOperands($arg,$multiplier,2);
$matrixResult = $matrix1->arrayTimesEquals($multiplier);
$result = $matrixResult->getArray();
} catch (Exception $ex) {
$this->_writeDebug('JAMA Matrix Exception: '. $ex->getMessage());
$this->_writeDebug('Evaluation Result is '. $this->_showTypeDetails($result));
$stack->push('Value',$result);
$this->_executeNumericBinaryOperation($cellID,$multiplier,$arg,'*','arrayTimesEquals',$stack);
} elseif (preg_match('/^'. self::CALCULATION_REGEXP_CELLREF. '$/i', $token, $matches)) {
// echo 'Element '.$token.' is a Cell reference<br />';
if (isset ($matches[8])) {
// echo 'Reference is a Range of cells<br />';
// We can't access the range, so return a REF error
$cellRef = $matches[6]. $matches[7]. ':'. $matches[9]. $matches[10];
$matches[2] = trim($matches[2],"\"'");
// echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'<br />';
$this->_writeDebug('Evaluating Cell Range '. $cellRef. ' in worksheet '. $matches[2]);
$cellValue = $this->extractCellRange($cellRef, $pCellParent->getParent()->getSheetByName($matches[2]), false);
$this->_writeDebug('Evaluation Result for cells '. $cellRef. ' in worksheet '. $matches[2]. ' is '. $this->_showTypeDetails($cellValue));
// $cellRef = $matches[2].'!'.$cellRef;
// echo '$cellRef='.$cellRef.' in current worksheet<br />';
$this->_writeDebug('Evaluating Cell Range '. $cellRef. ' in current worksheet');
$this->_writeDebug('Evaluation Result for cells '. $cellRef. ' is '. $this->_showTypeDetails($cellValue));
// echo 'Reference is a single Cell<br />';
// We can't access the cell, so return a REF error
$cellRef = $matches[6]. $matches[7];
$matches[2] = trim($matches[2],"\"'");
// echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'<br />';
$this->_writeDebug('Evaluating Cell '. $cellRef. ' in worksheet '. $matches[2]);
if ($pCellParent->getParent()->getSheetByName($matches[2])->cellExists($cellRef)) {
$cellValue = $this->extractCellRange($cellRef, $pCellParent->getParent()->getSheetByName($matches[2]), false);
$pCell->attach($pCellParent);
$this->_writeDebug('Evaluation Result for cell '. $cellRef. ' in worksheet '. $matches[2]. ' is '. $this->_showTypeDetails($cellValue));
// $cellRef = $matches[2].'!'.$cellRef;
// echo '$cellRef='.$cellRef.' in current worksheet<br />';
$this->_writeDebug('Evaluating Cell '. $cellRef. ' in current worksheet');
if ($pCellParent->cellExists($cellRef)) {
$pCell->attach($pCellParent);
$this->_writeDebug('Evaluation Result for cell '. $cellRef. ' is '. $this->_showTypeDetails($cellValue));
$stack->push('Value',$cellValue,$cellRef);
// if the token is a function, pop arguments off the stack, hand them to the function, and push the result back on
} elseif (preg_match('/^'. self::CALCULATION_REGEXP_FUNCTION. '$/i', $token, $matches)) {
// echo 'Token is a function<br />';
$functionName = $matches[1];
$argCount = $stack->pop();
$argCount = $argCount['value'];
if ($functionName != 'MKMATRIX') {
$this->_writeDebug('Evaluating Function '. self::_localeFunc($functionName). '() with '. (($argCount == 0) ? 'no' : $argCount). ' argument'. (($argCount == 1) ? '' : 's'));
if ((isset (self::$_PHPExcelFunctions[$functionName])) || (isset (self::$_controlFunctions[$functionName]))) { // function
if (isset (self::$_PHPExcelFunctions[$functionName])) {
$functionCall = self::$_PHPExcelFunctions[$functionName]['functionCall'];
$passByReference = isset (self::$_PHPExcelFunctions[$functionName]['passByReference']);
$passCellReference = isset (self::$_PHPExcelFunctions[$functionName]['passCellReference']);
} elseif (isset (self::$_controlFunctions[$functionName])) {
$functionCall = self::$_controlFunctions[$functionName]['functionCall'];
$passByReference = isset (self::$_controlFunctions[$functionName]['passByReference']);
$passCellReference = isset (self::$_controlFunctions[$functionName]['passCellReference']);
// get the arguments for this function
// echo 'Function '.$functionName.' expects '.$argCount.' arguments<br />';
$args = $argArrayVals = array();
for ($i = 0; $i < $argCount; ++ $i) {
if (($passByReference) &&
(isset (self::$_PHPExcelFunctions[$functionName]['passByReference'][$a])) &&
(self::$_PHPExcelFunctions[$functionName]['passByReference'][$a])) {
if (is_null($arg['reference'])) {
if ($functionName != 'MKMATRIX') { $argArrayVals[] = $this->_showValue($cellID); }
$args[] = $arg['reference'];
if ($functionName != 'MKMATRIX') { $argArrayVals[] = $this->_showValue($arg['reference']); }
$args[] = self::_unwrapResult($arg['value']);
if ($functionName != 'MKMATRIX') { $argArrayVals[] = $this->_showValue($arg['value']); }
// Reverse the order of the arguments
if (($passByReference) && ($argCount == 0)) {
$argArrayVals[] = $this->_showValue($cellID);
// echo 'Arguments are: ';
if ($functionName != 'MKMATRIX') {
$this->_writeDebug('Evaluating '. self::_localeFunc($functionName). '( '. implode(self::$_localeArgumentSeparator. ' ',PHPExcel_Calculation_Functions::flattenArray($argArrayVals)). ' )');
// Process each argument in turn, building the return value as an array
// if (($argCount == 1) && (is_array($args[1])) && ($functionName != 'MKMATRIX')) {
// $this->_writeDebug('Argument is a matrix: '.$this->_showValue($operand1));
// foreach($operand1 as $args) {
// if (is_array($args)) {
// foreach($args as $arg) {
// $this->_writeDebug('Evaluating '.self::_localeFunc($functionName).'( '.$this->_showValue($arg).' )');
// $r = call_user_func_array($functionCall,$arg);
// $this->_writeDebug('Evaluation Result for '.self::_localeFunc($functionName).'() function call is '.$this->_showTypeDetails($r));
// $this->_writeDebug('Evaluating '.self::_localeFunc($functionName).'( '.$this->_showValue($args).' )');
// $r = call_user_func_array($functionCall,$args);
// $this->_writeDebug('Evaluation Result for '.self::_localeFunc($functionName).'() function call is '.$this->_showTypeDetails($r));
// Process the argument with the appropriate function call
if ($passCellReference) {
if (strpos($functionCall,'::') !== false) {
foreach($args as &$arg) {
if ($functionName != 'MKMATRIX') {
$this->_writeDebug('Evaluation Result for '. self::_localeFunc($functionName). '() function call is '. $this->_showTypeDetails($result));
$stack->push('Value',self::_wrapResult($result));
// if the token is a number, boolean, string or an Excel error, push it onto the stack
if (isset (self::$_ExcelConstants[strtoupper($token)])) {
// echo 'Token is a PHPExcel constant: '.$excelConstant.'<br />';
$stack->push('Constant Value',self::$_ExcelConstants[$excelConstant]);
$this->_writeDebug('Evaluating Constant '. $excelConstant. ' as '. $this->_showTypeDetails(self::$_ExcelConstants[$excelConstant]));
} elseif ((is_numeric($token)) || (is_null($token)) || (is_bool($token)) || ($token == '') || ($token{0} == '"') || ($token{0} == '#')) {
// echo 'Token is a number, boolean, string, null or an Excel error<br />';
$stack->push('Value',$token);
// if the token is a named range, push the named range name onto the stack
} elseif (preg_match('/^'. self::CALCULATION_REGEXP_NAMEDRANGE. '$/i', $token, $matches)) {
// echo 'Token is a named range<br />';
$namedRange = $matches[6];
// echo 'Named Range is '.$namedRange.'<br />';
$this->_writeDebug('Evaluating Named Range '. $namedRange);
$cellValue = $this->extractNamedRange($namedRange, ((null !== $pCell) ? $pCellParent : null), false);
$pCell->attach($pCellParent);
$this->_writeDebug('Evaluation Result for named range '. $namedRange. ' is '. $this->_showTypeDetails($cellValue));
$stack->push('Named Range',$cellValue,$namedRange);
// when we're out of tokens, the stack should have a single element, the final result
$output = $output['value'];
// if ((is_array($output)) && (self::$returnArrayAsType != self::RETURN_ARRAY_AS_ARRAY)) {
// return array_shift(PHPExcel_Calculation_Functions::flattenArray($output));
} // function _processTokenStack()
private function _validateBinaryOperand($cellID,&$operand,&$stack) {
// Numbers, matrices and booleans can pass straight through, as they're already valid
// We only need special validations for the operand if it is a string
// Start by stripping off the quotation marks we use to identify true excel string values internally
if ($operand > '' && $operand{0} == '"') { $operand = self::_unwrapResult($operand); }
// If the string is a numeric value, we treat it as a numeric, so no further testing
// If not a numeric, test to see if the value is an Excel error, and so can't be used in normal binary operations
if ($operand > '' && $operand{0} == '#') {
$stack->push('Value', $operand);
$this->_writeDebug('Evaluation Result is '. $this->_showTypeDetails($operand));
// If not a numeric or a fraction, then it's a text string, and so can't be used in mathematical binary operations
$stack->push('Value', '#VALUE!');
$this->_writeDebug('Evaluation Result is a '. $this->_showTypeDetails('#VALUE!'));
// return a true if the value of the operand is one that we can use in normal binary operations
} // function _validateBinaryOperand()
private function _executeBinaryComparisonOperation($cellID,$operand1,$operand2,$operation,&$stack,$recursingArrays= false) {
// If we're dealing with matrix operations, we want a matrix result
foreach($operand1 as $x => $operandData) {
$this->_writeDebug('Evaluating '. $this->_showValue($operandData). ' '. $operation. ' '. $this->_showValue($operand2));
$this->_executeBinaryComparisonOperation($cellID,$operandData,$operand2,$operation,$stack);
$result[$x] = $r['value'];
foreach($operand2 as $x => $operandData) {
$this->_writeDebug('Evaluating '. $this->_showValue($operand1). ' '. $operation. ' '. $this->_showValue($operandData));
$this->_executeBinaryComparisonOperation($cellID,$operand1,$operandData,$operation,$stack);
$result[$x] = $r['value'];
if (!$recursingArrays) { self::_checkMatrixOperands($operand1,$operand2,2); }
foreach($operand1 as $x => $operandData) {
$this->_writeDebug('Evaluating '. $this->_showValue($operandData). ' '. $operation. ' '. $this->_showValue($operand2[$x]));
$this->_executeBinaryComparisonOperation($cellID,$operandData,$operand2[$x],$operation,$stack,true);
$result[$x] = $r['value'];
// Log the result details
$this->_writeDebug('Evaluation Result is '. $this->_showTypeDetails($result));
// And push the result onto the stack
$stack->push('Array',$result);
// Simple validate the two operands if they are string values
if (is_string($operand1) && $operand1 > '' && $operand1{0} == '"') { $operand1 = self::_unwrapResult($operand1); }
if (is_string($operand2) && $operand2 > '' && $operand2{0} == '"') { $operand2 = self::_unwrapResult($operand2); }
// execute the necessary operation
$result = ($operand1 > $operand2);
$result = ($operand1 < $operand2);
$result = ($operand1 == $operand2);
$result = ($operand1 >= $operand2);
$result = ($operand1 <= $operand2);
$result = ($operand1 != $operand2);
// Log the result details
$this->_writeDebug('Evaluation Result is '. $this->_showTypeDetails($result));
// And push the result onto the stack
$stack->push('Value',$result);
} // function _executeBinaryComparisonOperation()
private function _executeNumericBinaryOperation($cellID,$operand1,$operand2,$operation,$matrixFunction,&$stack) {
// Validate the two operands
if (!$this->_validateBinaryOperand($cellID,$operand1,$stack)) return false;
if (!$this->_validateBinaryOperand($cellID,$operand2,$stack)) return false;
$executeMatrixOperation = false;
// If either of the operands is a matrix, we need to treat them both as matrices
// (converting the other operand to a matrix if need be); then perform the required
// Ensure that both operands are arrays/matrices
$executeMatrixOperation = true;
list ($mSize[],$mSize[],$mSize[],$mSize[]) = self::_checkMatrixOperands($operand1,$operand2,2);
// But if they're both single cell matrices, then we can treat them as simple values
$executeMatrixOperation = false;
$operand1 = $operand1[0][0];
$operand2 = $operand2[0][0];
if ($executeMatrixOperation) {
// Convert operand 1 from a PHP array to a matrix
// Perform the required operation against the operand 1 matrix, passing in operand 2
$matrixResult = $matrix->$matrixFunction($operand2);
$result = $matrixResult->getArray();
} catch (Exception $ex) {
$this->_writeDebug('JAMA Matrix Exception: '. $ex->getMessage());
// If we're dealing with non-matrix operations, execute the necessary operation
$result = $operand1+ $operand2;
$result = $operand1- $operand2;
$result = $operand1* $operand2;
// Trap for Divide by Zero error
$stack->push('Value','#DIV/0!');
$this->_writeDebug('Evaluation Result is '. $this->_showTypeDetails('#DIV/0!'));
$result = $operand1/ $operand2;
$result = pow($operand1,$operand2);
// Log the result details
$this->_writeDebug('Evaluation Result is '. $this->_showTypeDetails($result));
// And push the result onto the stack
$stack->push('Value',$result);
} // function _executeNumericBinaryOperation()
private function _writeDebug($message) {
// Only write the debug log if logging is enabled
echo implode(' -> ',$this->debugLogStack). ' -> '. $message,'<br />';
} // function _writeDebug()
// trigger an error, but nicely, if need be
} // function _raiseFormulaError()
* @param string &$pRange String based range representation
* @param PHPExcel_Worksheet $pSheet Worksheet
* @return mixed Array of values in range if range contains more than one element. Otherwise, a single value is returned.
public function extractCellRange(&$pRange = 'A1', PHPExcel_Worksheet $pSheet = null, $resetLog= true) {
// echo 'extractCellRange('.$pRange.')<br />';
// echo 'Passed sheet name is '.$pSheet->getTitle().'<br />';
// echo 'Range reference is '.$pRange.'<br />';
if (strpos ($pRange, '!') !== false) {
// echo '$pRange reference includes sheet reference<br />';
$pSheet = $pSheet->getParent()->getSheetByName($worksheetReference[0]);
// echo 'New sheet name is '.$pSheet->getTitle().'<br />';
$pRange = $worksheetReference[1];
// echo 'Adjusted Range reference is '.$pRange.'<br />';
$pRange = $pSheet->getTitle(). '!'. $pRange;
if (!isset ($aReferences[1])) {
list ($currentCol,$currentRow) = sscanf($aReferences[0],'%[A-Z]%d');
if ($pSheet->cellExists($aReferences[0])) {
$returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog);
$returnValue[$currentRow][$currentCol] = null;
// Extract cell data for all cells in the range
foreach ($aReferences as $reference) {
list ($currentCol,$currentRow) = sscanf($reference,'%[A-Z]%d');
if ($pSheet->cellExists($reference)) {
$returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog);
$returnValue[$currentRow][$currentCol] = null;
} // function extractCellRange()
* @param string &$pRange String based range representation
* @param PHPExcel_Worksheet $pSheet Worksheet
* @return mixed Array of values in range if range contains more than one element. Otherwise, a single value is returned.
public function extractNamedRange(&$pRange = 'A1', PHPExcel_Worksheet $pSheet = null, $resetLog= true) {
// echo 'extractNamedRange('.$pRange.')<br />';
// echo 'Current sheet name is '.$pSheet->getTitle().'<br />';
// echo 'Range reference is '.$pRange.'<br />';
if (strpos ($pRange, '!') !== false) {
// echo '$pRange reference includes sheet reference<br />';
$pSheet = $pSheet->getParent()->getSheetByName($worksheetReference[0]);
// echo 'New sheet name is '.$pSheet->getTitle().'<br />';
$pRange = $worksheetReference[1];
// echo 'Adjusted Range reference is '.$pRange.'<br />';
$pSheet = $namedRange->getWorksheet();
// echo 'Named Range '.$pRange.' (';
$pRange = $namedRange->getRange();
// Convert row and column references
$pRange = $splitRange[0][0] . '1:' . $splitRange[0][1] . $namedRange->getWorksheet()->getHighestRow();
$pRange = 'A' . $splitRange[0][0] . ':' . $namedRange->getWorksheet()->getHighestColumn() . $splitRange[0][1];
// echo $pRange.') is in sheet '.$namedRange->getWorksheet()->getTitle().'<br />';
// if ($pSheet->getTitle() != $namedRange->getWorksheet()->getTitle()) {
// if (!$namedRange->getLocalOnly()) {
// $pSheet = $namedRange->getWorksheet();
// var_dump($aReferences);
if (!isset ($aReferences[1])) {
// Single cell (or single column or row) in range
if ($pSheet->cellExists($aReferences[0])) {
$returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog);
$returnValue[$currentRow][$currentCol] = null;
// Extract cell data for all cells in the range
foreach ($aReferences as $reference) {
// echo 'NAMED RANGE: $currentCol='.$currentCol.' $currentRow='.$currentRow.'<br />';
if ($pSheet->cellExists($reference)) {
$returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog);
$returnValue[$currentRow][$currentCol] = null;
// print_r($returnValue);
} // function extractNamedRange()
* Is a specific function implemented?
* @param string $pFunction Function Name
if (isset (self::$_PHPExcelFunctions[$pFunction])) {
return (self::$_PHPExcelFunctions[$pFunction]['functionCall'] != 'PHPExcel_Calculation_Functions::DUMMY');
} // function isImplemented()
* Get a list of all implemented functions as an array of function objects
* @return array of PHPExcel_Calculation_Function
foreach(self::$_PHPExcelFunctions as $functionName => $function) {
if ($function['functionCall'] != 'PHPExcel_Calculation_Functions::DUMMY') {
$returnValue[$functionName] = new PHPExcel_Calculation_Function($function['category'],
$function['functionCall']
} // function listFunctions()
* Get a list of all Excel function names
} // function listAllFunctionNames()
* Get a list of implemented Excel function names
public function listFunctionNames() {
foreach(self::$_PHPExcelFunctions as $functionName => $function) {
if ($function['functionCall'] != 'PHPExcel_Calculation_Functions::DUMMY') {
$returnValue[] = $functionName;
} // function listFunctionNames()
} // class PHPExcel_Calculation
private $_stack = array();
public function count() {
public function push($type,$value,$reference= null) {
$this->_stack[$this->_count++ ] = array('type' => $type,
'reference' => $reference
if ($type == 'Function') {
$localeFunction = PHPExcel_Calculation::_localeFunc($value);
if ($localeFunction != $value) {
$this->_stack[($this->_count - 1)]['localeValue'] = $localeFunction;
return $this->_stack[-- $this->_count];
public function last($n= 1) {
if ($this->_count- $n < 0) {
return $this->_stack[$this->_count- $n];
} // class PHPExcel_Token_Stack
|