Source for file Calculation.php
Documentation is available at Calculation.php
* Copyright (c) 2006 - 2009 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 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10
/** PHPExcel root directory */
define('PHPEXCEL_ROOT', dirname(__FILE__ ) . '/../');
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/JAMA/Matrix.php';
/** PHPExcel_Calculation_Function */
require_once PHPEXCEL_ROOT . 'PHPExcel/Calculation/Function.php';
/** PHPExcel_Calculation_Functions */
require_once PHPEXCEL_ROOT . 'PHPExcel/Calculation/Functions.php';
* PHPExcel_Calculation (Singleton)
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
const CALCULATION_REGEXP_NUMBER = '[-+]?\d*\.?\d+(e[-+]?\d+)?';
const CALCULATION_REGEXP_STRING = '"(?:[^"]|"")*"';
const CALCULATION_REGEXP_OPENBRACE = '\(';
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 = '(((\w*)|(\'.*\')|(\".*\"))!)?\$?([a-z]+)\$?(\d+)(:\$?([a-z]+)\$?(\d+))?';
const CALCULATION_REGEXP_NAMEDRANGE = '(((\w*)|(\'.*\')|(\".*\"))!)?([_A-Z][_A-Z0-9]*)';
const CALCULATION_REGEXP_ERROR = '\#[^!]+!';
const RETURN_ARRAY_AS_VALUE = 'value';
const RETURN_ARRAY_AS_ARRAY = 'array';
private static $returnArrayAsType = self::RETURN_ARRAY_AS_ARRAY;
* @var PHPExcel_Calculation
private static $_instance;
* Calculation cache enabled
* Calculation cache expiration time
* List of operators that can be used within formulae
private $_operators = array('+', '-', '*', '/', '^', '&', '%', '_', '>', '<', '=', '>=', '<=', '<>');
* List of binary operators (those that expect two operands)
private $_binaryOperators = array('+', '-', '*', '/', '^', '&', '>', '<', '=', '>=', '<=', '<>');
// Constant conversion from text name/value to actual (datatyped) value
'ABS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'ACCRINT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::ACCRINT',
'ACCRINTM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::CELL_ADDRESS',
'AMORDEGRC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'AMORLINC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'AND' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::REVERSE_ATAN2',
'ATANH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'atanh',
'AVEDEV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::AVEDEV',
'AVERAGE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::AVERAGE',
'AVERAGEA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::AVERAGEA',
'AVERAGEIF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'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_Functions::BESSELI',
'BESSELJ' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::BESSELJ',
'BESSELK' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::BESSELK',
'BESSELY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::BESSELY',
'BETADIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::BETADIST',
'BETAINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::BETAINV',
'BIN2DEC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::BINTODEC',
'BIN2HEX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::BINTOHEX',
'BIN2OCT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::BINTOOCT',
'BINOMDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::BINOMDIST',
'CEILING' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::CHARACTER',
'CHIDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::CHIDIST',
'CHIINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::CHOOSE',
'CLEAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::TRIMNONPRINTABLE',
'CODE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::ASCIICODE',
'COLUMN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_Functions::COLUMN',
'COLUMNS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'COMBIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::COMBIN',
'COMPLEX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::COMPLEX',
'CONCATENATE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::CONCATENATE',
'CONFIDENCE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::CONFIDENCE',
'CONVERT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::CONVERTUOM',
'CORREL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::COUNT',
'COUNTA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::COUNTA',
'COUNTBLANK' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::COUNTBLANK',
'COUNTIF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::DUMMY',
'COUPDAYS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'COUPDAYSNC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'COUPNCD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'COUPNUM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'COUPPCD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'COVAR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::COVAR',
'CRITBINOM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::CUMIPMT',
'CUMPRINC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::CUMPRINC',
'DATE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_Functions::DATE',
'DATEDIF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_Functions::DATEDIF',
'DATEVALUE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::DAYOFMONTH',
'DAYS360' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_Functions::DAYS360',
'DB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DB',
'DCOUNT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'DCOUNTA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'DDB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DDB',
'DEC2BIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::DECTOBIN',
'DEC2HEX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::DECTOHEX',
'DEC2OCT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::DECTOOCT',
'DEGREES' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'rad2deg',
'DELTA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::DELTA',
'DEVSQ' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DEVSQ',
'DGET' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'DISC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DISC',
'DMAX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'DMIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'DOLLAR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::DOLLAR',
'DOLLARDE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DOLLARDE',
'DOLLARFR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DOLLARFR',
'DPRODUCT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'DSTDEV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'DSTDEVP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'DSUM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'DURATION' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'DVAR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'DVARP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'EDATE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_Functions::EDATE',
'EFFECT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::EFFECT',
'EOMONTH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_Functions::EOMONTH',
'ERF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::ERF',
'ERFC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::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_Functions::EXPONDIST',
'FACT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::FACT',
'FACTDOUBLE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::FACTDOUBLE',
'FALSE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::SEARCHSENSITIVE',
'FINDB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::FISHER',
'FISHERINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::FISHERINV',
'FIXED' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::FIXEDFORMAT',
'FLOOR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::FLOOR',
'FORECAST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::FV',
'FVSCHEDULE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'GAMMADIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::GAMMADIST',
'GAMMAINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::GAMMAINV',
'GAMMALN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::GAMMALN',
'GCD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::GCD',
'GEOMEAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::GEOMEAN',
'GESTEP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::GROWTH',
'HARMEAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::HARMEAN',
'HEX2BIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::HEXTOBIN',
'HEX2DEC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::HEXTODEC',
'HEX2OCT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::HOUROFDAY',
'HYPERLINK' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'HYPGEOMDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::HYPGEOMDIST',
'IF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::STATEMENT_IF',
'IFERROR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::STATEMENT_IFERROR',
'IMABS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::IMABS',
'IMAGINARY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::IMAGINARY',
'IMARGUMENT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::IMARGUMENT',
'IMCONJUGATE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::IMCONJUGATE',
'IMCOS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::IMCOS',
'IMDIV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::IMDIV',
'IMEXP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::IMEXP',
'IMLN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::IMLN',
'IMLOG10' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::IMLOG10',
'IMLOG2' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::IMLOG2',
'IMPOWER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::IMPOWER',
'IMPRODUCT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::IMPRODUCT',
'IMREAL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::IMREAL',
'IMSIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::IMSIN',
'IMSQRT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::IMSQRT',
'IMSUB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::IMSUB',
'IMSUM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::IMSUM',
'INDEX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_Functions::INDEX',
'INDIRECT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'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_Functions::INTVALUE',
'INTERCEPT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::INTERCEPT',
'INTRATE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::INTRATE',
'IPMT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::IPMT',
'IRR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'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_Functions::DUMMY',
'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_Functions::KURT',
'LARGE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::LARGE',
'LCM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::LCM',
'LEFT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::LEFT',
'LEFTB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::LEFT',
'LEN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::STRINGLENGTH',
'LENB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::STRINGLENGTH',
'LINEST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::LINEST',
'LN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'LOG' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::LOGEST',
'LOGINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::LOGINV',
'LOGNORMDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::LOGNORMDIST',
'LOOKUP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_Functions::LOOKUP',
'LOWER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::LOWERCASE',
'MATCH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_Functions::MATCH',
'MAX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::MAX',
'MAXA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::MAXA',
'MDETERM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::MEDIAN',
'MID' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::MID',
'MIDB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::MID',
'MIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::MIN',
'MINA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::MINA',
'MINUTE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_Functions::MINUTEOFHOUR',
'MINVERSE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::MINVERSE',
'MIRR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'MMULT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::MMULT',
'MOD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::MOD',
'MODE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::MODE',
'MONTH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_Functions::MONTHOFYEAR',
'MROUND' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::MROUND',
'MULTINOMIAL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::MULTINOMIAL',
'N' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'NA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
'functionCall' => 'PHPExcel_Calculation_Functions::NA',
'NEGBINOMDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::NEGBINOMDIST',
'NETWORKDAYS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_Functions::NETWORKDAYS',
'NOMINAL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::NOMINAL',
'NORMDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::NORMDIST',
'NORMINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::NORMINV',
'NORMSDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::NORMSDIST',
'NORMSINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::NORMSINV',
'NOT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::LOGICAL_NOT',
'NOW' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_Functions::DATETIMENOW',
'NPER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::NPER',
'NPV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::NPV',
'OCT2BIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::OCTTOBIN',
'OCT2DEC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::OCTTODEC',
'OCT2HEX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
'functionCall' => 'PHPExcel_Calculation_Functions::OCTTOHEX',
'ODD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::OFFSET',
'OR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::LOGICAL_OR',
'PEARSON' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::CORREL',
'PERCENTILE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::PERCENTILE',
'PERCENTRANK' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::PERCENTRANK',
'PERMUT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::PMT',
'POISSON' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::POISSON',
'POWER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::POWER',
'PPMT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::PPMT',
'PRICE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'PRICEDISC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::PRICEDISC',
'PRICEMAT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::PRODUCT',
'PROPER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::PROPERCASE',
'PV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::PV',
'QUARTILE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::QUARTILE',
'QUOTIENT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::RAND',
'RANDBETWEEN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::RAND',
'RANK' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::RANK',
'RATE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'RECEIVED' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::RECEIVED',
'REPLACE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::REPLACE',
'REPLACEB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::RIGHT',
'RIGHTB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::RIGHT',
'ROMAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::ROUNDDOWN',
'ROUNDUP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::ROUNDUP',
'ROW' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_Functions::ROW',
'ROWS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'RSQ' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::SEARCHINSENSITIVE',
'SEARCHB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::SEARCHINSENSITIVE',
'SECOND' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_Functions::SECONDOFMINUTE',
'SERIESSUM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::SERIESSUM',
'SIGN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::SKEW',
'SLN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::SLN',
'SLOPE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::SLOPE',
'SMALL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::SQRTPI',
'STANDARDIZE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::STANDARDIZE',
'STDEV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::STDEV',
'STDEVA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::STDEVA',
'STDEVP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::STDEVP',
'STDEVPA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::STDEVPA',
'STEYX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::STEYX',
'SUBSTITUTE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'SUBTOTAL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::SUBTOTAL',
'SUM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::SUM',
'SUMIF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::DUMMY',
'SUMSQ' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::SUMSQ',
'SUMX2MY2' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::SUMX2MY2',
'SUMX2PY2' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::SUMX2PY2',
'SUMXMY2' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::SUMXMY2',
'SYD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::SYD',
'T' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::TBILLEQ',
'TBILLPRICE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::TBILLPRICE',
'TBILLYIELD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::TBILLYIELD',
'TDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::TDIST',
'TEXT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::TEXTFORMAT',
'TIME' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_Functions::TIME',
'TIMEVALUE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_Functions::TIMEVALUE',
'TINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::TINV',
'TODAY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_Functions::DATENOW',
'TRANSPOSE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
'functionCall' => 'PHPExcel_Calculation_Functions::TRANSPOSE',
'TREND' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::TREND',
'TRIM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::TRIMSPACES',
'TRIMMEAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::TRIMMEAN',
'TRUE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::LOGICAL_TRUE',
'TRUNC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
'functionCall' => 'PHPExcel_Calculation_Functions::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::DUMMY',
'UPPER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::VARFunc',
'VARA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::VARA',
'VARP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::VARP',
'VARPA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::VLOOKUP',
'WEEKDAY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_Functions::DAYOFWEEK',
'WEEKNUM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_Functions::WEEKOFYEAR',
'WEIBULL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::WEIBULL',
'WORKDAY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_Functions::WORKDAY',
'XIRR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'XNPV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'YEAR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_Functions::YEAR',
'YEARFRAC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
'functionCall' => 'PHPExcel_Calculation_Functions::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_Functions::YIELDDISC',
'YIELDMAT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
'functionCall' => 'PHPExcel_Calculation_Functions::YIELDMAT',
'ZTEST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
// Internal functions used for special control purposes
'MKMATRIX' => array('argumentCount' => '*',
'functionCall' => array('self','_mkMatrix')
* Get an instance of this class
* @return PHPExcel_Calculation
if (!isset (self::$_instance) || is_null(self::$_instance)) {
self::$_instance = new PHPExcel_Calculation();
} // function getInstance()
* __clone implementation. Cloning should not be allowed in a Singleton!
throw new Exception ( 'Cloning a Singleton is not allowed!' );
* 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_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?
} // function getCalculationCacheEnabled()
* Enable/disable calculation cache
} // function setCalculationCacheEnabled()
* Enable calculation cache
} // function enableCalculationCache()
* Disable calculation cache
} // function disableCalculationCache()
* Clear calculation cache
} // function clearCalculationCache()
* Get calculation cache expiration time
} // getCalculationCacheExpirationTime()
* Set calculation cache expiration time
} // function setCalculationCacheExpirationTime()
* 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 ((strlen($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) {
} // 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
// Read the formula from the cell
$formula = $pCell->getValue();
$cellID = $pCell->getCoordinate();
// Execute the calculation for the cell formula
} // 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 ($formula{0} != '=') return array();
$formulaLength = strlen($formula);
if ($formulaLength < 1) return array();
// Parse the formula and return the token stack
} // 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
// Disable calculation cacheing because it only applies to cell calculations, not straight formulae
// But don't actually flush any cache
// Execute the calculation
// Reset calculation cacheing to its previous state
} // 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);
$formulaLength = strlen($formula);
if ($formulaLength < 1) return self::_wrapResult($formula);
// Is calculation cacheing enabled?
// Is the value present in calculation cache?
// echo 'Testing cache value<br />';
if (isset ($this->_calculationCache[$pCell->getParent()->getTitle()][$pCell->getCoordinate()])) {
// echo 'Value is in cache<br />';
// echo 'Cache time is still valid<br />';
$this->_writeDebug($cellID,'Retrieving value from cache');
// Return the cached result
$returnValue = $this->_calculationCache[$pCell->getParent()->getTitle()][$pCell->getCoordinate()]['data'];
// echo 'Retrieving data value of '.$returnValue.' for '.$pCell->getCoordinate().' from cache<br />';
// echo 'Cache has expired<br />';
// Clear the cache if it's no longer valid
unset ($this->_calculationCache[$pCell->getParent()->getTitle()][$pCell->getCoordinate()]);
// Parse the formula onto the token stack and calculate the value
// Save to calculation cache
$this->_calculationCache[$pCell->getParent()->getTitle()][$pCell->getCoordinate()]['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
// 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
list ($matrixRows,$matrixColumns) = self::_getMatrixDimensions($operand2);
list ($matrixRows,$matrixColumns) = self::_getMatrixDimensions($operand1);
// Given two matrices of (potentially) unequal size, convert the smaller in each dimension to match the larger
self::_resizeMatricesExtend($operand1,$operand2);
} elseif ($resize == 1) {
self::_resizeMatricesShrink($operand1,$operand2);
} // function _checkMatrixOperands()
* Re-index a matrix with straight numeric keys starting from row 0, column 0
* @param mixed $matrix matrix operand
* @return array The re-indexed matrix
foreach($matrix as $rowKey => $rowValue) {
} // function _getMatrixDimensions()
* 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) {
$colCount = count($rowValue);
if ($colCount > $matrixColumns) {
$matrixColumns = $colCount;
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
list ($matrix1Rows,$matrix1Columns) = self::_getMatrixDimensions($matrix1);
list ($matrix2Rows,$matrix2Columns) = self::_getMatrixDimensions($matrix2);
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
list ($matrix1Rows,$matrix1Columns) = self::_getMatrixDimensions($matrix1);
list ($matrix2Rows,$matrix2Columns) = self::_getMatrixDimensions($matrix2);
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
foreach($value as $row) {
if ($i > 0) { $retVal .= '; '; }
foreach($row as $column) {
if ($j > 0) { $retVal .= ', '; }
if ($i > 0) { $retVal .= ', '; }
return '{ '. $retVal. ' }';
return ($value) ? 'TRUE' : '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
$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 '. self::_showValue($value);
} // function _showTypeDetails()
static $matrixReplaceFrom = array('{',';','}');
static $matrixReplaceTo = array('MKMATRIX(MKMATRIX(','),MKMATRIX(','))');
// Convert any Excel matrix references to the MKMATRIX() function
if (strpos($formula,'{') !== false) {
// Open and Closed counts used for trapping mismatched braces in the formula
$openCount = $closeCount = 0;
// 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);
foreach($temp as &$value) {
// Only count/replace in alternate 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()
} // function _mkMatrix()
// Convert infix to postfix notation
if (($formula = self::_convertMatrixReferences(trim($formula))) === false) {
// 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
'&' => 1, // Concatenation
'>' => 0, '<' => 0, '=' => 0, '>=' => 0, '<=' => 0, '<>' => 0 // Comparison
// Comparison (Boolean) Operators
// These operators work on two values, but always return a boolean result
$comparisonOperators = array('>', '<', '=', '>=', '<=', '<>');
// 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('_' => 6, // Negation
'^' => 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.
// 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 ((in_array($opCharacter, $comparisonOperators)) && (strlen($formula) > $index) && (in_array($formula{$index+ 1}, $comparisonOperators))) {
$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('_'); // Put a negation on the stack
++ $index; // and drop the negation symbol
} elseif ($opCharacter == '%' && $expectingOperator) {
// echo 'Element is a Percentage operator<br />';
$stack->push('%'); // Put a percentage on the stack
} elseif ($opCharacter == '+' && !$expectingOperator) { // Positive (rather than plus) can be discarded?
// echo 'Element is a Positive number, not Plus operator<br />';
++ $index; // Drop the redundant plus symbol
} elseif (($opCharacter == '_') && (!$isOperandOrFunction)) { // We have to explicitly deny an underscore, because it's legal on
return $this->_raiseFormulaError("Formula Error: Illegal character '_'"); // the stack but not in the input expression
// Note that _ is a valid first character in named ranges
// and this will need modifying soon when we start integrating
} elseif ((in_array($opCharacter, $this->_operators) 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()) &&
($operatorAssociativity[$opCharacter] ? $operatorPrecedence[$opCharacter] < $operatorPrecedence[$o2] : $operatorPrecedence[$opCharacter] <= $operatorPrecedence[$o2])) {
$output[] = $stack->pop(); // Swap operands and higher precedence operators from the stack to the output
$stack->push($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()) != '(') { // Pop off the stack back to the last (
if (preg_match('/^'. self::CALCULATION_REGEXP_FUNCTION. '$/i', $stack->last(2), $matches)) { // Did this parenthesis just close a function?
$functionName = $matches[1]; // Get the function name
// echo 'Closed Function is '.$functionName.'<br />';
$argumentCount = $stack->pop(); // 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[] = $argumentCount; // Dump the argument count on the output
$output[] = $stack->pop(); // Pop the function and push onto the output
// echo 'Built-in function '.$functionName.'<br />';
// echo 'PHPExcel function '.$functionName.'<br />';
} else { // did we somehow push a non-function on the stack? this should never happen
// 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 comma separator for function arguments?
// echo 'Element is a Function argument separator<br />';
while (($o2 = $stack->pop()) != '(') {
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)) {
// make sure there was a function
if (!preg_match('/^'. self::CALCULATION_REGEXP_FUNCTION. '$/i', $stack->last(2), $matches))
$stack->push($stack->pop()+ 1); // increment the argument count
$stack->push('('); // 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 />';
} 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 />';
$expectingOperator = true;
$expectingOperator = false;
} else { // it's a var w/ implicit multiplication
} 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
// $cellRef = strtoupper($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 ($opCharacter == '"') {
// echo 'Element is a String<br />';
// echo 'Element is a Number<br />';
if ((strpos($val,'.') !== False) || (stripos($val,'e') !== False)) {
// echo 'Casting '.$val.' to float<br />';
// echo 'Casting '.$val.' to integer<br />';
// } elseif (array_key_exists(trim(strtoupper($val)), $this->_ExcelConstants)) {
// $excelConstant = trim(strtoupper($val));
// echo 'Element '.$val.' is an Excel Constant<br />';
// $val = $this->_ExcelConstants[$excelConstant];
} elseif ($opCharacter == ')') { // miscellaneous error checking
$expectingOperand = false;
$expectingOperator = True;
} 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
return $this->_raiseFormulaError("Formula Error: Operator '$opCharacter' has no operands");
while (substr($formula, $index, 1) == ' ') {
while (!is_null($opCharacter = $stack->pop())) { // pop everything off the stack and push onto output
if ($opCharacter == '(') return $this->_raiseFormulaError("Formula Error: Expecting ')'"); // if there are any opening braces on the stack, then braces were unbalanced
$output[] = $opCharacter;
} // function _parseFormula()
// evaluate postfix notation
if ($tokens == false) return false;
// Loop through each token in turn
foreach ($tokens as $token) {
// 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
// echo 'Token is a binary operator<br />';
// We must have two operands, error if we don't
if (is_null($operand2 = $stack->pop())) return $this->_raiseFormulaError('Internal error - Operand value missing from stack');
if (is_null($operand1 = $stack->pop())) return $this->_raiseFormulaError('Internal error - Operand value missing from stack');
$this->_writeDebug($cellID,'Evaluating '. self::_showValue($operand1). ' '. $token. ' '. self::_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
case '-' : // Subtraction
case '*' : // Multiplication
case '^' : // Exponential
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
// Ensure that both operands are arrays/matrices
self::_checkMatrixOperands($operand1,$operand2);
// Convert operand 1 from a PHP array to a matrix
$matrix = new Matrix($operand1);
// 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($cellID,'JAMA Matrix Exception: '. $ex->getMessage());
$result = '"'. str_replace('""','"',self::_unwrapResult($operand1,'"'). self::_unwrapResult($operand2,'"')). '"';
$this->_writeDebug($cellID,'Evaluation Result is '. self::_showTypeDetails($result));
// 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($cellID,'Evaluating Negation of '. self::_showValue($arg));
// echo 'Token is a percentile operator<br />';
$this->_writeDebug($cellID,'Evaluating Percentile of '. self::_showValue($arg));
self::_checkMatrixOperands($arg,$multiplier);
$matrixResult = $matrix1->arrayTimesEquals($multiplier);
$result = $matrixResult->getArray();
} catch (Exception $ex) {
$this->_writeDebug($cellID,'JAMA Matrix Exception: '. $ex->getMessage());
$result = $multiplier * $arg;
$this->_writeDebug($cellID,'Evaluation Result is '. self::_showTypeDetails($result));
} 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];
// echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'<br />';
$this->_writeDebug($cellID,'Evaluating Cell Range '. $cellRef. ' in worksheet '. $matches[2]);
$cellValue = $this->extractCellRange($cellRef, $pCell->getParent()->getParent()->getSheetByName($matches[2]), false);
$this->_writeDebug($cellID,'Evaluation Result for cells '. $cellRef. ' in worksheet '. $matches[2]. ' is '. self::_showTypeDetails($cellValue));
// echo '$cellRef='.$cellRef.' in current worksheet<br />';
$this->_writeDebug($cellID,'Evaluating Cell Range '. $cellRef. ' in current worksheet');
$this->_writeDebug($cellID,'Evaluation Result for cells '. $cellRef. ' is '. self::_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];
// echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'<br />';
$this->_writeDebug($cellID,'Evaluating Cell '. $cellRef. ' in worksheet '. $matches[2]);
if ($pCell->getParent()->cellExists($cellRef)) {
$cellValue = $this->extractCellRange($cellRef, $pCell->getParent()->getParent()->getSheetByName($matches[2]), false);
$this->_writeDebug($cellID,'Evaluation Result for cell '. $cellRef. ' in worksheet '. $matches[2]. ' is '. self::_showTypeDetails($cellValue));
// echo '$cellRef='.$cellRef.' in current worksheet<br />';
$this->_writeDebug($cellID,'Evaluating Cell '. $cellRef. ' in current worksheet');
if ($pCell->getParent()->cellExists($cellRef)) {
$cellValue = $pCell->getParent()->getCell($cellRef)->getCalculatedValue(false);
$this->_writeDebug($cellID,'Evaluation Result for cell '. $cellRef. ' is '. self::_showTypeDetails($cellValue));
$stack->push($cellValue);
// 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();
if ($functionName != 'MKMATRIX') {
$this->_writeDebug($cellID,'Evaluating Function '. $functionName. '() with '. (($argCount == 0) ? 'no' : $argCount). ' argument'. (($argCount == 1) ? '' : 's'));
// get the arguments for this function
// echo 'Function '.$functionName.' expects '.$argCount.' arguments<br />';
for ($i = $argCount; $i > 0; -- $i) {
// if (is_null($arg)) return $this->_raiseFormulaError("internal error");
// Reverse the order of the arguments
// echo 'Arguments are: ';
if ($functionName != 'MKMATRIX') {
foreach($args as &$arg) {
$argArrayVals[] = self::_showValue($arg);
$arg = self::_unwrapResult($arg);
$this->_writeDebug($cellID,'Evaluating '. $functionName. '( '. implode(', ',$argArrayVals). ' )');
// Process each argument in turn, building the return value as an array
// if (($argCount == 1) && (is_array($args[1])) && ($functionName != 'MKMATRIX')) {
// $this->_writeDebug($cellID,'Argument is a matrix: '.self::_showValue($operand1));
// foreach($operand1 as $args) {
// if (is_array($args)) {
// foreach($args as $arg) {
// $this->_writeDebug($cellID,'Evaluating '. $functionName.'( '.self::_showValue($arg).' )');
// $r = call_user_func_array($functionCall,$arg);
// $this->_writeDebug($cellID,'Evaluation Result is '.self::_showTypeDetails($r));
// $this->_writeDebug($cellID,'Evaluating '. $functionName.'( '.self::_showValue($args).' )');
// $r = call_user_func_array($functionCall,$args);
// $this->_writeDebug($cellID,'Evaluation Result is '.self::_showTypeDetails($r));
// Process the argument with the appropriate function call
if ($functionName != 'MKMATRIX') {
$this->_writeDebug($cellID,'Evaluation Result is '. self::_showTypeDetails($result));
$stack->push(self::_wrapResult($result));
// if the token is a number, boolean, string or an Excel error, push it onto the stack
// echo 'Token is a PHPExcel constant: '.$excelConstant.'<br />';
$this->_writeDebug($cellID,'Evaluating Constant '. $excelConstant. ' as '. self::_showTypeDetails($this->_ExcelConstants[$excelConstant]));
} elseif ((is_null($token)) || ($token == '') || (is_bool($token)) || (is_numeric($token)) || ($token{0} == '"') || ($token{0} == '#')) {
// echo 'Token is a number, boolean, string or an Excel error<br />';
// if the token is a constant, push the constant value on 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($cellID,'Evaluating Named Range '. $namedRange);
$this->_writeDebug($cellID,'Evaluation Result for named range '. $namedRange. ' is '. self::_showTypeDetails($cellValue));
$stack->push($cellValue);
// when we're out of tokens, the stack should have a single element, the final result
if ((is_array($output)) && (self::$returnArrayAsType != self::RETURN_ARRAY_AS_ARRAY)) {
} // function _processTokenStack()
// 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} == '#') {
$this->_writeDebug($cellID,'Evaluation Result is '. self::_showTypeDetails($operand));
// If not a numeric, then it's a text string, and so can't be used in mathematical binary operations
$this->_writeDebug($cellID,'Evaluation Result is a '. self::_showTypeDetails('#VALUE!'));
// return a true if the value of the operand is one that we can use in normal binary operations
} // function _validateBinaryOperand()
// Validate the two operands
// If we're dealing with non-matrix operations, 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($cellID,'Evaluation Result is '. self::_showTypeDetails($result));
// And push the result onto the stack
} // function _executeBinaryComparisonOperation()
// Validate the two operands
// 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
self::_checkMatrixOperands($operand1,$operand2);
// Convert operand 1 from a PHP array to a matrix
$matrix = new Matrix($operand1);
// 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($cellID,'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
$this->_writeDebug($cellID,'Evaluation Result is '. self::_showTypeDetails('#DIV/0!'));
$result = $operand1/ $operand2;
$result = pow($operand1,$operand2);
// Log the result details
$this->_writeDebug($cellID,'Evaluation Result is '. self::_showTypeDetails($result));
// And push the result onto the stack
} // function _executeNumericBinaryOperation()
// Only write the debug log if logging is enabled
// $prefix = substr(implode(' -> ',$this->debugLogStack).' -> ',4+strlen($this->debugLogStack[0]));
} // 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) {
$returnValue = array ( );
// echo 'extractCellRange('.$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 />';
if (count($aReferences) == 1) {
return $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog);
foreach ($aReferences as $reference) {
$returnValue[$currentCol][$currentRow] = $pSheet->getCell($reference)->getCalculatedValue($resetLog);
} // 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) {
$returnValue = array ( );
// 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 />';
// echo 'Named Range '.$pRange.' (';
$pRange = $namedRange->getRange();
// echo $pRange.') is in sheet '.$namedRange->getWorksheet()->getTitle().'<br />';
if ($pSheet->getTitle() != $namedRange->getWorksheet()->getTitle()) {
if (!$namedRange->getLocalOnly()) {
$pSheet = $namedRange->getWorksheet();
if (count($aReferences) == 1) {
return $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog);
foreach ($aReferences as $reference) {
// echo 'NAMED RANGE: $currentCol='.$currentCol.' $currentRow='.$currentRow.'<br />';
$returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog);
// print_r($returnValue);
foreach($returnValue as &$rr) {
// print_r($returnValue);
} // function extractNamedRange()
* Is a specific function implemented?
* @param string $pFunction Function Name
return ($this->_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
if ($function['functionCall'] != 'PHPExcel_Calculation_Functions::DUMMY') {
$function['functionCall']
} // function listFunctions()
* Get a list of implemented Excel function names
$returnValue[] = $functionName;
} // function listFunctionNames()
} // class PHPExcel_Calculation
public function count() {
public function push($value) {
public function last($n= 1) {
} // class PHPExcel_Token_Stack
|