PHPExcel_Calculation
[ class tree: PHPExcel_Calculation ] [ index: PHPExcel_Calculation ] [ all elements ]

Source for file Calculation.php

Documentation is available at Calculation.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2009 PHPExcel
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  * @category   PHPExcel
  22.  * @package    PHPExcel_Calculation
  23.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.7.0, 2009-08-10
  26.  */
  27.  
  28.  
  29. /** PHPExcel root directory */
  30. if (!defined('PHPEXCEL_ROOT')) {
  31.     /**
  32.      * @ignore
  33.      */
  34.     define('PHPEXCEL_ROOT'dirname(__FILE__'/../');
  35. }
  36.  
  37. /** Matrix */
  38. require_once PHPEXCEL_ROOT 'PHPExcel/Shared/JAMA/Matrix.php';
  39.  
  40. /** PHPExcel_Calculation_Function */
  41. require_once PHPEXCEL_ROOT 'PHPExcel/Calculation/Function.php';
  42.  
  43. /** PHPExcel_Calculation_Functions */
  44. require_once PHPEXCEL_ROOT 'PHPExcel/Calculation/Functions.php';
  45.  
  46.  
  47. /**
  48.  * PHPExcel_Calculation (Singleton)
  49.  *
  50.  * @category   PHPExcel
  51.  * @package    PHPExcel_Calculation
  52.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  53.  */
  54.  
  55.     /**    Constants                */
  56.             const CALCULATION_REGEXP_NUMBER        '[-+]?\d*\.?\d+(e[-+]?\d+)?';
  57.     //    String operand
  58.     const CALCULATION_REGEXP_STRING        '"(?:[^"]|"")*"';
  59.     //    Opening bracket
  60.     const CALCULATION_REGEXP_OPENBRACE    '\(';
  61.     //    Function
  62.     const CALCULATION_REGEXP_FUNCTION    '([A-Z][A-Z0-9\.]*)[\s]*\(';
  63.     //    Cell reference (cell or range of cells, with or without a sheet reference)
  64.     const CALCULATION_REGEXP_CELLREF    '(((\w*)|(\'.*\')|(\".*\"))!)?\$?([a-z]+)\$?(\d+)(:\$?([a-z]+)\$?(\d+))?';
  65.     //    Named Range of cells
  66.     const CALCULATION_REGEXP_NAMEDRANGE    '(((\w*)|(\'.*\')|(\".*\"))!)?([_A-Z][_A-Z0-9]*)';
  67.     //    Error
  68.     const CALCULATION_REGEXP_ERROR        '\#[^!]+!';
  69.  
  70.  
  71.     /** constants */
  72.     const RETURN_ARRAY_AS_VALUE 'value';
  73.     const RETURN_ARRAY_AS_ARRAY 'array';
  74.  
  75.     private static $returnArrayAsType    self::RETURN_ARRAY_AS_ARRAY;
  76.  
  77.     /**
  78.      *    Instance of this class
  79.      *
  80.      *    @access    private
  81.      *    @var PHPExcel_Calculation 
  82.      */
  83.     private static $_instance;
  84.  
  85.  
  86.     /**
  87.      *    Calculation cache
  88.      *
  89.      *    @access    private
  90.      *    @var array 
  91.      */
  92.     private $_calculationCache = array ();
  93.  
  94.  
  95.     /**
  96.      *    Calculation cache enabled
  97.      *
  98.      *    @access    private
  99.      *    @var boolean 
  100.      */
  101.     private $_calculationCacheEnabled = true;
  102.  
  103.  
  104.     /**
  105.      *    Calculation cache expiration time
  106.      *
  107.      *    @access    private
  108.      *    @var float 
  109.      */
  110.     private $_calculationCacheExpirationTime = 0.01;
  111.  
  112.  
  113.     /**
  114.      *    List of operators that can be used within formulae
  115.      *
  116.      *    @access    private
  117.      *    @var array 
  118.      */
  119.     private $_operators            = array('+''-''*''/''^''&''%''_''>''<''=''>=''<=''<>');
  120.  
  121.  
  122.     /**
  123.      *    List of binary operators (those that expect two operands)
  124.      *
  125.      *    @access    private
  126.      *    @var array 
  127.      */
  128.     private $_binaryOperators    = array('+''-''*''/''^''&''>''<''=''>=''<=''<>');
  129.  
  130.     public $suppressFormulaErrors = false;
  131.     public $formulaError = null;
  132.     public $writeDebugLog = false;
  133.     private $debugLogStack = array();
  134.     public $debugLog = array();
  135.  
  136.  
  137.     //    Constant conversion from text name/value to actual (datatyped) value
  138.     private $_ExcelConstants = array('TRUE'        => True,
  139.                                      'FALSE'    => False,
  140.                                      'NULL'        => Null
  141.                                     );
  142.  
  143.     //    PHPExcel functions
  144.     private $_PHPExcelFunctions = array(    // PHPExcel functions
  145.                 'ABS'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  146.                                                  'functionCall'        =>    'abs',
  147.                                                  'argumentCount'    =>    '1'
  148.                                                 ),
  149.                 'ACCRINT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  150.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::ACCRINT',
  151.                                                  'argumentCount'    =>    '4-7'
  152.                                                 ),
  153.                 'ACCRINTM'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  154.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::ACCRINTM',
  155.                                                  'argumentCount'    =>    '3-5'
  156.                                                 ),
  157.                 'ACOS'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  158.                                                  'functionCall'        =>    'acos',
  159.                                                  'argumentCount'    =>    '1'
  160.                                                 ),
  161.                 'ACOSH'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  162.                                                  'functionCall'        =>    'acosh',
  163.                                                  'argumentCount'    =>    '1'
  164.                                                 ),
  165.                 'ADDRESS'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
  166.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::CELL_ADDRESS',
  167.                                                  'argumentCount'    =>    '2-5'
  168.                                                 ),
  169.                 'AMORDEGRC'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  170.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  171.                                                  'argumentCount'    =>    '6,7'
  172.                                                 ),
  173.                 'AMORLINC'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  174.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  175.                                                  'argumentCount'    =>    '6,7'
  176.                                                 ),
  177.                 'AND'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
  178.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::LOGICAL_AND',
  179.                                                  'argumentCount'    =>    '1+'
  180.                                                 ),
  181.                 'AREAS'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
  182.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  183.                                                  'argumentCount'    =>    '1'
  184.                                                 ),
  185.                 'ASC'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  186.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  187.                                                  'argumentCount'    =>    '1'
  188.                                                 ),
  189.                 'ASIN'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  190.                                                  'functionCall'        =>    'asin',
  191.                                                  'argumentCount'    =>    '1'
  192.                                                 ),
  193.                 'ASINH'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  194.                                                  'functionCall'        =>    'asinh',
  195.                                                  'argumentCount'    =>    '1'
  196.                                                 ),
  197.                 'ATAN'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  198.                                                  'functionCall'        =>    'atan',
  199.                                                  'argumentCount'    =>    '1'
  200.                                                 ),
  201.                 'ATAN2'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  202.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::REVERSE_ATAN2',
  203.                                                  'argumentCount'    =>    '2'
  204.                                                 ),
  205.                 'ATANH'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  206.                                                  'functionCall'        =>    'atanh',
  207.                                                  'argumentCount'    =>    '1'
  208.                                                 ),
  209.                 'AVEDEV'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  210.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::AVEDEV',
  211.                                                  'argumentCount'    =>    '1+'
  212.                                                 ),
  213.                 'AVERAGE'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  214.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::AVERAGE',
  215.                                                  'argumentCount'    =>    '1+'
  216.                                                 ),
  217.                 'AVERAGEA'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  218.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::AVERAGEA',
  219.                                                  'argumentCount'    =>    '1+'
  220.                                                 ),
  221.                 'AVERAGEIF'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  222.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  223.                                                  'argumentCount'    =>    '2,3'
  224.                                                 ),
  225.                 'AVERAGEIFS'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  226.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  227.                                                  'argumentCount'    =>    '3+'
  228.                                                 ),
  229.                 'BAHTTEXT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  230.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  231.                                                  'argumentCount'    =>    '1'
  232.                                                 ),
  233.                 'BESSELI'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  234.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::BESSELI',
  235.                                                  'argumentCount'    =>    '2'
  236.                                                 ),
  237.                 'BESSELJ'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  238.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::BESSELJ',
  239.                                                  'argumentCount'    =>    '2'
  240.                                                 ),
  241.                 'BESSELK'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  242.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::BESSELK',
  243.                                                  'argumentCount'    =>    '2'
  244.                                                 ),
  245.                 'BESSELY'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  246.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::BESSELY',
  247.                                                  'argumentCount'    =>    '2'
  248.                                                 ),
  249.                 'BETADIST'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  250.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::BETADIST',
  251.                                                  'argumentCount'    =>    '3-5'
  252.                                                 ),
  253.                 'BETAINV'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  254.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::BETAINV',
  255.                                                  'argumentCount'    =>    '3-5'
  256.                                                 ),
  257.                 'BIN2DEC'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  258.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::BINTODEC',
  259.                                                  'argumentCount'    =>    '1'
  260.                                                 ),
  261.                 'BIN2HEX'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  262.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::BINTOHEX',
  263.                                                  'argumentCount'    =>    '1,2'
  264.                                                 ),
  265.                 'BIN2OCT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  266.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::BINTOOCT',
  267.                                                  'argumentCount'    =>    '1,2'
  268.                                                 ),
  269.                 'BINOMDIST'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  270.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::BINOMDIST',
  271.                                                  'argumentCount'    =>    '4'
  272.                                                 ),
  273.                 'CEILING'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  274.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::CEILING',
  275.                                                  'argumentCount'    =>    '2'
  276.                                                 ),
  277.                 'CELL'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
  278.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  279.                                                  'argumentCount'    =>    '1,2'
  280.                                                 ),
  281.                 'CHAR'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  282.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::CHARACTER',
  283.                                                  'argumentCount'    =>    '1'
  284.                                                 ),
  285.                 'CHIDIST'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  286.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::CHIDIST',
  287.                                                  'argumentCount'    =>    '2'
  288.                                                 ),
  289.                 'CHIINV'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  290.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::CHIINV',
  291.                                                  'argumentCount'    =>    '2'
  292.                                                 ),
  293.                 'CHITEST'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  294.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  295.                                                  'argumentCount'    =>    '2'
  296.                                                 ),
  297.                 'CHOOSE'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
  298.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::CHOOSE',
  299.                                                  'argumentCount'    =>    '2+'
  300.                                                 ),
  301.                 'CLEAN'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  302.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::TRIMNONPRINTABLE',
  303.                                                  'argumentCount'    =>    '1'
  304.                                                 ),
  305.                 'CODE'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  306.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::ASCIICODE',
  307.                                                  'argumentCount'    =>    '1'
  308.                                                 ),
  309.                 'COLUMN'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
  310.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::COLUMN',
  311.                                                  'argumentCount'    =>    '-1'
  312.                                                 ),
  313.                 'COLUMNS'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
  314.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  315.                                                  'argumentCount'    =>    '1'
  316.                                                 ),
  317.                 'COMBIN'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  318.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::COMBIN',
  319.                                                  'argumentCount'    =>    '2'
  320.                                                 ),
  321.                 'COMPLEX'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  322.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::COMPLEX',
  323.                                                  'argumentCount'    =>    '2,3'
  324.                                                 ),
  325.                 'CONCATENATE'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  326.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::CONCATENATE',
  327.                                                  'argumentCount'    =>    '1+'
  328.                                                 ),
  329.                 'CONFIDENCE'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  330.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::CONFIDENCE',
  331.                                                  'argumentCount'    =>    '3'
  332.                                                 ),
  333.                 'CONVERT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  334.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::CONVERTUOM',
  335.                                                  'argumentCount'    =>    '3'
  336.                                                 ),
  337.                 'CORREL'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  338.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::CORREL',
  339.                                                  'argumentCount'    =>    '2'
  340.                                                 ),
  341.                 'COS'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  342.                                                  'functionCall'        =>    'cos',
  343.                                                  'argumentCount'    =>    '1'
  344.                                                 ),
  345.                 'COSH'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  346.                                                  'functionCall'        =>    'cosh',
  347.                                                  'argumentCount'    =>    '1'
  348.                                                 ),
  349.                 'COUNT'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  350.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::COUNT',
  351.                                                  'argumentCount'    =>    '1+'
  352.                                                 ),
  353.                 'COUNTA'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  354.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::COUNTA',
  355.                                                  'argumentCount'    =>    '1+'
  356.                                                 ),
  357.                 'COUNTBLANK'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  358.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::COUNTBLANK',
  359.                                                  'argumentCount'    =>    '1'
  360.                                                 ),
  361.                 'COUNTIF'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  362.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::COUNTIF',
  363.                                                  'argumentCount'    =>    '2'
  364.                                                 ),
  365.                 'COUNTIFS'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  366.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  367.                                                  'argumentCount'    =>    '2'
  368.                                                 ),
  369.                 'COUPDAYBS'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  370.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  371.                                                  'argumentCount'    =>    '3,4'
  372.                                                 ),
  373.                 'COUPDAYS'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  374.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  375.                                                  'argumentCount'    =>    '3,4'
  376.                                                 ),
  377.                 'COUPDAYSNC'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  378.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  379.                                                  'argumentCount'    =>    '3,4'
  380.                                                 ),
  381.                 'COUPNCD'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  382.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  383.                                                  'argumentCount'    =>    '3,4'
  384.                                                 ),
  385.                 'COUPNUM'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  386.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  387.                                                  'argumentCount'    =>    '3,4'
  388.                                                 ),
  389.                 'COUPPCD'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  390.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  391.                                                  'argumentCount'    =>    '3,4'
  392.                                                 ),
  393.                 'COVAR'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  394.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::COVAR',
  395.                                                  'argumentCount'    =>    '2'
  396.                                                 ),
  397.                 'CRITBINOM'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  398.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::CRITBINOM',
  399.                                                  'argumentCount'    =>    '3'
  400.                                                 ),
  401.                 'CUBEKPIMEMBER'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_CUBE,
  402.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  403.                                                  'argumentCount'    =>    '?'
  404.                                                 ),
  405.                 'CUBEMEMBER'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_CUBE,
  406.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  407.                                                  'argumentCount'    =>    '?'
  408.                                                 ),
  409.                 'CUBEMEMBERPROPERTY'    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_CUBE,
  410.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  411.                                                  'argumentCount'    =>    '?'
  412.                                                 ),
  413.                 'CUBERANKEDMEMBER'        => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_CUBE,
  414.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  415.                                                  'argumentCount'    =>    '?'
  416.                                                 ),
  417.                 'CUBESET'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_CUBE,
  418.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  419.                                                  'argumentCount'    =>    '?'
  420.                                                 ),
  421.                 'CUBESETCOUNT'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_CUBE,
  422.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  423.                                                  'argumentCount'    =>    '?'
  424.                                                 ),
  425.                 'CUBEVALUE'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_CUBE,
  426.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  427.                                                  'argumentCount'    =>    '?'
  428.                                                 ),
  429.                 'CUMIPMT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  430.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::CUMIPMT',
  431.                                                  'argumentCount'    =>    '6'
  432.                                                 ),
  433.                 'CUMPRINC'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  434.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::CUMPRINC',
  435.                                                  'argumentCount'    =>    '6'
  436.                                                 ),
  437.                 'DATE'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  438.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DATE',
  439.                                                  'argumentCount'    =>    '3'
  440.                                                 ),
  441.                 'DATEDIF'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  442.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DATEDIF',
  443.                                                  'argumentCount'    =>    '3'
  444.                                                 ),
  445.                 'DATEVALUE'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  446.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DATEVALUE',
  447.                                                  'argumentCount'    =>    '1'
  448.                                                 ),
  449.                 'DAVERAGE'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATABASE,
  450.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  451.                                                  'argumentCount'    =>    '?'
  452.                                                 ),
  453.                 'DAY'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  454.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DAYOFMONTH',
  455.                                                  'argumentCount'    =>    '1'
  456.                                                 ),
  457.                 'DAYS360'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  458.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DAYS360',
  459.                                                  'argumentCount'    =>    '2,3'
  460.                                                 ),
  461.                 'DB'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  462.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DB',
  463.                                                  'argumentCount'    =>    '4,5'
  464.                                                 ),
  465.                 'DCOUNT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATABASE,
  466.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  467.                                                  'argumentCount'    =>    '?'
  468.                                                 ),
  469.                 'DCOUNTA'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATABASE,
  470.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  471.                                                  'argumentCount'    =>    '?'
  472.                                                 ),
  473.                 'DDB'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  474.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DDB',
  475.                                                  'argumentCount'    =>    '4,5'
  476.                                                 ),
  477.                 'DEC2BIN'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  478.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DECTOBIN',
  479.                                                  'argumentCount'    =>    '1,2'
  480.                                                 ),
  481.                 'DEC2HEX'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  482.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DECTOHEX',
  483.                                                  'argumentCount'    =>    '1,2'
  484.                                                 ),
  485.                 'DEC2OCT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  486.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DECTOOCT',
  487.                                                  'argumentCount'    =>    '1,2'
  488.                                                 ),
  489.                 'DEGREES'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  490.                                                  'functionCall'        =>    'rad2deg',
  491.                                                  'argumentCount'    =>    '1'
  492.                                                 ),
  493.                 'DELTA'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  494.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DELTA',
  495.                                                  'argumentCount'    =>    '1,2'
  496.                                                 ),
  497.                 'DEVSQ'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  498.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DEVSQ',
  499.                                                  'argumentCount'    =>    '1+'
  500.                                                 ),
  501.                 'DGET'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATABASE,
  502.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  503.                                                  'argumentCount'    =>    '?'
  504.                                                 ),
  505.                 'DISC'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  506.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DISC',
  507.                                                  'argumentCount'    =>    '4,5'
  508.                                                 ),
  509.                 'DMAX'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATABASE,
  510.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  511.                                                  'argumentCount'    =>    '?'
  512.                                                 ),
  513.                 'DMIN'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATABASE,
  514.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  515.                                                  'argumentCount'    =>    '?'
  516.                                                 ),
  517.                 'DOLLAR'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  518.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DOLLAR',
  519.                                                  'argumentCount'    =>    '1,2'
  520.                                                 ),
  521.                 'DOLLARDE'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  522.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DOLLARDE',
  523.                                                  'argumentCount'    =>    '2'
  524.                                                 ),
  525.                 'DOLLARFR'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  526.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DOLLARFR',
  527.                                                  'argumentCount'    =>    '2'
  528.                                                 ),
  529.                 'DPRODUCT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATABASE,
  530.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  531.                                                  'argumentCount'    =>    '?'
  532.                                                 ),
  533.                 'DSTDEV'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATABASE,
  534.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  535.                                                  'argumentCount'    =>    '?'
  536.                                                 ),
  537.                 'DSTDEVP'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATABASE,
  538.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  539.                                                  'argumentCount'    =>    '?'
  540.                                                 ),
  541.                 'DSUM'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATABASE,
  542.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  543.                                                  'argumentCount'    =>    '?'
  544.                                                 ),
  545.                 'DURATION'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  546.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  547.                                                  'argumentCount'    =>    '5,6'
  548.                                                 ),
  549.                 'DVAR'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATABASE,
  550.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  551.                                                  'argumentCount'    =>    '?'
  552.                                                 ),
  553.                 'DVARP'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATABASE,
  554.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  555.                                                  'argumentCount'    =>    '?'
  556.                                                 ),
  557.                 'EDATE'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  558.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::EDATE',
  559.                                                  'argumentCount'    =>    '2'
  560.                                                 ),
  561.                 'EFFECT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  562.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::EFFECT',
  563.                                                  'argumentCount'    =>    '2'
  564.                                                 ),
  565.                 'EOMONTH'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  566.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::EOMONTH',
  567.                                                  'argumentCount'    =>    '2'
  568.                                                 ),
  569.                 'ERF'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  570.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::ERF',
  571.                                                  'argumentCount'    =>    '1,2'
  572.                                                 ),
  573.                 'ERFC'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  574.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::ERFC',
  575.                                                  'argumentCount'    =>    '1'
  576.                                                 ),
  577.                 'ERROR.TYPE'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
  578.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::ERROR_TYPE',
  579.                                                  'argumentCount'    =>    '1'
  580.                                                 ),
  581.                 'EVEN'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  582.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::EVEN',
  583.                                                  'argumentCount'    =>    '1'
  584.                                                 ),
  585.                 'EXACT'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  586.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  587.                                                  'argumentCount'    =>    '2'
  588.                                                 ),
  589.                 'EXP'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  590.                                                  'functionCall'        =>    'exp',
  591.                                                  'argumentCount'    =>    '1'
  592.                                                 ),
  593.                 'EXPONDIST'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  594.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::EXPONDIST',
  595.                                                  'argumentCount'    =>    '3'
  596.                                                 ),
  597.                 'FACT'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  598.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::FACT',
  599.                                                  'argumentCount'    =>    '1'
  600.                                                 ),
  601.                 'FACTDOUBLE'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  602.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::FACTDOUBLE',
  603.                                                  'argumentCount'    =>    '1'
  604.                                                 ),
  605.                 'FALSE'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
  606.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::LOGICAL_FALSE',
  607.                                                  'argumentCount'    =>    '0'
  608.                                                 ),
  609.                 'FDIST'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  610.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  611.                                                  'argumentCount'    =>    '3'
  612.                                                 ),
  613.                 'FIND'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  614.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::SEARCHSENSITIVE',
  615.                                                  'argumentCount'    =>    '2,3'
  616.                                                 ),
  617.                 'FINDB'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  618.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::SEARCHSENSITIVE',
  619.                                                  'argumentCount'    =>    '2,3'
  620.                                                 ),
  621.                 'FINV'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  622.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  623.                                                  'argumentCount'    =>    '3'
  624.                                                 ),
  625.                 'FISHER'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  626.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::FISHER',
  627.                                                  'argumentCount'    =>    '1'
  628.                                                 ),
  629.                 'FISHERINV'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  630.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::FISHERINV',
  631.                                                  'argumentCount'    =>    '1'
  632.                                                 ),
  633.                 'FIXED'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  634.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::FIXEDFORMAT',
  635.                                                  'argumentCount'    =>    '1-3'
  636.                                                 ),
  637.                 'FLOOR'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  638.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::FLOOR',
  639.                                                  'argumentCount'    =>    '2'
  640.                                                 ),
  641.                 'FORECAST'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  642.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::FORECAST',
  643.                                                  'argumentCount'    =>    '3'
  644.                                                 ),
  645.                 'FREQUENCY'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  646.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  647.                                                  'argumentCount'    =>    '2'
  648.                                                 ),
  649.                 'FTEST'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  650.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  651.                                                  'argumentCount'    =>    '2'
  652.                                                 ),
  653.                 'FV'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  654.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::FV',
  655.                                                  'argumentCount'    =>    '3-5'
  656.                                                 ),
  657.                 'FVSCHEDULE'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  658.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  659.                                                  'argumentCount'    =>    '2'
  660.                                                 ),
  661.                 'GAMMADIST'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  662.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::GAMMADIST',
  663.                                                  'argumentCount'    =>    '4'
  664.                                                 ),
  665.                 'GAMMAINV'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  666.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::GAMMAINV',
  667.                                                  'argumentCount'    =>    '3'
  668.                                                 ),
  669.                 'GAMMALN'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  670.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::GAMMALN',
  671.                                                  'argumentCount'    =>    '1'
  672.                                                 ),
  673.                 'GCD'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  674.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::GCD',
  675.                                                  'argumentCount'    =>    '1+'
  676.                                                 ),
  677.                 'GEOMEAN'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  678.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::GEOMEAN',
  679.                                                  'argumentCount'    =>    '1+'
  680.                                                 ),
  681.                 'GESTEP'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  682.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::GESTEP',
  683.                                                  'argumentCount'    =>    '1,2'
  684.                                                 ),
  685.                 'GETPIVOTDATA'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
  686.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  687.                                                  'argumentCount'    =>    '2+'
  688.                                                 ),
  689.                 'GROWTH'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  690.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::GROWTH',
  691.                                                  'argumentCount'    =>    '1-4'
  692.                                                 ),
  693.                 'HARMEAN'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  694.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::HARMEAN',
  695.                                                  'argumentCount'    =>    '1+'
  696.                                                 ),
  697.                 'HEX2BIN'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  698.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::HEXTOBIN',
  699.                                                  'argumentCount'    =>    '1,2'
  700.                                                 ),
  701.                 'HEX2DEC'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  702.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::HEXTODEC',
  703.                                                  'argumentCount'    =>    '1'
  704.                                                 ),
  705.                 'HEX2OCT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  706.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::HEXTOOCT',
  707.                                                  'argumentCount'    =>    '1,2'
  708.                                                 ),
  709.                 'HLOOKUP'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
  710.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  711.                                                  'argumentCount'    =>    '3,4'
  712.                                                 ),
  713.                 'HOUR'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  714.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::HOUROFDAY',
  715.                                                  'argumentCount'    =>    '1'
  716.                                                 ),
  717.                 'HYPERLINK'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
  718.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  719.                                                  'argumentCount'    =>    '1,2'
  720.                                                 ),
  721.                 'HYPGEOMDIST'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  722.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::HYPGEOMDIST',
  723.                                                  'argumentCount'    =>    '4'
  724.                                                 ),
  725.                 'IF'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
  726.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::STATEMENT_IF',
  727.                                                  'argumentCount'    =>    '1-3'
  728.                                                 ),
  729.                 'IFERROR'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
  730.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::STATEMENT_IFERROR',
  731.                                                  'argumentCount'    =>    '1'
  732.                                                 ),
  733.                 'IMABS'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  734.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IMABS',
  735.                                                  'argumentCount'    =>    '1'
  736.                                                 ),
  737.                 'IMAGINARY'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  738.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IMAGINARY',
  739.                                                  'argumentCount'    =>    '1'
  740.                                                 ),
  741.                 'IMARGUMENT'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  742.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IMARGUMENT',
  743.                                                  'argumentCount'    =>    '1'
  744.                                                 ),
  745.                 'IMCONJUGATE'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  746.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IMCONJUGATE',
  747.                                                  'argumentCount'    =>    '1'
  748.                                                 ),
  749.                 'IMCOS'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  750.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IMCOS',
  751.                                                  'argumentCount'    =>    '1'
  752.                                                 ),
  753.                 'IMDIV'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  754.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IMDIV',
  755.                                                  'argumentCount'    =>    '2'
  756.                                                 ),
  757.                 'IMEXP'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  758.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IMEXP',
  759.                                                  'argumentCount'    =>    '1'
  760.                                                 ),
  761.                 'IMLN'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  762.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IMLN',
  763.                                                  'argumentCount'    =>    '1'
  764.                                                 ),
  765.                 'IMLOG10'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  766.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IMLOG10',
  767.                                                  'argumentCount'    =>    '1'
  768.                                                 ),
  769.                 'IMLOG2'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  770.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IMLOG2',
  771.                                                  'argumentCount'    =>    '1'
  772.                                                 ),
  773.                 'IMPOWER'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  774.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IMPOWER',
  775.                                                  'argumentCount'    =>    '2'
  776.                                                 ),
  777.                 'IMPRODUCT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  778.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IMPRODUCT',
  779.                                                  'argumentCount'    =>    '1+'
  780.                                                 ),
  781.                 'IMREAL'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  782.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IMREAL',
  783.                                                  'argumentCount'    =>    '1'
  784.                                                 ),
  785.                 'IMSIN'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  786.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IMSIN',
  787.                                                  'argumentCount'    =>    '1'
  788.                                                 ),
  789.                 'IMSQRT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  790.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IMSQRT',
  791.                                                  'argumentCount'    =>    '1'
  792.                                                 ),
  793.                 'IMSUB'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  794.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IMSUB',
  795.                                                  'argumentCount'    =>    '2'
  796.                                                 ),
  797.                 'IMSUM'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  798.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IMSUM',
  799.                                                  'argumentCount'    =>    '1+'
  800.                                                 ),
  801.                 'INDEX'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
  802.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::INDEX',
  803.                                                  'argumentCount'    =>    '1-4'
  804.                                                 ),
  805.                 'INDIRECT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
  806.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  807.                                                  'argumentCount'    =>    '1,2'
  808.                                                 ),
  809.                 'INFO'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
  810.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  811.                                                  'argumentCount'    =>    '1'
  812.                                                 ),
  813.                 'INT'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  814.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::INTVALUE',
  815.                                                  'argumentCount'    =>    '1'
  816.                                                 ),
  817.                 'INTERCEPT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  818.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::INTERCEPT',
  819.                                                  'argumentCount'    =>    '2'
  820.                                                 ),
  821.                 'INTRATE'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  822.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::INTRATE',
  823.                                                  'argumentCount'    =>    '4,5'
  824.                                                 ),
  825.                 'IPMT'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  826.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IPMT',
  827.                                                  'argumentCount'    =>    '4-6'
  828.                                                 ),
  829.                 'IRR'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  830.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  831.                                                  'argumentCount'    =>    '1,2'
  832.                                                 ),
  833.                 'ISBLANK'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
  834.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IS_BLANK',
  835.                                                  'argumentCount'    =>    '1'
  836.                                                 ),
  837.                 'ISERR'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
  838.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IS_ERR',
  839.                                                  'argumentCount'    =>    '1'
  840.                                                 ),
  841.                 'ISERROR'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
  842.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IS_ERROR',
  843.                                                  'argumentCount'    =>    '1'
  844.                                                 ),
  845.                 'ISEVEN'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
  846.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IS_EVEN',
  847.                                                  'argumentCount'    =>    '1'
  848.                                                 ),
  849.                 'ISLOGICAL'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
  850.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IS_LOGICAL',
  851.                                                  'argumentCount'    =>    '1'
  852.                                                 ),
  853.                 'ISNA'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
  854.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IS_NA',
  855.                                                  'argumentCount'    =>    '1'
  856.                                                 ),
  857.                 'ISNONTEXT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
  858.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IS_NONTEXT',
  859.                                                  'argumentCount'    =>    '1'
  860.                                                 ),
  861.                 'ISNUMBER'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
  862.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IS_NUMBER',
  863.                                                  'argumentCount'    =>    '1'
  864.                                                 ),
  865.                 'ISODD'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
  866.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IS_ODD',
  867.                                                  'argumentCount'    =>    '1'
  868.                                                 ),
  869.                 'ISPMT'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  870.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  871.                                                  'argumentCount'    =>    '4'
  872.                                                 ),
  873.                 'ISREF'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
  874.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  875.                                                  'argumentCount'    =>    '1'
  876.                                                 ),
  877.                 'ISTEXT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
  878.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::IS_TEXT',
  879.                                                  'argumentCount'    =>    '1'
  880.                                                 ),
  881.                 'JIS'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  882.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  883.                                                  'argumentCount'    =>    '1'
  884.                                                 ),
  885.                 'KURT'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  886.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::KURT',
  887.                                                  'argumentCount'    =>    '1+'
  888.                                                 ),
  889.                 'LARGE'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  890.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::LARGE',
  891.                                                  'argumentCount'    =>    '2'
  892.                                                 ),
  893.                 'LCM'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  894.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::LCM',
  895.                                                  'argumentCount'    =>    '1+'
  896.                                                 ),
  897.                 'LEFT'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  898.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::LEFT',
  899.                                                  'argumentCount'    =>    '1,2'
  900.                                                 ),
  901.                 'LEFTB'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  902.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::LEFT',
  903.                                                  'argumentCount'    =>    '1,2'
  904.                                                 ),
  905.                 'LEN'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  906.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::STRINGLENGTH',
  907.                                                  'argumentCount'    =>    '1'
  908.                                                 ),
  909.                 'LENB'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  910.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::STRINGLENGTH',
  911.                                                  'argumentCount'    =>    '1'
  912.                                                 ),
  913.                 'LINEST'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  914.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::LINEST',
  915.                                                  'argumentCount'    =>    '1-4'
  916.                                                 ),
  917.                 'LN'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  918.                                                  'functionCall'        =>    'log',
  919.                                                  'argumentCount'    =>    '1'
  920.                                                 ),
  921.                 'LOG'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  922.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::LOG_BASE',
  923.                                                  'argumentCount'    =>    '1,2'
  924.                                                 ),
  925.                 'LOG10'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  926.                                                  'functionCall'        =>    'log10',
  927.                                                  'argumentCount'    =>    '1'
  928.                                                 ),
  929.                 'LOGEST'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  930.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::LOGEST',
  931.                                                  'argumentCount'    =>    '1-4'
  932.                                                 ),
  933.                 'LOGINV'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  934.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::LOGINV',
  935.                                                  'argumentCount'    =>    '3'
  936.                                                 ),
  937.                 'LOGNORMDIST'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  938.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::LOGNORMDIST',
  939.                                                  'argumentCount'    =>    '3'
  940.                                                 ),
  941.                 'LOOKUP'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
  942.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::LOOKUP',
  943.                                                  'argumentCount'    =>    '2,3'
  944.                                                 ),
  945.                 'LOWER'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  946.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::LOWERCASE',
  947.                                                  'argumentCount'    =>    '1'
  948.                                                 ),
  949.                 'MATCH'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
  950.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::MATCH',
  951.                                                  'argumentCount'    =>    '2,3'
  952.                                                 ),
  953.                 'MAX'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  954.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::MAX',
  955.                                                  'argumentCount'    =>    '1+'
  956.                                                 ),
  957.                 'MAXA'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  958.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::MAXA',
  959.                                                  'argumentCount'    =>    '1+'
  960.                                                 ),
  961.                 'MDETERM'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  962.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::MDETERM',
  963.                                                  'argumentCount'    =>    '1'
  964.                                                 ),
  965.                 'MDURATION'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  966.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  967.                                                  'argumentCount'    =>    '5,6'
  968.                                                 ),
  969.                 'MEDIAN'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  970.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::MEDIAN',
  971.                                                  'argumentCount'    =>    '1+'
  972.                                                 ),
  973.                 'MID'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  974.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::MID',
  975.                                                  'argumentCount'    =>    '3'
  976.                                                 ),
  977.                 'MIDB'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  978.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::MID',
  979.                                                  'argumentCount'    =>    '3'
  980.                                                 ),
  981.                 'MIN'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  982.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::MIN',
  983.                                                  'argumentCount'    =>    '1+'
  984.                                                 ),
  985.                 'MINA'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  986.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::MINA',
  987.                                                  'argumentCount'    =>    '1+'
  988.                                                 ),
  989.                 'MINUTE'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  990.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::MINUTEOFHOUR',
  991.                                                  'argumentCount'    =>    '1'
  992.                                                 ),
  993.                 'MINVERSE'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  994.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::MINVERSE',
  995.                                                  'argumentCount'    =>    '1'
  996.                                                 ),
  997.                 'MIRR'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  998.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  999.                                                  'argumentCount'    =>    '3'
  1000.                                                 ),
  1001.                 'MMULT'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1002.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::MMULT',
  1003.                                                  'argumentCount'    =>    '2'
  1004.                                                 ),
  1005.                 'MOD'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1006.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::MOD',
  1007.                                                  'argumentCount'    =>    '2'
  1008.                                                 ),
  1009.                 'MODE'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1010.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::MODE',
  1011.                                                  'argumentCount'    =>    '1+'
  1012.                                                 ),
  1013.                 'MONTH'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  1014.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::MONTHOFYEAR',
  1015.                                                  'argumentCount'    =>    '1'
  1016.                                                 ),
  1017.                 'MROUND'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1018.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::MROUND',
  1019.                                                  'argumentCount'    =>    '2'
  1020.                                                 ),
  1021.                 'MULTINOMIAL'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1022.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::MULTINOMIAL',
  1023.                                                  'argumentCount'    =>    '1+'
  1024.                                                 ),
  1025.                 'N'                        => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
  1026.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1027.                                                  'argumentCount'    =>    '1'
  1028.                                                 ),
  1029.                 'NA'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
  1030.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::NA',
  1031.                                                  'argumentCount'    =>    '0'
  1032.                                                 ),
  1033.                 'NEGBINOMDIST'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1034.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::NEGBINOMDIST',
  1035.                                                  'argumentCount'    =>    '3'
  1036.                                                 ),
  1037.                 'NETWORKDAYS'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  1038.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::NETWORKDAYS',
  1039.                                                  'argumentCount'    =>    '2+'
  1040.                                                 ),
  1041.                 'NOMINAL'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1042.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::NOMINAL',
  1043.                                                  'argumentCount'    =>    '2'
  1044.                                                 ),
  1045.                 'NORMDIST'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1046.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::NORMDIST',
  1047.                                                  'argumentCount'    =>    '4'
  1048.                                                 ),
  1049.                 'NORMINV'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1050.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::NORMINV',
  1051.                                                  'argumentCount'    =>    '3'
  1052.                                                 ),
  1053.                 'NORMSDIST'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1054.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::NORMSDIST',
  1055.                                                  'argumentCount'    =>    '1'
  1056.                                                 ),
  1057.                 'NORMSINV'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1058.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::NORMSINV',
  1059.                                                  'argumentCount'    =>    '1'
  1060.                                                 ),
  1061.                 'NOT'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
  1062.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::LOGICAL_NOT',
  1063.                                                  'argumentCount'    =>    '1'
  1064.                                                 ),
  1065.                 'NOW'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  1066.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DATETIMENOW',
  1067.                                                  'argumentCount'    =>    '0'
  1068.                                                 ),
  1069.                 'NPER'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1070.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::NPER',
  1071.                                                  'argumentCount'    =>    '3-5'
  1072.                                                 ),
  1073.                 'NPV'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1074.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::NPV',
  1075.                                                  'argumentCount'    =>    '2+'
  1076.                                                 ),
  1077.                 'OCT2BIN'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  1078.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::OCTTOBIN',
  1079.                                                  'argumentCount'    =>    '1,2'
  1080.                                                 ),
  1081.                 'OCT2DEC'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  1082.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::OCTTODEC',
  1083.                                                  'argumentCount'    =>    '1'
  1084.                                                 ),
  1085.                 'OCT2HEX'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
  1086.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::OCTTOHEX',
  1087.                                                  'argumentCount'    =>    '1,2'
  1088.                                                 ),
  1089.                 'ODD'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1090.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::ODD',
  1091.                                                  'argumentCount'    =>    '1'
  1092.                                                 ),
  1093.                 'ODDFPRICE'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1094.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1095.                                                  'argumentCount'    =>    '8,9'
  1096.                                                 ),
  1097.                 'ODDFYIELD'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1098.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1099.                                                  'argumentCount'    =>    '8,9'
  1100.                                                 ),
  1101.                 'ODDLPRICE'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1102.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1103.                                                  'argumentCount'    =>    '7,8'
  1104.                                                 ),
  1105.                 'ODDLYIELD'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1106.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1107.                                                  'argumentCount'    =>    '7,8'
  1108.                                                 ),
  1109.                 'OFFSET'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
  1110.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::OFFSET',
  1111.                                                  'argumentCount'    =>    '3,5'
  1112.                                                 ),
  1113.                 'OR'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
  1114.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::LOGICAL_OR',
  1115.                                                  'argumentCount'    =>    '1+'
  1116.                                                 ),
  1117.                 'PEARSON'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1118.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::CORREL',
  1119.                                                  'argumentCount'    =>    '2'
  1120.                                                 ),
  1121.                 'PERCENTILE'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1122.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::PERCENTILE',
  1123.                                                  'argumentCount'    =>    '2'
  1124.                                                 ),
  1125.                 'PERCENTRANK'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1126.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::PERCENTRANK',
  1127.                                                  'argumentCount'    =>    '2,3'
  1128.                                                 ),
  1129.                 'PERMUT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1130.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::PERMUT',
  1131.                                                  'argumentCount'    =>    '2'
  1132.                                                 ),
  1133.                 'PHONETIC'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  1134.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1135.                                                  'argumentCount'    =>    '1'
  1136.                                                 ),
  1137.                 'PI'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1138.                                                  'functionCall'        =>    'pi',
  1139.                                                  'argumentCount'    =>    '0'
  1140.                                                 ),
  1141.                 'PMT'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1142.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::PMT',
  1143.                                                  'argumentCount'    =>    '3-5'
  1144.                                                 ),
  1145.                 'POISSON'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1146.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::POISSON',
  1147.                                                  'argumentCount'    =>    '3'
  1148.                                                 ),
  1149.                 'POWER'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1150.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::POWER',
  1151.                                                  'argumentCount'    =>    '2'
  1152.                                                 ),
  1153.                 'PPMT'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1154.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::PPMT',
  1155.                                                  'argumentCount'    =>    '4-6'
  1156.                                                 ),
  1157.                 'PRICE'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1158.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1159.                                                  'argumentCount'    =>    '6,7'
  1160.                                                 ),
  1161.                 'PRICEDISC'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1162.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::PRICEDISC',
  1163.                                                  'argumentCount'    =>    '4,5'
  1164.                                                 ),
  1165.                 'PRICEMAT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1166.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::PRICEMAT',
  1167.                                                  'argumentCount'    =>    '5,6'
  1168.                                                 ),
  1169.                 'PROB'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1170.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1171.                                                  'argumentCount'    =>    '3,4'
  1172.                                                 ),
  1173.                 'PRODUCT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1174.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::PRODUCT',
  1175.                                                  'argumentCount'    =>    '1+'
  1176.                                                 ),
  1177.                 'PROPER'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  1178.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::PROPERCASE',
  1179.                                                  'argumentCount'    =>    '1'
  1180.                                                 ),
  1181.                 'PV'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1182.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::PV',
  1183.                                                  'argumentCount'    =>    '3-5'
  1184.                                                 ),
  1185.                 'QUARTILE'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1186.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::QUARTILE',
  1187.                                                  'argumentCount'    =>    '2'
  1188.                                                 ),
  1189.                 'QUOTIENT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1190.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::QUOTIENT',
  1191.                                                  'argumentCount'    =>    '2'
  1192.                                                 ),
  1193.                 'RADIANS'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1194.                                                  'functionCall'        =>    'deg2rad',
  1195.                                                  'argumentCount'    =>    '1'
  1196.                                                 ),
  1197.                 'RAND'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1198.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::RAND',
  1199.                                                  'argumentCount'    =>    '0'
  1200.                                                 ),
  1201.                 'RANDBETWEEN'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1202.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::RAND',
  1203.                                                  'argumentCount'    =>    '2'
  1204.                                                 ),
  1205.                 'RANK'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1206.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::RANK',
  1207.                                                  'argumentCount'    =>    '2,3'
  1208.                                                 ),
  1209.                 'RATE'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1210.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1211.                                                  'argumentCount'    =>    '3-6'
  1212.                                                 ),
  1213.                 'RECEIVED'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1214.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::RECEIVED',
  1215.                                                  'argumentCount'    =>    '4-5'
  1216.                                                 ),
  1217.                 'REPLACE'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  1218.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::REPLACE',
  1219.                                                  'argumentCount'    =>    '4'
  1220.                                                 ),
  1221.                 'REPLACEB'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  1222.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::REPLACE',
  1223.                                                  'argumentCount'    =>    '4'
  1224.                                                 ),
  1225.                 'REPT'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  1226.                                                  'functionCall'        =>    'str_repeat',
  1227.                                                  'argumentCount'    =>    '2'
  1228.                                                 ),
  1229.                 'RIGHT'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  1230.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::RIGHT',
  1231.                                                  'argumentCount'    =>    '1,2'
  1232.                                                 ),
  1233.                 'RIGHTB'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  1234.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::RIGHT',
  1235.                                                  'argumentCount'    =>    '1,2'
  1236.                                                 ),
  1237.                 'ROMAN'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1238.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::ROMAN',
  1239.                                                  'argumentCount'    =>    '1,2'
  1240.                                                 ),
  1241.                 'ROUND'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1242.                                                  'functionCall'        =>    'round',
  1243.                                                  'argumentCount'    =>    '2'
  1244.                                                 ),
  1245.                 'ROUNDDOWN'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1246.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::ROUNDDOWN',
  1247.                                                  'argumentCount'    =>    '2'
  1248.                                                 ),
  1249.                 'ROUNDUP'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1250.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::ROUNDUP',
  1251.                                                  'argumentCount'    =>    '2'
  1252.                                                 ),
  1253.                 'ROW'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
  1254.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::ROW',
  1255.                                                  'argumentCount'    =>    '-1'
  1256.                                                 ),
  1257.                 'ROWS'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
  1258.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1259.                                                  'argumentCount'    =>    '1'
  1260.                                                 ),
  1261.                 'RSQ'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1262.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::RSQ',
  1263.                                                  'argumentCount'    =>    '2'
  1264.                                                 ),
  1265.                 'RTD'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
  1266.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1267.                                                  'argumentCount'    =>    '1+'
  1268.                                                 ),
  1269.                 'SEARCH'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  1270.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::SEARCHINSENSITIVE',
  1271.                                                  'argumentCount'    =>    '2,3'
  1272.                                                 ),
  1273.                 'SEARCHB'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  1274.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::SEARCHINSENSITIVE',
  1275.                                                  'argumentCount'    =>    '2,3'
  1276.                                                 ),
  1277.                 'SECOND'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  1278.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::SECONDOFMINUTE',
  1279.                                                  'argumentCount'    =>    '1'
  1280.                                                 ),
  1281.                 'SERIESSUM'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1282.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::SERIESSUM',
  1283.                                                  'argumentCount'    =>    '4'
  1284.                                                 ),
  1285.                 'SIGN'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1286.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::SIGN',
  1287.                                                  'argumentCount'    =>    '1'
  1288.                                                 ),
  1289.                 'SIN'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1290.                                                  'functionCall'        =>    'sin',
  1291.                                                  'argumentCount'    =>    '1'
  1292.                                                 ),
  1293.                 'SINH'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1294.                                                  'functionCall'        =>    'sinh',
  1295.                                                  'argumentCount'    =>    '1'
  1296.                                                 ),
  1297.                 'SKEW'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1298.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::SKEW',
  1299.                                                  'argumentCount'    =>    '1+'
  1300.                                                 ),
  1301.                 'SLN'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1302.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::SLN',
  1303.                                                  'argumentCount'    =>    '3'
  1304.                                                 ),
  1305.                 'SLOPE'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1306.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::SLOPE',
  1307.                                                  'argumentCount'    =>    '2'
  1308.                                                 ),
  1309.                 'SMALL'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1310.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::SMALL',
  1311.                                                  'argumentCount'    =>    '2'
  1312.                                                 ),
  1313.                 'SQRT'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1314.                                                  'functionCall'        =>    'sqrt',
  1315.                                                  'argumentCount'    =>    '1'
  1316.                                                 ),
  1317.                 'SQRTPI'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1318.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::SQRTPI',
  1319.                                                  'argumentCount'    =>    '1'
  1320.                                                 ),
  1321.                 'STANDARDIZE'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1322.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::STANDARDIZE',
  1323.                                                  'argumentCount'    =>    '3'
  1324.                                                 ),
  1325.                 'STDEV'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1326.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::STDEV',
  1327.                                                  'argumentCount'    =>    '1+'
  1328.                                                 ),
  1329.                 'STDEVA'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1330.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::STDEVA',
  1331.                                                  'argumentCount'    =>    '1+'
  1332.                                                 ),
  1333.                 'STDEVP'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1334.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::STDEVP',
  1335.                                                  'argumentCount'    =>    '1+'
  1336.                                                 ),
  1337.                 'STDEVPA'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1338.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::STDEVPA',
  1339.                                                  'argumentCount'    =>    '1+'
  1340.                                                 ),
  1341.                 'STEYX'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1342.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::STEYX',
  1343.                                                  'argumentCount'    =>    '2'
  1344.                                                 ),
  1345.                 'SUBSTITUTE'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  1346.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1347.                                                  'argumentCount'    =>    '3,4'
  1348.                                                 ),
  1349.                 'SUBTOTAL'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1350.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::SUBTOTAL',
  1351.                                                  'argumentCount'    =>    '2+'
  1352.                                                 ),
  1353.                 'SUM'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1354.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::SUM',
  1355.                                                  'argumentCount'    =>    '1+'
  1356.                                                 ),
  1357.                 'SUMIF'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1358.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::SUMIF',
  1359.                                                  'argumentCount'    =>    '2,3'
  1360.                                                 ),
  1361.                 'SUMIFS'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1362.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1363.                                                  'argumentCount'    =>    '?'
  1364.                                                 ),
  1365.                 'SUMPRODUCT'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1366.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1367.                                                  'argumentCount'    =>    '1+'
  1368.                                                 ),
  1369.                 'SUMSQ'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1370.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::SUMSQ',
  1371.                                                  'argumentCount'    =>    '1+'
  1372.                                                 ),
  1373.                 'SUMX2MY2'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1374.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::SUMX2MY2',
  1375.                                                  'argumentCount'    =>    '2'
  1376.                                                 ),
  1377.                 'SUMX2PY2'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1378.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::SUMX2PY2',
  1379.                                                  'argumentCount'    =>    '2'
  1380.                                                 ),
  1381.                 'SUMXMY2'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1382.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::SUMXMY2',
  1383.                                                  'argumentCount'    =>    '2'
  1384.                                                 ),
  1385.                 'SYD'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1386.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::SYD',
  1387.                                                  'argumentCount'    =>    '4'
  1388.                                                 ),
  1389.                 'T'                        => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  1390.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::RETURNSTRING',
  1391.                                                  'argumentCount'    =>    '1'
  1392.                                                 ),
  1393.                 'TAN'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1394.                                                  'functionCall'        =>    'tan',
  1395.                                                  'argumentCount'    =>    '1'
  1396.                                                 ),
  1397.                 'TANH'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1398.                                                  'functionCall'        =>    'tanh',
  1399.                                                  'argumentCount'    =>    '1'
  1400.                                                 ),
  1401.                 'TBILLEQ'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1402.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::TBILLEQ',
  1403.                                                  'argumentCount'    =>    '3'
  1404.                                                 ),
  1405.                 'TBILLPRICE'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1406.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::TBILLPRICE',
  1407.                                                  'argumentCount'    =>    '3'
  1408.                                                 ),
  1409.                 'TBILLYIELD'            => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1410.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::TBILLYIELD',
  1411.                                                  'argumentCount'    =>    '3'
  1412.                                                 ),
  1413.                 'TDIST'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1414.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::TDIST',
  1415.                                                  'argumentCount'    =>    '3'
  1416.                                                 ),
  1417.                 'TEXT'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  1418.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::TEXTFORMAT',
  1419.                                                  'argumentCount'    =>    '2'
  1420.                                                 ),
  1421.                 'TIME'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  1422.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::TIME',
  1423.                                                  'argumentCount'    =>    '3'
  1424.                                                 ),
  1425.                 'TIMEVALUE'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  1426.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::TIMEVALUE',
  1427.                                                  'argumentCount'    =>    '1'
  1428.                                                 ),
  1429.                 'TINV'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1430.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::TINV',
  1431.                                                  'argumentCount'    =>    '2'
  1432.                                                 ),
  1433.                 'TODAY'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  1434.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DATENOW',
  1435.                                                  'argumentCount'    =>    '0'
  1436.                                                 ),
  1437.                 'TRANSPOSE'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
  1438.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::TRANSPOSE',
  1439.                                                  'argumentCount'    =>    '1'
  1440.                                                 ),
  1441.                 'TREND'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1442.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::TREND',
  1443.                                                  'argumentCount'    =>    '1-4'
  1444.                                                 ),
  1445.                 'TRIM'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  1446.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::TRIMSPACES',
  1447.                                                  'argumentCount'    =>    '1'
  1448.                                                 ),
  1449.                 'TRIMMEAN'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1450.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::TRIMMEAN',
  1451.                                                  'argumentCount'    =>    '2'
  1452.                                                 ),
  1453.                 'TRUE'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
  1454.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::LOGICAL_TRUE',
  1455.                                                  'argumentCount'    =>    '0'
  1456.                                                 ),
  1457.                 'TRUNC'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
  1458.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::TRUNC',
  1459.                                                  'argumentCount'    =>    '1,2'
  1460.                                                 ),
  1461.                 'TTEST'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1462.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1463.                                                  'argumentCount'    =>    '4'
  1464.                                                 ),
  1465.                 'TYPE'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
  1466.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1467.                                                  'argumentCount'    =>    '1'
  1468.                                                 ),
  1469.                 'UPPER'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  1470.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::UPPERCASE',
  1471.                                                  'argumentCount'    =>    '1'
  1472.                                                 ),
  1473.                 'USDOLLAR'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1474.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1475.                                                  'argumentCount'    =>    '2'
  1476.                                                 ),
  1477.                 'VALUE'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
  1478.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1479.                                                  'argumentCount'    =>    '1'
  1480.                                                 ),
  1481.                 'VAR'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1482.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::VARFunc',
  1483.                                                  'argumentCount'    =>    '1+'
  1484.                                                 ),
  1485.                 'VARA'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1486.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::VARA',
  1487.                                                  'argumentCount'    =>    '1+'
  1488.                                                 ),
  1489.                 'VARP'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1490.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::VARP',
  1491.                                                  'argumentCount'    =>    '1+'
  1492.                                                 ),
  1493.                 'VARPA'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1494.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::VARPA',
  1495.                                                  'argumentCount'    =>    '1+'
  1496.                                                 ),
  1497.                 'VDB'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1498.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1499.                                                  'argumentCount'    =>    '5-7'
  1500.                                                 ),
  1501.                 'VERSION'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
  1502.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::VERSION',
  1503.                                                  'argumentCount'    =>    '0'
  1504.                                                 ),
  1505.                 'VLOOKUP'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
  1506.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::VLOOKUP',
  1507.                                                  'argumentCount'    =>    '3,4'
  1508.                                                 ),
  1509.                 'WEEKDAY'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  1510.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DAYOFWEEK',
  1511.                                                  'argumentCount'    =>    '1,2'
  1512.                                                 ),
  1513.                 'WEEKNUM'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  1514.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::WEEKOFYEAR',
  1515.                                                  'argumentCount'    =>    '1,2'
  1516.                                                 ),
  1517.                 'WEIBULL'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1518.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::WEIBULL',
  1519.                                                  'argumentCount'    =>    '4'
  1520.                                                 ),
  1521.                 'WORKDAY'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  1522.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::WORKDAY',
  1523.                                                  'argumentCount'    =>    '2+'
  1524.                                                 ),
  1525.                 'XIRR'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1526.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1527.                                                  'argumentCount'    =>    '2,3'
  1528.                                                 ),
  1529.                 'XNPV'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1530.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1531.                                                  'argumentCount'    =>    '3'
  1532.                                                 ),
  1533.                 'YEAR'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  1534.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::YEAR',
  1535.                                                  'argumentCount'    =>    '1'
  1536.                                                 ),
  1537.                 'YEARFRAC'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
  1538.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::YEARFRAC',
  1539.                                                  'argumentCount'    =>    '2,3'
  1540.                                                 ),
  1541.                 'YIELD'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1542.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1543.                                                  'argumentCount'    =>    '6,7'
  1544.                                                 ),
  1545.                 'YIELDDISC'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1546.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::YIELDDISC',
  1547.                                                  'argumentCount'    =>    '4,5'
  1548.                                                 ),
  1549.                 'YIELDMAT'                => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
  1550.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::YIELDMAT',
  1551.                                                  'argumentCount'    =>    '5,6'
  1552.                                                 ),
  1553.                 'ZTEST'                    => array('category'            =>    PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
  1554.                                                  'functionCall'        =>    'PHPExcel_Calculation_Functions::DUMMY',
  1555.                                                  'argumentCount'    =>    '?'
  1556.                                                 )
  1557.             );
  1558.  
  1559.  
  1560.     //    Internal functions used for special control purposes
  1561.     private $_controlFunctions = array(
  1562.                 'MKMATRIX'    => array('argumentCount'    =>    '*',
  1563.                                      'functionCall'        =>    array('self','_mkMatrix')
  1564.                                     )
  1565.             );
  1566.  
  1567.  
  1568.  
  1569.  
  1570.     /**
  1571.      *    Get an instance of this class
  1572.      *
  1573.      *    @access    public
  1574.      *    @return PHPExcel_Calculation 
  1575.      */
  1576.     public static function getInstance({
  1577.         if (!isset(self::$_instance|| is_null(self::$_instance)) {
  1578.             self::$_instance new PHPExcel_Calculation();
  1579.         }
  1580.  
  1581.         return self::$_instance;
  1582.     }    //    function getInstance()
  1583.  
  1584.  
  1585.     /**
  1586.      *    __clone implementation. Cloning should not be allowed in a Singleton!
  1587.      *
  1588.      *    @access    public
  1589.      *    @throws    Exception
  1590.      */
  1591.     public final function __clone({
  1592.         throw new Exception 'Cloning a Singleton is not allowed!' );
  1593.     }    //    function __clone()
  1594.  
  1595.  
  1596.     /**
  1597.      *    Set the Array Return Type (Array or Value of first element in the array)
  1598.      *
  1599.      *    @access    public
  1600.      *    @param     string    $returnType            Array return type
  1601.      *    @return     boolean                    Success or failure
  1602.      */
  1603.     public static function setArrayReturnType($returnType{
  1604.         if (($returnType == self::RETURN_ARRAY_AS_VALUE||
  1605.             ($returnType == self::RETURN_ARRAY_AS_ARRAY)) {
  1606.             self::$returnArrayAsType $returnType;
  1607.             return True;
  1608.         }
  1609.         return False;
  1610.     }    //    function setExcelCalendar()
  1611.  
  1612.  
  1613.     /**
  1614.      *    Return the Array Return Type (Array or Value of first element in the array)
  1615.      *
  1616.      *    @access    public
  1617.      *    @return     string        $returnType            Array return type
  1618.      */
  1619.     public static function getArrayReturnType({
  1620.         return self::$returnArrayAsType;
  1621.     }    //    function getExcelCalendar()
  1622.  
  1623.  
  1624.     /**
  1625.      *    Is calculation caching enabled?
  1626.      *
  1627.      *    @access    public
  1628.      *    @return boolean 
  1629.      */
  1630.     public function getCalculationCacheEnabled({
  1631.         return $this->_calculationCacheEnabled;
  1632.     }    //    function getCalculationCacheEnabled()
  1633.  
  1634.  
  1635.     /**
  1636.      *    Enable/disable calculation cache
  1637.      *
  1638.      *    @access    public
  1639.      *    @param boolean $pValue 
  1640.      */
  1641.     public function setCalculationCacheEnabled($pValue true{
  1642.         $this->_calculationCacheEnabled = $pValue;
  1643.         $this->clearCalculationCache();
  1644.     }    //    function setCalculationCacheEnabled()
  1645.  
  1646.  
  1647.     /**
  1648.      *    Enable calculation cache
  1649.      */
  1650.     public function enableCalculationCache({
  1651.         $this->setCalculationCacheEnabled(true);
  1652.     }    //    function enableCalculationCache()
  1653.  
  1654.  
  1655.     /**
  1656.      *    Disable calculation cache
  1657.      */
  1658.     public function disableCalculationCache({
  1659.         $this->setCalculationCacheEnabled(false);
  1660.     }    //    function disableCalculationCache()
  1661.  
  1662.  
  1663.     /**
  1664.      *    Clear calculation cache
  1665.      */
  1666.     public function clearCalculationCache({
  1667.         $this->_calculationCache = array();
  1668.     }    //    function clearCalculationCache()
  1669.  
  1670.  
  1671.     /**
  1672.      *    Get calculation cache expiration time
  1673.      *
  1674.      *    @return float 
  1675.      */
  1676.     public function getCalculationCacheExpirationTime({
  1677.         return $this->_calculationCacheExpirationTime;
  1678.     }    //    getCalculationCacheExpirationTime()
  1679.  
  1680.  
  1681.     /**
  1682.      *    Set calculation cache expiration time
  1683.      *
  1684.      *    @param float $pValue 
  1685.      */
  1686.     public function setCalculationCacheExpirationTime($pValue 0.01{
  1687.         $this->_calculationCacheExpirationTime = $pValue;
  1688.     }    //    function setCalculationCacheExpirationTime()
  1689.  
  1690.  
  1691.  
  1692.  
  1693.     /**
  1694.      *    Wrap string values in quotes
  1695.      *
  1696.      *    @param mixed $value 
  1697.      *    @return mixed 
  1698.      */
  1699.     public static function _wrapResult($value{
  1700.         if (is_string($value)) {
  1701.             //    Error values cannot be "wrapped"
  1702.             if (preg_match('/^'.self::CALCULATION_REGEXP_ERROR.'$/i'$value$match)) {
  1703.                 //    Return Excel errors "as is"
  1704.                 return $value;
  1705.             }
  1706.             //    Return strings wrapped in quotes
  1707.             return '"'.$value.'"';
  1708.         //    Convert numeric errors to NaN error
  1709.         else if((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) {
  1710.             return PHPExcel_Calculation_Functions::NaN();
  1711.         }
  1712.  
  1713.         return $value;
  1714.     }    //    function _wrapResult()
  1715.  
  1716.  
  1717.     /**
  1718.      *    Remove quotes used as a wrapper to identify string values
  1719.      *
  1720.      *    @param mixed $value 
  1721.      *    @return mixed 
  1722.      */
  1723.     public static function _unwrapResult($value{
  1724.         if (is_string($value)) {
  1725.             if ((strlen($value0&& ($value{0== '"'&& (substr($value,-1== '"')) {
  1726.                 return substr($value,1,-1);
  1727.             }
  1728.         //    Convert numeric errors to NaN error
  1729.         else if((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) {
  1730.             return PHPExcel_Calculation_Functions::NaN();
  1731.         }
  1732.         return $value;
  1733.     }    //    function _unwrapResult()
  1734.  
  1735.  
  1736.  
  1737.  
  1738.     /**
  1739.      *    Calculate cell value (using formula from a cell ID)
  1740.      *    Retained for backward compatibility
  1741.      *
  1742.      *    @access    public
  1743.      *    @param    PHPExcel_Cell    $pCell    Cell to calculate
  1744.      *    @return    mixed 
  1745.      *    @throws    Exception
  1746.      */
  1747.     public function calculate(PHPExcel_Cell $pCell null{
  1748.         return $this->calculateCellValue($pCell);
  1749.     }    //    function calculate()
  1750.  
  1751.  
  1752.     /**
  1753.      *    Calculate the value of a cell formula
  1754.      *
  1755.      *    @access    public
  1756.      *    @param    PHPExcel_Cell    $pCell        Cell to calculate
  1757.      *    @param    Boolean            $resetLog    Flag indicating whether the debug log should be reset or not
  1758.      *    @return    mixed 
  1759.      *    @throws    Exception
  1760.      */
  1761.     public function calculateCellValue(PHPExcel_Cell $pCell null$resetLog true{
  1762.         if ($resetLog{
  1763.             //    Initialise the logging settings if requested
  1764.             $this->formulaError = null;
  1765.             $this->debugLog = array();
  1766.             $this->debugLogStack = array();
  1767.         }
  1768.  
  1769.         //    Read the formula from the cell
  1770.         if (is_null($pCell)) {
  1771.             return null;
  1772.         }
  1773.         $formula $pCell->getValue();
  1774.         $cellID $pCell->getCoordinate();
  1775.  
  1776.         //    Execute the calculation for the cell formula
  1777.         return self::_unwrapResult($this->_calculateFormulaValue($formula$cellID$pCell));
  1778.     }    //    function calculateCellValue(
  1779.  
  1780.  
  1781.     /**
  1782.      *    Validate and parse a formula string
  1783.      *
  1784.      *    @param    string        $formula        Formula to parse
  1785.      *    @return    array 
  1786.      *    @throws    Exception
  1787.      */
  1788.     public function parseFormula($formula{
  1789.         //    Basic validation that this is indeed a formula
  1790.         //    We return an empty array if not
  1791.         $formula trim($formula);
  1792.         if ($formula{0!= '='return array();
  1793.         $formula trim(substr($formula,1));
  1794.         $formulaLength strlen($formula);
  1795.         if ($formulaLength 1return array();
  1796.  
  1797.         //    Parse the formula and return the token stack
  1798.         return $this->_parseFormula($formula);
  1799.     }    //    function parseFormula()
  1800.  
  1801.  
  1802.     /**
  1803.      *    Calculate the value of a formula
  1804.      *
  1805.      *    @param    string        $formula        Formula to parse
  1806.      *    @return    mixed 
  1807.      *    @throws    Exception
  1808.      */
  1809.     public function calculateFormula($formula$cellID=nullPHPExcel_Cell $pCell null{
  1810.         //    Initialise the logging settings
  1811.         $this->formulaError = null;
  1812.         $this->debugLog = array();
  1813.         $this->debugLogStack = array();
  1814.  
  1815.         //    Disable calculation cacheing because it only applies to cell calculations, not straight formulae
  1816.         //    But don't actually flush any cache
  1817.         $resetCache $this->getCalculationCacheEnabled();
  1818.         $this->_calculationCacheEnabled = false;
  1819.         //    Execute the calculation
  1820.         $result self::_unwrapResult($this->_calculateFormulaValue($formula$cellID$pCell));
  1821.         //    Reset calculation cacheing to its previous state
  1822.         $this->_calculationCacheEnabled = $resetCache;
  1823.  
  1824.         return $result;
  1825.     }    //    function calculateFormula()
  1826.  
  1827.  
  1828.     /**
  1829.      *    Parse a cell formula and calculate its value
  1830.      *
  1831.      *    @param    string            $formula    The formula to parse and calculate
  1832.      *    @param    string            $cellID        The ID (e.g. A3) of the cell that we are calculating
  1833.      *    @param    PHPExcel_Cell    $pCell        Cell to calculate
  1834.      *    @return    mixed 
  1835.      *    @throws    Exception
  1836.      */
  1837.     public function _calculateFormulaValue($formula$cellID=nullPHPExcel_Cell $pCell null{
  1838. //        echo '<b>'.$cellID.'</b><br />';
  1839.         $cellValue '';
  1840.  
  1841.         //    Basic validation that this is indeed a formula
  1842.         //    We simply return the "cell value" (formula) if not
  1843.         $formula trim($formula);
  1844.         if ($formula{0!= '='return self::_wrapResult($formula);
  1845.         $formula trim(substr($formula,1));
  1846.         $formulaLength strlen($formula);
  1847.         if ($formulaLength 1return self::_wrapResult($formula);
  1848.  
  1849.         // Is calculation cacheing enabled?
  1850.         if (!is_null($cellID)) {
  1851.             if ($this->_calculationCacheEnabled{
  1852.                 // Is the value present in calculation cache?
  1853. //                echo 'Testing cache value<br />';
  1854.                 if (isset($this->_calculationCache[$pCell->getParent()->getTitle()][$pCell->getCoordinate()])) {
  1855. //                    echo 'Value is in cache<br />';
  1856.                     $this->_writeDebug($cellID,'Testing cache value');
  1857.                     //    Is cache still valid?
  1858.                     if ((time(microtime()) $this->_calculationCache[$pCell->getParent()->getTitle()][$pCell->getCoordinate()]['time'$this->_calculationCacheExpirationTime{
  1859. //                        echo 'Cache time is still valid<br />';
  1860.                         $this->_writeDebug($cellID,'Retrieving value from cache');
  1861.                         // Return the cached result
  1862.                         $returnValue $this->_calculationCache[$pCell->getParent()->getTitle()][$pCell->getCoordinate()]['data'];
  1863. //                        echo 'Retrieving data value of '.$returnValue.' for '.$pCell->getCoordinate().' from cache<br />';
  1864.                         if (is_array($returnValue)) {
  1865.                             return array_shift(PHPExcel_Calculation_Functions::flattenArray($returnValue));
  1866.                         }
  1867.                         return $returnValue;
  1868.                     else {
  1869. //                        echo 'Cache has expired<br />';
  1870.                         $this->_writeDebug($cellID,'Cache value has expired');
  1871.                         //    Clear the cache if it's no longer valid
  1872.                         unset($this->_calculationCache[$pCell->getParent()->getTitle()][$pCell->getCoordinate()]);
  1873.                     }
  1874.                 }
  1875.             }
  1876.         }
  1877.  
  1878.         $this->debugLogStack[$cellID;
  1879.         //    Parse the formula onto the token stack and calculate the value
  1880.         $cellValue $this->_processTokenStack($this->_parseFormula($formula)$cellID$pCell);
  1881.         array_pop($this->debugLogStack);
  1882.  
  1883.         // Save to calculation cache
  1884.         if (!is_null($cellID)) {
  1885.             if ($this->_calculationCacheEnabled{
  1886.                 $this->_calculationCache[$pCell->getParent()->getTitle()][$pCell->getCoordinate()]['time'(time(microtime());
  1887.                 $this->_calculationCache[$pCell->getParent()->getTitle()][$pCell->getCoordinate()]['data'$cellValue;
  1888.             }
  1889.         }
  1890.  
  1891.         //    Return the calculated value
  1892.         if (is_array($cellValue)) {
  1893.             $cellValue array_shift(PHPExcel_Calculation_Functions::flattenArray($cellValue));
  1894.         }
  1895.  
  1896.         return $cellValue;
  1897.     }    //    function _calculateFormulaValue()
  1898.  
  1899.  
  1900.     /**
  1901.      *    Ensure that paired matrix operands are both matrices and of the same size
  1902.      *
  1903.      *    @param    mixed        $operand1    First matrix operand
  1904.      *    @param    mixed        $operand2    Second matrix operand
  1905.      */
  1906.     private static function _checkMatrixOperands(&$operand1,&$operand2,$resize 1{
  1907.         //    Examine each of the two operands, and turn them into an array if they aren't one already
  1908.         //    Note that this function should only be called if one or both of the operand is already an array
  1909.         if (!is_array($operand1)) {
  1910.             list($matrixRows,$matrixColumnsself::_getMatrixDimensions($operand2);
  1911.             $operand1 array_fill(0,$matrixRows,array_fill(0,$matrixColumns,$operand1));
  1912.             $resize 0;
  1913.         elseif (!is_array($operand2)) {
  1914.             list($matrixRows,$matrixColumnsself::_getMatrixDimensions($operand1);
  1915.             $operand2 array_fill(0,$matrixRows,array_fill(0,$matrixColumns,$operand2));
  1916.             $resize 0;
  1917.         }
  1918.  
  1919.         //    Given two matrices of (potentially) unequal size, convert the smaller in each dimension to match the larger
  1920.         if ($resize == 2{
  1921.             self::_resizeMatricesExtend($operand1,$operand2);
  1922.         elseif ($resize == 1{
  1923.             self::_resizeMatricesShrink($operand1,$operand2);
  1924.         }
  1925.     }    //    function _checkMatrixOperands()
  1926.  
  1927.  
  1928.     /**
  1929.      *    Re-index a matrix with straight numeric keys starting from row 0, column 0
  1930.      *
  1931.      *    @param    mixed        $matrix        matrix operand
  1932.      *    @return    array        The re-indexed matrix
  1933.      */
  1934.     private static function _reindexMatrixDimensions($matrix{
  1935.         foreach($matrix as $rowKey => $rowValue{
  1936.             $matrix[$rowKeyarray_values($rowValue);
  1937.         }
  1938.         return array_values($matrix);
  1939.     }    //    function _getMatrixDimensions()
  1940.  
  1941.  
  1942.     /**
  1943.      *    Read the dimensions of a matrix, and re-index it with straight numeric keys starting from row 0, column 0
  1944.      *
  1945.      *    @param    mixed        $matrix        matrix operand
  1946.      *    @return    array        An array comprising the number of rows, and number of columns
  1947.      */
  1948.     private static function _getMatrixDimensions(&$matrix{
  1949.         $matrixRows count($matrix);
  1950.         $matrixColumns 0;
  1951.         foreach($matrix as $rowKey => $rowValue{
  1952.             $colCount count($rowValue);
  1953.             if ($colCount $matrixColumns{
  1954.                 $matrixColumns $colCount;
  1955.             }
  1956.             $matrix[$rowKeyarray_values($rowValue);
  1957.         }
  1958.         $matrix array_values($matrix);
  1959.         return array($matrixRows,$matrixColumns);
  1960.     }    //    function _getMatrixDimensions()
  1961.  
  1962.  
  1963.     /**
  1964.      *    Ensure that paired matrix operands are both matrices of the same size
  1965.      *
  1966.      *    @param    mixed        $matrix1    First matrix operand
  1967.      *    @param    mixed        $matrix2    Second matrix operand
  1968.      */
  1969.     private static function _resizeMatricesShrink(&$matrix1,&$matrix2{
  1970.         list($matrix1Rows,$matrix1Columnsself::_getMatrixDimensions($matrix1);
  1971.         list($matrix2Rows,$matrix2Columnsself::_getMatrixDimensions($matrix2);
  1972.  
  1973.         if (($matrix2Columns $matrix1Columns|| ($matrix2Rows $matrix1Rows)) {
  1974.             if ($matrix2Columns $matrix1Columns{
  1975.                 for ($i 0$i $matrix1Rows++$i{
  1976.                     for ($j $matrix2Columns$j $matrix1Columns++$j{
  1977.                         unset($matrix1[$i][$j]);
  1978.                     }
  1979.                 }
  1980.             }
  1981.             if ($matrix2Rows $matrix1Rows{
  1982.                 for ($i $matrix2Rows$i $matrix1Rows++$i{
  1983.                     unset($matrix1[$i]);
  1984.                 }
  1985.             }
  1986.         }
  1987.  
  1988.         if (($matrix1Columns $matrix2Columns|| ($matrix1Rows $matrix2Rows)) {
  1989.             if ($matrix1Columns $matrix2Columns{
  1990.                 for ($i 0$i $matrix2Rows++$i{
  1991.                     for ($j $matrix1Columns$j $matrix2Columns++$j{
  1992.                         unset($matrix2[$i][$j]);
  1993.                     }
  1994.                 }
  1995.             }
  1996.             if ($matrix1Rows $matrix2Rows{
  1997.                 for ($i $matrix1Rows$i $matrix2Rows++$i{
  1998.                     unset($matrix2[$i]);
  1999.                 }
  2000.             }
  2001.         }
  2002.     }    //    function _resizeMatricesShrink()
  2003.  
  2004.  
  2005.     /**
  2006.      *    Ensure that paired matrix operands are both matrices of the same size
  2007.      *
  2008.      *    @param    mixed        $matrix1    First matrix operand
  2009.      *    @param    mixed        $matrix2    Second matrix operand
  2010.      */
  2011.     private static function _resizeMatricesExtend(&$matrix1,&$matrix2{
  2012.         list($matrix1Rows,$matrix1Columnsself::_getMatrixDimensions($matrix1);
  2013.         list($matrix2Rows,$matrix2Columnsself::_getMatrixDimensions($matrix2);
  2014.  
  2015.         if (($matrix2Columns $matrix1Columns|| ($matrix2Rows $matrix1Rows)) {
  2016.             if ($matrix2Columns $matrix1Columns{
  2017.                 for ($i 0$i $matrix2Rows++$i{
  2018.                     $x $matrix2[$i][$matrix2Columns-1];
  2019.                     for ($j $matrix2Columns$j $matrix1Columns++$j{
  2020.                         $matrix2[$i][$j$x;
  2021.                     }
  2022.                 }
  2023.             }
  2024.             if ($matrix2Rows $matrix1Rows{
  2025.                 $x $matrix2[$matrix2Rows-1];
  2026.                 for ($i 0$i $matrix1Rows++$i{
  2027.                     $matrix2[$i$x;
  2028.                 }
  2029.             }
  2030.         }
  2031.  
  2032.         if (($matrix1Columns $matrix2Columns|| ($matrix1Rows $matrix2Rows)) {
  2033.             if ($matrix1Columns $matrix2Columns{
  2034.                 for ($i 0$i $matrix1Rows++$i{
  2035.                     $x $matrix1[$i][$matrix1Columns-1];
  2036.                     for ($j $matrix1Columns$j $matrix2Columns++$j{
  2037.                         $matrix1[$i][$j$x;
  2038.                     }
  2039.                 }
  2040.             }
  2041.             if ($matrix1Rows $matrix2Rows{
  2042.                 $x $matrix1[$matrix1Rows-1];
  2043.                 for ($i 0$i $matrix2Rows++$i{
  2044.                     $matrix1[$i$x;
  2045.                 }
  2046.             }
  2047.         }
  2048.     }    //    function _resizeMatricesExtend()
  2049.  
  2050.  
  2051.     /**
  2052.      *    Format details of an operand for display in the log (based on operand type)
  2053.      *
  2054.      *    @param    mixed        $value    First matrix operand
  2055.      *    @return    mixed 
  2056.      */
  2057.     private static function _showValue($value{
  2058.         if (is_array($value)) {
  2059.             $retVal '';
  2060.             $i 0;
  2061.             foreach($value as $row{
  2062.                 if (is_array($row)) {
  2063.                     if ($i 0$retVal .= '; '}
  2064.                     $j 0;
  2065.                     foreach($row as $column{
  2066.                         if ($j 0$retVal .= ', '}
  2067.                         $retVal .= $column;
  2068.                         ++$j;
  2069.                     }
  2070.                 else {
  2071.                     if ($i 0$retVal .= ', '}
  2072.                     $retVal .= $row;
  2073.                 }
  2074.                 ++$i;
  2075.             }
  2076.             return '{ '.$retVal.' }';
  2077.         elseif(is_bool($value)) {
  2078.             return ($value'TRUE' 'FALSE';
  2079.         }
  2080.  
  2081.         return $value;
  2082.     }    //    function _showValue()
  2083.  
  2084.  
  2085.     /**
  2086.      *    Format type and details of an operand for display in the log (based on operand type)
  2087.      *
  2088.      *    @param    mixed        $value    First matrix operand
  2089.      *    @return    mixed 
  2090.      */
  2091.     private static function _showTypeDetails($value{
  2092.         switch (gettype($value)) {
  2093.             case 'double'    :
  2094.             case 'float'    :
  2095.                 $typeString 'a floating point number';
  2096.                 break;
  2097.             case 'integer'    :
  2098.                 $typeString 'an integer number';
  2099.                 break;
  2100.             case 'boolean'    :
  2101.                 $typeString 'a boolean';
  2102.                 break;
  2103.             case 'array'    :
  2104.                 $typeString 'a matrix';
  2105.                 break;
  2106.             case 'string'    :
  2107.                 if ($value == ''{
  2108.                     return 'an empty string';
  2109.                 elseif ($value{0== '#'{
  2110.                     return 'a '.$value.' error';
  2111.                 else {
  2112.                     $typeString 'a string';
  2113.                 }
  2114.                 break;
  2115.             case 'NULL'    :
  2116.                 return 'a null value';
  2117.         }
  2118.         return $typeString.' with a value of '.self::_showValue($value);
  2119.     }    //    function _showTypeDetails()
  2120.  
  2121.  
  2122.     private static function _convertMatrixReferences($formula{
  2123.         static $matrixReplaceFrom array('{',';','}');
  2124.         static $matrixReplaceTo array('MKMATRIX(MKMATRIX(','),MKMATRIX(','))');
  2125.  
  2126.         //    Convert any Excel matrix references to the MKMATRIX() function
  2127.         if (strpos($formula,'{'!== false{
  2128.             //    Open and Closed counts used for trapping mismatched braces in the formula
  2129.             $openCount $closeCount 0;
  2130.             //    If there is the possibility of braces within a quoted string, then we don't treat those as matrix indicators
  2131.             if (strpos($formula,'"'!== false{
  2132.                 //    So instead we skip replacing in any quoted strings by only replacing in every other array element after we've exploded
  2133.                 //        the formula
  2134.                 $temp explode('"',$formula);
  2135.                 $i 0;
  2136.                 foreach($temp as &$value{
  2137.                     //    Only count/replace in alternate array entries
  2138.                     if (($i++ % 2== 0{
  2139.                         $openCount += substr_count($value,'{');
  2140.                         $closeCount += substr_count($value,'}');
  2141.                         $value str_replace($matrixReplaceFrom,$matrixReplaceTo,$value);
  2142.                     }
  2143.                 }
  2144.                 unset($value);
  2145.                 //    Then rebuild the formula string
  2146.                 $formula implode('"',$temp);
  2147.             else {
  2148.                 //    If there's no quoted strings, then we do a simple count/replace
  2149.                 $openCount += substr_count($formula,'{');
  2150.                 $closeCount += substr_count($formula,'}');
  2151.                 $formula str_replace($matrixReplaceFrom,$matrixReplaceTo,$formula);
  2152.             }
  2153.             //    Trap for mismatched braces and trigger an appropriate error
  2154.             if ($openCount $closeCount{
  2155.                 if ($openCount 0{
  2156.                     return $this->_raiseFormulaError("Formula Error: Mismatched matrix braces '}'");
  2157.                 else {
  2158.                     return $this->_raiseFormulaError("Formula Error: Unexpected '}' encountered");
  2159.                 }
  2160.             elseif ($openCount $closeCount{
  2161.                 if ($closeCount 0{
  2162.                     return $this->_raiseFormulaError("Formula Error: Mismatched matrix braces '{'");
  2163.                 else {
  2164.                     return $this->_raiseFormulaError("Formula Error: Unexpected '{' encountered");
  2165.                 }
  2166.             }
  2167.         }
  2168.  
  2169.         return $formula;
  2170.     }    //    function _convertMatrixReferences()
  2171.  
  2172.  
  2173.     private static function _mkMatrix({
  2174.         return func_get_args();
  2175.     }    //    function _mkMatrix()
  2176.  
  2177.  
  2178.     // Convert infix to postfix notation
  2179.     private function _parseFormula($formula{
  2180.         if (($formula self::_convertMatrixReferences(trim($formula))) === false{
  2181.             return false;
  2182.         }
  2183.  
  2184.         //    Binary Operators
  2185.         //    These operators always work on two values
  2186.         //    Array key is the operator, the value indicates whether this is a left or right associative operator
  2187.         $operatorAssociativity    array('^' => 0,                                                            //    Exponentiation
  2188.                                         '*' => 0'/' => 0,                                                 //    Multiplication and Division
  2189.                                         '+' => 0'-' => 0,                                                    //    Addition and Subtraction
  2190.                                         '&' => 1,                                                            //    Concatenation
  2191.                                         '>' => 0'<' => 0'=' => 0'>=' => 0'<=' => 0'<>' => 0        //    Comparison
  2192.                                        );
  2193.         //    Comparison (Boolean) Operators
  2194.         //    These operators work on two values, but always return a boolean result
  2195.         $comparisonOperators    array('>''<''=''>=''<=''<>');
  2196.  
  2197.         //    Operator Precedence
  2198.         //    This list includes all valid operators, whether binary (including boolean) or unary (such as %)
  2199.         //    Array key is the operator, the value is its precedence
  2200.         $operatorPrecedence    array('_' => 6,                                                                //    Negation
  2201.                                     '%' => 5,                                                                //    Percentage
  2202.                                     '^' => 4,                                                                //    Exponentiation
  2203.                                     '*' => 3'/' => 3,                                                     //    Multiplication and Division
  2204.                                     '+' => 2'-' => 2,                                                        //    Addition and Subtraction
  2205.                                     '&' => 1,                                                                //    Concatenation
  2206.                                     '>' => 0'<' => 0'=' => 0'>=' => 0'<=' => 0'<>' => 0            //    Comparison
  2207.                                    );
  2208.  
  2209.         $regexpMatchString '/^('.self::CALCULATION_REGEXP_FUNCTION.
  2210.                                '|'.self::CALCULATION_REGEXP_NUMBER.
  2211.                                '|'.self::CALCULATION_REGEXP_STRING.
  2212.                                '|'.self::CALCULATION_REGEXP_OPENBRACE.
  2213.                                '|'.self::CALCULATION_REGEXP_CELLREF.
  2214.                                '|'.self::CALCULATION_REGEXP_NAMEDRANGE.
  2215.                              ')/i';
  2216.  
  2217.         //    Start with initialisation
  2218.         $index 0;
  2219.         $stack new PHPExcel_Token_Stack;
  2220.         $output array();
  2221.         $expectingOperator false;                    //    We use this test in syntax-checking the expression to determine when a
  2222.                                                     //        - is a negation or + is a positive operator rather than an operation
  2223.         $expectingOperand false;                    //    We use this test in syntax-checking the expression to determine whether an operand
  2224.                                                     //        should be null in a function call
  2225.         //    The guts of the lexical parser
  2226.         //    Loop through the formula extracting each operator and operand in turn
  2227.         while(True{
  2228. //            echo 'Assessing Expression <b>'.substr($formula, $index).'</b><br />';
  2229.             $opCharacter $formula{$index};    //    Get the first character of the value at the current index position
  2230. //            echo 'Initial character of expression block is '.$opCharacter.'<br />';
  2231.             if ((in_array($opCharacter$comparisonOperators)) && (strlen($formula$index&& (in_array($formula{$index+1}$comparisonOperators))) {
  2232.                 $opCharacter .= $formula{++$index};
  2233. //                echo 'Initial character of expression block is comparison operator '.$opCharacter.'<br />';
  2234.             }
  2235.  
  2236.             //    Find out if we're currently at the beginning of a number, variable, cell reference, function, parenthesis or operand
  2237.             $isOperandOrFunction preg_match($regexpMatchStringsubstr($formula$index)$match);
  2238. //            echo '$isOperandOrFunction is '.(($isOperandOrFunction)?'True':'False').'<br />';
  2239.  
  2240.             if ($opCharacter == '-' && !$expectingOperator{                //    Is it a negation instead of a minus?
  2241. //                echo 'Element is a Negation operator<br />';
  2242.                 $stack->push('_');                                            //    Put a negation on the stack
  2243.                 ++$index;                                                    //        and drop the negation symbol
  2244.             elseif ($opCharacter == '%' && $expectingOperator{
  2245. //                echo 'Element is a Percentage operator<br />';
  2246.                 $stack->push('%');                                            //    Put a percentage on the stack
  2247.                 ++$index;
  2248.             elseif ($opCharacter == '+' && !$expectingOperator{            //    Positive (rather than plus) can be discarded?
  2249. //                echo 'Element is a Positive number, not Plus operator<br />';
  2250.                 ++$index;                                                    //    Drop the redundant plus symbol
  2251.             elseif (($opCharacter == '_'&& (!$isOperandOrFunction)) {    //    We have to explicitly deny an underscore, because it's legal on
  2252.                 return $this->_raiseFormulaError("Formula Error: Illegal character '_'");    //        the stack but not in the input expression
  2253.                                                                             //    Note that _ is a valid first character in named ranges
  2254.                                                                             //        and this will need modifying soon when we start integrating
  2255.                                                                             //        with PHPExcel proper
  2256.  
  2257.             elseif ((in_array($opCharacter$this->_operatorsor $isOperandOrFunction&& $expectingOperator{    //    Are we putting an operator on the stack?
  2258. //                echo 'Element with value '.$opCharacter.' is an Operator<br />';
  2259.                 while($stack->count(&&
  2260.                     ($o2 $stack->last()) &&
  2261.                     in_array($o2$this->_operators&&
  2262.                     ($operatorAssociativity[$opCharacter$operatorPrecedence[$opCharacter$operatorPrecedence[$o2$operatorPrecedence[$opCharacter<= $operatorPrecedence[$o2])) {
  2263.                     $output[$stack->pop();                                //    Swap operands and higher precedence operators from the stack to the output
  2264.                 }
  2265.                 $stack->push($opCharacter);    //    Finally put our current operator onto the stack
  2266.                 ++$index;
  2267.                 $expectingOperator false;
  2268.  
  2269.             elseif ($opCharacter == ')' && $expectingOperator{            //    Are we expecting to close a parenthesis?
  2270. //                echo 'Element is a Closing bracket<br />';
  2271.                 $expectingOperand false;
  2272.                 while (($o2 $stack->pop()) != '('{                        //    Pop off the stack back to the last (
  2273.                     if (is_null($o2)) return $this->_raiseFormulaError('Formula Error: Unexpected closing brace ")"');
  2274.                     else $output[$o2;
  2275.                 }
  2276.                 if (preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i'$stack->last(2)$matches)) {    //    Did this parenthesis just close a function?
  2277.                     $functionName $matches[1];                                        //    Get the function name
  2278. //                    echo 'Closed Function is '.$functionName.'<br />';
  2279.                     $argumentCount $stack->pop();        //    See how many arguments there were (argument count is the next value stored on the stack)
  2280. //                    if ($argumentCount == 0) {
  2281. //                        echo 'With no arguments<br />';
  2282. //                    } elseif ($argumentCount == 1) {
  2283. //                        echo 'With 1 argument<br />';
  2284. //                    } else {
  2285. //                        echo 'With '.$argumentCount.' arguments<br />';
  2286. //                    }
  2287.                     $output[$argumentCount;            //    Dump the argument count on the output
  2288.                     $output[$stack->pop();            //    Pop the function and push onto the output
  2289.                     if (array_key_exists($functionName$this->_controlFunctions)) {
  2290. //                        echo 'Built-in function '.$functionName.'<br />';
  2291.                         $expectedArgumentCount $this->_controlFunctions[$functionName]['argumentCount'];
  2292.                         $functionCall $this->_controlFunctions[$functionName]['functionCall'];
  2293.                     elseif (array_key_exists($functionName$this->_PHPExcelFunctions)) {
  2294. //                        echo 'PHPExcel function '.$functionName.'<br />';
  2295.                         $expectedArgumentCount $this->_PHPExcelFunctions[$functionName]['argumentCount'];
  2296.                         $functionCall $this->_PHPExcelFunctions[$functionName]['functionCall'];
  2297.                     else {    // did we somehow push a non-function on the stack? this should never happen
  2298.                         return $this->_raiseFormulaError("Formula Error: Internal error, non-function on stack");
  2299.                     }
  2300.                     //    Check the argument count
  2301.                     $argumentCountError False;
  2302.                     if (is_numeric($expectedArgumentCount)) {
  2303.                         if ($expectedArgumentCount 0{
  2304. //                            echo '$expectedArgumentCount is between 0 and '.abs($expectedArgumentCount).'<br />';
  2305.                             if ($argumentCount abs($expectedArgumentCount)) {
  2306.                                 $argumentCountError True;
  2307.                                 $expectedArgumentCountString 'no more than '.abs($expectedArgumentCount);
  2308.                             }
  2309.                         else {
  2310. //                            echo '$expectedArgumentCount is numeric '.$expectedArgumentCount.'<br />';
  2311.                             if ($argumentCount != $expectedArgumentCount{
  2312.                                 $argumentCountError True;
  2313.                                 $expectedArgumentCountString $expectedArgumentCount;
  2314.                             }
  2315.                         }
  2316.                     elseif ($expectedArgumentCount != '*'{
  2317.                         $isOperandOrFunction preg_match('/(\d*)([-+,])(\d*)/',$expectedArgumentCount,$argMatch);
  2318. //                        print_r($argMatch);
  2319. //                        echo '<br />';
  2320.                         switch ($argMatch[2]{
  2321.                             case '+' :
  2322.                                 if ($argumentCount $argMatch[1]{
  2323.                                     $argumentCountError True;
  2324.                                     $expectedArgumentCountString $argMatch[1].' or more ';
  2325.                                 }
  2326.                                 break;
  2327.                             case '-' :
  2328.                                 if (($argumentCount $argMatch[1]|| ($argumentCount $argMatch[3])) {
  2329.                                     $argumentCountError True;
  2330.                                     $expectedArgumentCountString 'between '.$argMatch[1].' and '.$argMatch[3];
  2331.                                 }
  2332.                                 break;
  2333.                             case ',' :
  2334.                                 if (($argumentCount != $argMatch[1]&& ($argumentCount != $argMatch[3])) {
  2335.                                     $argumentCountError True;
  2336.                                     $expectedArgumentCountString 'either '.$argMatch[1].' or '.$argMatch[3];
  2337.                                 }
  2338.                                 break;
  2339.                         }
  2340.                     }
  2341.                     if ($argumentCountError{
  2342.                         return $this->_raiseFormulaError("Formula Error: Wrong number of arguments for $functionName() function: $argumentCount given, ".$expectedArgumentCountString." expected");
  2343.                     }
  2344.                 }
  2345.                 ++$index;
  2346.  
  2347.             elseif ($opCharacter == ','{            //    Is this the comma separator for function arguments?
  2348. //                echo 'Element is a Function argument separator<br />';
  2349.                 while (($o2 $stack->pop()) != '('{
  2350.                     if (is_null($o2)) return $this->_raiseFormulaError("Formula Error: Unexpected ','");
  2351.                     else $output[$o2;    // pop the argument expression stuff and push onto the output
  2352.                 }
  2353.                 //    If we've a comma when we're expecting an operand, then what we actually have is a null operand;
  2354.                 //        so push a null onto the stack
  2355.                 if (($expectingOperand|| (!$expectingOperator)) {
  2356.                     $output[$this->_ExcelConstants['NULL'];
  2357.                 }
  2358.                 // make sure there was a function
  2359.                 if (!preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i'$stack->last(2)$matches))
  2360.                     return $this->_raiseFormulaError("Formula Error: Unexpected ','");
  2361.                 $stack->push($stack->pop()+1);    // increment the argument count
  2362.                 $stack->push('(');    // put the ( back on, we'll need to pop back to it again
  2363.                 $expectingOperator false;
  2364.                 $expectingOperand true;
  2365.                 ++$index;
  2366.  
  2367.             elseif ($opCharacter == '(' && !$expectingOperator{
  2368. //                echo 'Element is an Opening Bracket<br />';
  2369.                 $stack->push('(');
  2370.                 ++$index;
  2371.  
  2372.             elseif ($isOperandOrFunction && !$expectingOperator{    // do we now have a function/variable/number?
  2373.                 $expectingOperator true;
  2374.                 $expectingOperand false;
  2375.                 $val $match[1];
  2376.                 $length strlen($val);
  2377. //                echo 'Element with value '.$val.' is an Operand, Variable, Constant, String, Number, Cell Reference or Function<br />';
  2378.  
  2379.                 if (preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i'$val$matches)) {
  2380.                     $val preg_replace('/\s/','',$val);
  2381. //                    echo 'Element '.$val.' is a Function<br />';
  2382.                     if (array_key_exists(strtoupper($matches[1])$this->_controlFunctions|| array_key_exists(strtoupper($matches[1])$this->_PHPExcelFunctions)) {    // it's a func
  2383.                         $stack->push(strtoupper($val));
  2384.                         $ax preg_match('/^\s*(\s*\))/i'substr($formula$index+$length)$amatch);
  2385.                         if ($ax{
  2386.                             $stack->push(0);
  2387.                             $expectingOperator true;
  2388.                         else {
  2389.                             $stack->push(1);
  2390.                             $expectingOperator false;
  2391.                         }
  2392.                         $stack->push('(');
  2393.                     else {    // it's a var w/ implicit multiplication
  2394.                         $val $matches[1];
  2395.                         $output[$val;
  2396.                     }
  2397.                 elseif (preg_match('/^'.self::CALCULATION_REGEXP_CELLREF.'$/i'$val$matches)) {
  2398. //                    echo 'Element '.$val.' is a Cell reference<br />';
  2399. //                    Watch for this case-change when modifying to allow cell references in different worksheets...
  2400. //                        Should only be applied to the actual cell column, not the worksheet name
  2401. //                    $cellRef = strtoupper($val);
  2402. //                    $output[] = $cellRef;
  2403.                     $output[$val;
  2404. //                    $expectingOperator = false;
  2405.                 else {    // it's a variable, constant, string, number or boolean
  2406. //                    echo 'Element is a Variable, Constant, String, Number or Boolean<br />';
  2407.                     if ($opCharacter == '"'{
  2408. //                        echo 'Element is a String<br />';
  2409.                         $val str_replace('""','"',$val);
  2410.                     elseif (is_numeric($val)) {
  2411. //                        echo 'Element is a Number<br />';
  2412.                         if ((strpos($val,'.'!== False|| (stripos($val,'e'!== False)) {
  2413. //                            echo 'Casting '.$val.' to float<br />';
  2414.                             $val = (float) $val;
  2415.                         else {
  2416. //                            echo 'Casting '.$val.' to integer<br />';
  2417.                             $val = (integer) $val;
  2418.                         }
  2419. //                    } elseif (array_key_exists(trim(strtoupper($val)), $this->_ExcelConstants)) {
  2420. //                        $excelConstant = trim(strtoupper($val));
  2421. //                        echo 'Element '.$val.' is an Excel Constant<br />';
  2422. //                        $val = $this->_ExcelConstants[$excelConstant];
  2423.                     }
  2424.                     $output[$val;
  2425.                 }
  2426.                 $index += $length;
  2427.  
  2428.             elseif ($opCharacter == ')'{    // miscellaneous error checking
  2429.                 if ($expectingOperand{
  2430.                     $output[$this->_ExcelConstants['NULL'];
  2431.                     $expectingOperand false;
  2432.                     $expectingOperator True;
  2433.                 else {
  2434.                     return $this->_raiseFormulaError("Formula Error: Unexpected ')'");
  2435.                 }
  2436.             elseif (in_array($opCharacter$this->_operators&& !$expectingOperator{
  2437.                 return $this->_raiseFormulaError("Formula Error: Unexpected operator '$opCharacter'");
  2438.             else {    // I don't even want to know what you did to get here
  2439.                 return $this->_raiseFormulaError("Formula Error: An unexpected error occured");
  2440.             }
  2441.             //    Test for end of formula string
  2442.             if ($index == strlen($formula)) {
  2443.                 //    Did we end with an operator?.
  2444.                 //    Only valid for the % unary operator
  2445.                 if ((in_array($opCharacter$this->_operators)) && ($opCharacter != '%')) {
  2446.                     return $this->_raiseFormulaError("Formula Error: Operator '$opCharacter' has no operands");
  2447.                 else {
  2448.                     break;
  2449.                 }
  2450.             }
  2451.             //    Ignore white space
  2452.             while (substr($formula$index1== ' '{
  2453.                 ++$index;
  2454.             }
  2455.         }
  2456.  
  2457.         while (!is_null($opCharacter $stack->pop())) {    // pop everything off the stack and push onto output
  2458.             if ($opCharacter == '('return $this->_raiseFormulaError("Formula Error: Expecting ')'");    // if there are any opening braces on the stack, then braces were unbalanced
  2459.             $output[$opCharacter;
  2460.         }
  2461.         return $output;
  2462.     }    //    function _parseFormula()
  2463.  
  2464.  
  2465.     // evaluate postfix notation
  2466.     private function _processTokenStack($tokens$cellID=nullPHPExcel_Cell $pCell null{
  2467.         if ($tokens == falsereturn false;
  2468.  
  2469.         $stack new PHPExcel_Token_Stack;
  2470.  
  2471.         //    Loop through each token in turn
  2472.         foreach ($tokens as $token{
  2473. //            echo '<b>Token is '.$token.'</b><br />';
  2474.             // 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
  2475.             if (in_array($token$this->_binaryOperatorstrue)) {
  2476. //                echo 'Token is a binary operator<br />';
  2477.                 //    We must have two operands, error if we don't
  2478.                 if (is_null($operand2 $stack->pop())) return $this->_raiseFormulaError('Internal error - Operand value missing from stack');
  2479.                 if (is_null($operand1 $stack->pop())) return $this->_raiseFormulaError('Internal error - Operand value missing from stack');
  2480.                 //    Log what we're doing
  2481.                 $this->_writeDebug($cellID,'Evaluating '.self::_showValue($operand1).' '.$token.' '.self::_showValue($operand2));
  2482.                 //    Process the operation in the appropriate manner
  2483.                 switch ($token{
  2484.                     //    Comparison (Boolean) Operators
  2485.                     case '>'    :            //    Greater than
  2486.                     case '<'    :            //    Less than
  2487.                     case '>='    :            //    Greater than or Equal to
  2488.                     case '<='    :            //    Less than or Equal to
  2489.                     case '='    :            //    Equality
  2490.                     case '<>'    :            //    Inequality
  2491.                         $this->_executeBinaryComparisonOperation($cellID,$operand1,$operand2,$token,$stack);
  2492.                         break;
  2493.                     //    Binary Operators
  2494.                     case '+'    :            //    Addition
  2495.                         $this->_executeNumericBinaryOperation($cellID,$operand1,$operand2,$token,'plusEquals',$stack);
  2496.                         break;
  2497.                     case '-'    :            //    Subtraction
  2498.                         $this->_executeNumericBinaryOperation($cellID,$operand1,$operand2,$token,'minusEquals',$stack);
  2499.                         break;
  2500.                     case '*'    :            //    Multiplication
  2501.                         $this->_executeNumericBinaryOperation($cellID,$operand1,$operand2,$token,'arrayTimesEquals',$stack);
  2502.                         break;
  2503.                     case '/'    :            //    Division
  2504.                         $this->_executeNumericBinaryOperation($cellID,$operand1,$operand2,$token,'arrayRightDivide',$stack);
  2505.                         break;
  2506.                     case '^'    :            //    Exponential
  2507.                         $this->_executeNumericBinaryOperation($cellID,$operand1,$operand2,$token,'power',$stack);
  2508.                         break;
  2509.                     case '&'    :            //    Concatenation
  2510.                         //    If either of the operands is a matrix, we need to treat them both as matrices
  2511.                         //        (converting the other operand to a matrix if need be); then perform the required
  2512.                         //        matrix operation
  2513.                         if ((is_array($operand1)) || (is_array($operand2))) {
  2514.                             //    Ensure that both operands are arrays/matrices
  2515.                             self::_checkMatrixOperands($operand1,$operand2);
  2516.                             try {
  2517.                                 //    Convert operand 1 from a PHP array to a matrix
  2518.                                 $matrix new Matrix($operand1);
  2519.                                 //    Perform the required operation against the operand 1 matrix, passing in operand 2
  2520.                                 $matrixResult $matrix->concat($operand2);
  2521.                                 $result $matrixResult->getArray();
  2522.                             catch (Exception $ex{
  2523.                                 $this->_writeDebug($cellID,'JAMA Matrix Exception: '.$ex->getMessage());
  2524.                                 $result '#VALUE!';
  2525.                             }
  2526.                         else {
  2527.                             $result '"'.str_replace('""','"',self::_unwrapResult($operand1,'"').self::_unwrapResult($operand2,'"')).'"';
  2528.                         }
  2529.                         $this->_writeDebug($cellID,'Evaluation Result is '.self::_showTypeDetails($result));
  2530.                         $stack->push($result);
  2531.                         break;
  2532.                 }
  2533.  
  2534.             // if the token is a unary operator, pop one value off the stack, do the operation, and push it back on
  2535.             elseif (($token === "_"|| ($token === "%")) {
  2536. //                echo 'Token is a unary operator<br />';
  2537.                 if (is_null($arg $stack->pop())) return $this->_raiseFormulaError('Internal error - Operand value missing from stack');
  2538.                 if ($token === "_"{
  2539. //                    echo 'Token is a negation operator<br />';
  2540.                     $this->_writeDebug($cellID,'Evaluating Negation of '.self::_showValue($arg));
  2541.                     $multiplier = -1;
  2542.                 else {
  2543. //                    echo 'Token is a percentile operator<br />';
  2544.                     $this->_writeDebug($cellID,'Evaluating Percentile of '.self::_showValue($arg));
  2545.                     $multiplier 0.01;
  2546.                 }
  2547.                 if (is_array($arg)) {
  2548.                     self::_checkMatrixOperands($arg,$multiplier);
  2549.                     try {
  2550.                         $matrix1 new Matrix($arg);
  2551.                         $matrixResult $matrix1->arrayTimesEquals($multiplier);
  2552.                         $result $matrixResult->getArray();
  2553.                     catch (Exception $ex{
  2554.                         $this->_writeDebug($cellID,'JAMA Matrix Exception: '.$ex->getMessage());
  2555.                         $result '#VALUE!';
  2556.                     }
  2557.  
  2558.                 else {
  2559.                     $result $multiplier $arg;
  2560.                 }
  2561.                 $this->_writeDebug($cellID,'Evaluation Result is '.self::_showTypeDetails($result));
  2562.                 $stack->push($result);
  2563.  
  2564.             elseif (preg_match('/^'.self::CALCULATION_REGEXP_CELLREF.'$/i'$token$matches)) {
  2565. //                echo 'Element '.$token.' is a Cell reference<br />';
  2566.                 if (isset($matches[8])) {
  2567. //                    echo 'Reference is a Range of cells<br />';
  2568.                     if (is_null($pCell)) {
  2569. //                        We can't access the range, so return a REF error
  2570.                         $cellValue PHPExcel_Calculation_Functions::REF();
  2571.                     else {
  2572.                         $cellRef $matches[6].$matches[7].':'.$matches[9].$matches[10];
  2573.                         if ($matches[2''{
  2574. //                            echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'<br />';
  2575.                             $this->_writeDebug($cellID,'Evaluating Cell Range '.$cellRef.' in worksheet '.$matches[2]);
  2576.                             $cellValue $this->extractCellRange($cellRef$pCell->getParent()->getParent()->getSheetByName($matches[2])false);
  2577.                             $this->_writeDebug($cellID,'Evaluation Result for cells '.$cellRef.' in worksheet '.$matches[2].' is '.self::_showTypeDetails($cellValue));
  2578.                         else {
  2579. //                            echo '$cellRef='.$cellRef.' in current worksheet<br />';
  2580.                             $this->_writeDebug($cellID,'Evaluating Cell Range '.$cellRef.' in current worksheet');
  2581.                             $cellValue $this->extractCellRange($cellRef$pCell->getParent()false);
  2582.                             $this->_writeDebug($cellID,'Evaluation Result for cells '.$cellRef.' is '.self::_showTypeDetails($cellValue));
  2583.                         }
  2584.                     }
  2585.                 else {
  2586. //                    echo 'Reference is a single Cell<br />';
  2587.                     if (is_null($pCell)) {
  2588. //                        We can't access the cell, so return a REF error
  2589.                         $cellValue PHPExcel_Calculation_Functions::REF();
  2590.                     else {
  2591.                         $cellRef $matches[6].$matches[7];
  2592.                         if ($matches[2''{
  2593. //                            echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'<br />';
  2594.                             $this->_writeDebug($cellID,'Evaluating Cell '.$cellRef.' in worksheet '.$matches[2]);
  2595.                             if ($pCell->getParent()->cellExists($cellRef)) {
  2596.                                 $cellValue $this->extractCellRange($cellRef$pCell->getParent()->getParent()->getSheetByName($matches[2])false);
  2597.                             else {
  2598.                                 $cellValue null;
  2599.                             }
  2600.                             $this->_writeDebug($cellID,'Evaluation Result for cell '.$cellRef.' in worksheet '.$matches[2].' is '.self::_showTypeDetails($cellValue));
  2601.                         else {
  2602. //                            echo '$cellRef='.$cellRef.' in current worksheet<br />';
  2603.                             $this->_writeDebug($cellID,'Evaluating Cell '.$cellRef.' in current worksheet');
  2604.                             if ($pCell->getParent()->cellExists($cellRef)) {
  2605.                                 $cellValue $pCell->getParent()->getCell($cellRef)->getCalculatedValue(false);
  2606.                             else {
  2607.                                 $cellValue '';
  2608.                             }
  2609.                             $this->_writeDebug($cellID,'Evaluation Result for cell '.$cellRef.' is '.self::_showTypeDetails($cellValue));
  2610.                         }
  2611.                     }
  2612.                 }
  2613.                 $stack->push($cellValue);
  2614.  
  2615.             // if the token is a function, pop arguments off the stack, hand them to the function, and push the result back on
  2616.             elseif (preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i'$token$matches)) {
  2617. //                echo 'Token is a function<br />';
  2618.                 $functionName $matches[1];
  2619.                 $argCount $stack->pop();
  2620.                 if ($functionName != 'MKMATRIX'{
  2621.                     $this->_writeDebug($cellID,'Evaluating Function '.$functionName.'() with '.(($argCount == 0'no' $argCount).' argument'.(($argCount == 1'' 's'));
  2622.                 }
  2623.                 if ((array_key_exists($functionName$this->_controlFunctions)) || (array_key_exists($functionName$this->_PHPExcelFunctions))) {    // function
  2624.                     if (array_key_exists($functionName$this->_controlFunctions)) {
  2625.                         $functionCall $this->_controlFunctions[$functionName]['functionCall'];
  2626.                     elseif (array_key_exists($functionName$this->_PHPExcelFunctions)) {
  2627.                         $functionCall $this->_PHPExcelFunctions[$functionName]['functionCall'];
  2628.                     }
  2629.                     // get the arguments for this function
  2630. //                    echo 'Function '.$functionName.' expects '.$argCount.' arguments<br />';
  2631.                     $args array();
  2632.                     for ($i $argCount$i 0--$i{
  2633.                         $arg $stack->pop();
  2634. //                        if (is_null($arg)) return $this->_raiseFormulaError("internal error");
  2635.                         $args[$i$arg;
  2636.                     }
  2637.                     //    Reverse the order of the arguments
  2638.                     ksort($args);
  2639. //                    echo 'Arguments are: ';
  2640. //                    print_r($args);
  2641. //                    echo '<br />';
  2642.                     if ($functionName != 'MKMATRIX'{
  2643.                         $argArrayVals array();
  2644.                         foreach($args as &$arg{
  2645.                             $argArrayVals[self::_showValue($arg);
  2646.                             $arg self::_unwrapResult($arg);
  2647.                         }
  2648.                         unset($arg);
  2649.                         $this->_writeDebug($cellID,'Evaluating '$functionName.'( '.implode(', ',$argArrayVals).' )');
  2650.                     }
  2651.                     //    Process each argument in turn, building the return value as an array
  2652. //                    if (($argCount == 1) && (is_array($args[1])) && ($functionName != 'MKMATRIX')) {
  2653. //                        $operand1 = $args[1];
  2654. //                        $this->_writeDebug($cellID,'Argument is a matrix: '.self::_showValue($operand1));
  2655. //                        $result = array();
  2656. //                        $row = 0;
  2657. //                        foreach($operand1 as $args) {
  2658. //                            if (is_array($args)) {
  2659. //                                foreach($args as $arg) {
  2660. //                                    $this->_writeDebug($cellID,'Evaluating '. $functionName.'( '.self::_showValue($arg).' )');
  2661. //                                    $r = call_user_func_array($functionCall,$arg);
  2662. //                                    $this->_writeDebug($cellID,'Evaluation Result is '.self::_showTypeDetails($r));
  2663. //                                    $result[$row][] = $r;
  2664. //                                }
  2665. //                                ++$row;
  2666. //                            } else {
  2667. //                                $this->_writeDebug($cellID,'Evaluating '. $functionName.'( '.self::_showValue($args).' )');
  2668. //                                $r = call_user_func_array($functionCall,$args);
  2669. //                                $this->_writeDebug($cellID,'Evaluation Result is '.self::_showTypeDetails($r));
  2670. //                                $result[] = $r;
  2671. //                            }
  2672. //                        }
  2673. //                    } else {
  2674.                     //    Process the argument with the appropriate function call
  2675.                         $result call_user_func_array($functionCall,$args);
  2676. //                    }
  2677.                     if ($functionName != 'MKMATRIX'{
  2678.                         $this->_writeDebug($cellID,'Evaluation Result is '.self::_showTypeDetails($result));
  2679.                     }
  2680.                     $stack->push(self::_wrapResult($result));
  2681.                 }
  2682.  
  2683.             else {
  2684.                 // if the token is a number, boolean, string or an Excel error, push it onto the stack
  2685.                 if (array_key_exists(strtoupper($token)$this->_ExcelConstants)) {
  2686.                     $excelConstant strtoupper($token);
  2687. //                    echo 'Token is a PHPExcel constant: '.$excelConstant.'<br />';
  2688.                     $stack->push($this->_ExcelConstants[$excelConstant]);
  2689.                     $this->_writeDebug($cellID,'Evaluating Constant '.$excelConstant.' as '.self::_showTypeDetails($this->_ExcelConstants[$excelConstant]));
  2690.                 elseif ((is_null($token)) || ($token == ''|| (is_bool($token)) || (is_numeric($token)) || ($token{0== '"'|| ($token{0== '#')) {
  2691. //                    echo 'Token is a number, boolean, string or an Excel error<br />';
  2692.                     $stack->push($token);
  2693.                 // if the token is a constant, push the constant value on the stack
  2694.                 elseif (preg_match('/^'.self::CALCULATION_REGEXP_NAMEDRANGE.'$/i'$token$matches)) {
  2695. //                    echo 'Token is a named range<br />';
  2696.                     $namedRange $matches[6];
  2697. //                    echo 'Named Range is '.$namedRange.'<br />';
  2698.                     $this->_writeDebug($cellID,'Evaluating Named Range '.$namedRange);
  2699.                     $cellValue $this->extractNamedRange($namedRange$pCell->getParent()false);
  2700.                     $this->_writeDebug($cellID,'Evaluation Result for named range '.$namedRange.' is '.self::_showTypeDetails($cellValue));
  2701.                     $stack->push($cellValue);
  2702.                 else {
  2703.                     return $this->_raiseFormulaError("undefined variable '$token'");
  2704.                 }
  2705.             }
  2706.         }
  2707.         // when we're out of tokens, the stack should have a single element, the final result
  2708.         if ($stack->count(!= 1return $this->_raiseFormulaError("internal error");
  2709.         $output $stack->pop();
  2710.         if ((is_array($output)) && (self::$returnArrayAsType != self::RETURN_ARRAY_AS_ARRAY)) {
  2711.             return array_unshift(array_unshift($output));
  2712.         }
  2713.         return $output;
  2714.     }    //    function _processTokenStack()
  2715.  
  2716.  
  2717.     private function _validateBinaryOperand($cellID,&$operand,&$stack{
  2718.         //    Numbers, matrices and booleans can pass straight through, as they're already valid
  2719.         if (is_string($operand)) {
  2720.             //    We only need special validations for the operand if it is a string
  2721.             //    Start by stripping off the quotation marks we use to identify true excel string values internally
  2722.             if ($operand '' && $operand{0== '"'$operand self::_unwrapResult($operand,'"')}
  2723.             //    If the string is a numeric value, we treat it as a numeric, so no further testing
  2724.             if (!is_numeric($operand)) {
  2725.                 //    If not a numeric, test to see if the value is an Excel error, and so can't be used in normal binary operations
  2726.                 if ($operand '' && $operand{0== '#'{
  2727.                     $stack->push($operand);
  2728.                     $this->_writeDebug($cellID,'Evaluation Result is '.self::_showTypeDetails($operand));
  2729.                     return false;
  2730.                 else {
  2731.                 //    If not a numeric, then it's a text string, and so can't be used in mathematical binary operations
  2732.                     $stack->push('#VALUE!');
  2733.                     $this->_writeDebug($cellID,'Evaluation Result is a '.self::_showTypeDetails('#VALUE!'));
  2734.                     return false;
  2735.                 }
  2736.             }
  2737.         }
  2738.  
  2739.         //    return a true if the value of the operand is one that we can use in normal binary operations
  2740.         return true;
  2741.     }    //    function _validateBinaryOperand()
  2742.  
  2743.  
  2744.     private function _executeBinaryComparisonOperation($cellID,$operand1,$operand2,$operation,&$stack{
  2745.         //    Validate the two operands
  2746.  
  2747.         //    If we're dealing with non-matrix operations, execute the necessary operation
  2748.         switch ($operation{
  2749.             //    Greater than
  2750.             case '>':
  2751.                 $result ($operand1 $operand2);
  2752.                 break;
  2753.             //    Less than
  2754.             case '<':
  2755.                 $result ($operand1 $operand2);
  2756.                 break;
  2757.             //    Equality
  2758.             case '=':
  2759.                 $result ($operand1 == $operand2);
  2760.                 break;
  2761.             //    Greater than or equal
  2762.             case '>=':
  2763.                 $result ($operand1 >= $operand2);
  2764.                 break;
  2765.             //    Less than or equal
  2766.             case '<=':
  2767.                 $result ($operand1 <= $operand2);
  2768.                 break;
  2769.             //    Inequality
  2770.             case '<>':
  2771.                 $result ($operand1 != $operand2);
  2772.                 break;
  2773.         }
  2774.  
  2775.         //    Log the result details
  2776.         $this->_writeDebug($cellID,'Evaluation Result is '.self::_showTypeDetails($result));
  2777.         //    And push the result onto the stack
  2778.         $stack->push($result);
  2779.         return true;
  2780.     }    //    function _executeBinaryComparisonOperation()
  2781.  
  2782.     private function _executeNumericBinaryOperation($cellID,$operand1,$operand2,$operation,$matrixFunction,&$stack{
  2783.         //    Validate the two operands
  2784.         if (!$this->_validateBinaryOperand($cellID,$operand1,$stack)) return false;
  2785.         if (!$this->_validateBinaryOperand($cellID,$operand2,$stack)) return false;
  2786.  
  2787.         //    If either of the operands is a matrix, we need to treat them both as matrices
  2788.         //        (converting the other operand to a matrix if need be); then perform the required
  2789.         //        matrix operation
  2790.         if ((is_array($operand1)) || (is_array($operand2))) {
  2791.             //    Ensure that both operands are arrays/matrices
  2792.             self::_checkMatrixOperands($operand1,$operand2);
  2793.             try {
  2794.                 //    Convert operand 1 from a PHP array to a matrix
  2795.                 $matrix new Matrix($operand1);
  2796.                 //    Perform the required operation against the operand 1 matrix, passing in operand 2
  2797.                 $matrixResult $matrix->$matrixFunction($operand2);
  2798.                 $result $matrixResult->getArray();
  2799.             catch (Exception $ex{
  2800.                 $this->_writeDebug($cellID,'JAMA Matrix Exception: '.$ex->getMessage());
  2801.                 $result '#VALUE!';
  2802.             }
  2803.         else {
  2804.             //    If we're dealing with non-matrix operations, execute the necessary operation
  2805.             switch ($operation{
  2806.                 //    Addition
  2807.                 case '+':
  2808.                     $result $operand1+$operand2;
  2809.                     break;
  2810.                 //    Subtraction
  2811.                 case '-':
  2812.                     $result $operand1-$operand2;
  2813.                     break;
  2814.                 //    Multiplication
  2815.                 case '*':
  2816.                     $result $operand1*$operand2;
  2817.                     break;
  2818.                 //    Division
  2819.                 case '/':
  2820.                     if ($operand2 == 0{
  2821.                         //    Trap for Divide by Zero error
  2822.                         $stack->push('#DIV/0!');
  2823.                         $this->_writeDebug($cellID,'Evaluation Result is '.self::_showTypeDetails('#DIV/0!'));
  2824.                         return false;
  2825.                     else {
  2826.                         $result $operand1/$operand2;
  2827.                     }
  2828.                     break;
  2829.                 //    Power
  2830.                 case '^':
  2831.                     $result pow($operand1,$operand2);
  2832.                     break;
  2833.             }
  2834.         }
  2835.  
  2836.         //    Log the result details
  2837.         $this->_writeDebug($cellID,'Evaluation Result is '.self::_showTypeDetails($result));
  2838.         //    And push the result onto the stack
  2839.         $stack->push($result);
  2840.         return true;
  2841.     }    //    function _executeNumericBinaryOperation()
  2842.  
  2843.  
  2844.     private function _writeDebug($cellID,$message{
  2845.         //    Only write the debug log if logging is enabled
  2846.         if ($this->writeDebugLog{
  2847. //            $prefix = substr(implode(' -> ',$this->debugLogStack).' -> ',4+strlen($this->debugLogStack[0]));
  2848.             $prefix implode(' -> ',$this->debugLogStack).' -> ';
  2849.             $this->debugLog[$prefix.$message;
  2850.         }
  2851.     }    //    function _writeDebug()
  2852.  
  2853.  
  2854.     // trigger an error, but nicely, if need be
  2855.     private function _raiseFormulaError($errorMessage{
  2856.         $this->formulaError $errorMessage;
  2857.         if (!$this->suppressFormulaErrorsthrow new Exception($errorMessage);
  2858.         trigger_error($errorMessageE_USER_ERROR);
  2859.     }    //    function _raiseFormulaError()
  2860.  
  2861.  
  2862.     /**
  2863.      * Extract range values
  2864.      *
  2865.      * @param    string                $pRange        String based range representation
  2866.      * @param    PHPExcel_Worksheet    $pSheet        Worksheet
  2867.      * @return  mixed                Array of values in range if range contains more than one element. Otherwise, a single value is returned.
  2868.      * @throws    Exception
  2869.      */
  2870.     public function extractCellRange($pRange 'A1'PHPExcel_Worksheet $pSheet null$resetLog=true{
  2871.         // Return value
  2872.         $returnValue array );
  2873.  
  2874. //        echo 'extractCellRange('.$pRange.')<br />';
  2875.         // Worksheet given?
  2876.         if (!is_null($pSheet)) {
  2877.             // Worksheet reference?
  2878. //            echo 'Current sheet name is '.$pSheet->getTitle().'<br />';
  2879. //            echo 'Range reference is '.$pRange.'<br />';
  2880.             if (strpos ($pRange'!'!== false{
  2881. //                echo '$pRange reference includes sheet reference<br />';
  2882.                 $worksheetReference PHPExcel_Worksheet::extractSheetTitle($pRangetrue);
  2883.                 $pSheet $pSheet->getParent()->getSheetByName($worksheetReference[0]);
  2884. //                echo 'New sheet name is '.$pSheet->getTitle().'<br />';
  2885.                 $pRange $worksheetReference[1];
  2886. //                echo 'Adjusted Range reference is '.$pRange.'<br />';
  2887.             }
  2888.  
  2889.             // Extract range
  2890.             $aReferences PHPExcel_Cell::extractAllCellReferencesInRange($pRange);
  2891.             if (count($aReferences== 1{
  2892.                 return $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog);
  2893.             }
  2894.  
  2895.             // Extract cell data
  2896.             foreach ($aReferences as $reference{
  2897.                 // Extract range
  2898.                 list($currentCol,$currentRowPHPExcel_Cell::coordinateFromString($reference);
  2899.  
  2900.                 $returnValue[$currentCol][$currentRow$pSheet->getCell($reference)->getCalculatedValue($resetLog);
  2901.             }
  2902.         }
  2903.  
  2904.         // Return
  2905.         return $returnValue;
  2906.     }    //    function extractCellRange()
  2907.  
  2908.  
  2909.     /**
  2910.      * Extract range values
  2911.      *
  2912.      * @param    string                $pRange        String based range representation
  2913.      * @param    PHPExcel_Worksheet    $pSheet        Worksheet
  2914.      * @return  mixed                Array of values in range if range contains more than one element. Otherwise, a single value is returned.
  2915.      * @throws    Exception
  2916.      */
  2917.     public function extractNamedRange($pRange 'A1'PHPExcel_Worksheet $pSheet null$resetLog=true{
  2918.         // Return value
  2919.         $returnValue array );
  2920.  
  2921. //        echo 'extractNamedRange('.$pRange.')<br />';
  2922.         // Worksheet given?
  2923.         if (!is_null($pSheet)) {
  2924.             // Worksheet reference?
  2925. //            echo 'Current sheet name is '.$pSheet->getTitle().'<br />';
  2926. //            echo 'Range reference is '.$pRange.'<br />';
  2927.             if (strpos ($pRange'!'!== false{
  2928. //                echo '$pRange reference includes sheet reference<br />';
  2929.                 $worksheetReference PHPExcel_Worksheet::extractSheetTitle($pRangetrue);
  2930.                 $pSheet $pSheet->getParent()->getSheetByName($worksheetReference[0]);
  2931. //                echo 'New sheet name is '.$pSheet->getTitle().'<br />';
  2932.                 $pRange $worksheetReference[1];
  2933. //                echo 'Adjusted Range reference is '.$pRange.'<br />';
  2934.             }
  2935.  
  2936.             // Named range?
  2937.             $namedRange PHPExcel_NamedRange::resolveRange($pRange$pSheet);
  2938.             if (!is_null($namedRange)) {
  2939. //                echo 'Named Range '.$pRange.' (';
  2940.                 $pRange $namedRange->getRange();
  2941. //                echo $pRange.') is in sheet '.$namedRange->getWorksheet()->getTitle().'<br />';
  2942.                 if ($pSheet->getTitle(!= $namedRange->getWorksheet()->getTitle()) {
  2943.                     if (!$namedRange->getLocalOnly()) {
  2944.                         $pSheet $namedRange->getWorksheet();
  2945.                     else {
  2946.                         return $returnValue;
  2947.                     }
  2948.                 }
  2949.             }
  2950.  
  2951.             // Extract range
  2952.             $aReferences PHPExcel_Cell::extractAllCellReferencesInRange($pRange);
  2953.             if (count($aReferences== 1{
  2954.                 return $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog);
  2955.             }
  2956.  
  2957.             // Extract cell data
  2958.             foreach ($aReferences as $reference{
  2959.                 // Extract range
  2960.                 list($currentCol,$currentRowPHPExcel_Cell::coordinateFromString($reference);
  2961. //                echo 'NAMED RANGE: $currentCol='.$currentCol.' $currentRow='.$currentRow.'<br />';
  2962.                 $returnValue[$currentRow][$currentCol$pSheet->getCell($reference)->getCalculatedValue($resetLog);
  2963.             }
  2964. //            print_r($returnValue);
  2965. //            echo '<br />';
  2966.             $returnValue array_values($returnValue);
  2967.             foreach($returnValue as &$rr{
  2968.                 $rr array_values($rr);
  2969.             }
  2970.             unset($rr);
  2971. //            print_r($returnValue);
  2972. //            echo '<br />';
  2973.         }
  2974.  
  2975.         // Return
  2976.         return $returnValue;
  2977.     }    //    function extractNamedRange()
  2978.  
  2979.  
  2980.     /**
  2981.      * Is a specific function implemented?
  2982.      *
  2983.      * @param    string    $pFunction    Function Name
  2984.      * @return    boolean 
  2985.      */
  2986.     public function isImplemented($pFunction ''{
  2987.         $pFunction strtoupper ($pFunction);
  2988.         if (isset ($this->_PHPExcelFunctions[$pFunction])) {
  2989.             return ($this->_PHPExcelFunctions[$pFunction]['functionCall'!= 'PHPExcel_Calculation_Functions::DUMMY');
  2990.         else {
  2991.             return false;
  2992.         }
  2993.     }    //    function isImplemented()
  2994.  
  2995.  
  2996.     /**
  2997.      * Get a list of all implemented functions as an array of function objects
  2998.      *
  2999.      * @return    array of PHPExcel_Calculation_Function
  3000.      */
  3001.     public function listFunctions({
  3002.         // Return value
  3003.         $returnValue array();
  3004.         // Loop functions
  3005.         foreach($this->_PHPExcelFunctions as $functionName => $function{
  3006.             if ($function['functionCall'!= 'PHPExcel_Calculation_Functions::DUMMY'{
  3007.                 $returnValue[$functionNamenew PHPExcel_Calculation_Function($function['category'],
  3008.                                                                                 $functionName,
  3009.                                                                                 $function['functionCall']
  3010.                                                                                );
  3011.             }
  3012.         }
  3013.  
  3014.         // Return
  3015.         return $returnValue;
  3016.     }    //    function listFunctions()
  3017.  
  3018.  
  3019.     /**
  3020.      * Get a list of implemented Excel function names
  3021.      *
  3022.      * @return    array 
  3023.      */
  3024.     public function listFunctionNames({
  3025.         // Return value
  3026.         $returnValue array();
  3027.         // Loop functions
  3028.         foreach ($this->_PHPExcelFunctions as $functionName => $function{
  3029.             $returnValue[$functionName;
  3030.         }
  3031.  
  3032.         // Return
  3033.         return $returnValue;
  3034.     }    //    function listFunctionNames()
  3035.  
  3036. }    //    class PHPExcel_Calculation
  3037.  
  3038.  
  3039.  
  3040.  
  3041. // for internal use
  3042.  
  3043.     private $_stack = array();
  3044.     private $_count = 0;
  3045.  
  3046.     public function count({
  3047.         return $this->_count;
  3048.     }
  3049.  
  3050.     public function push($value{
  3051.         $this->_stack[$this->_count++$value;
  3052.     }
  3053.  
  3054.     public function pop({
  3055.         if ($this->_count > 0{
  3056.             return $this->_stack[--$this->_count];
  3057.         }
  3058.         return null;
  3059.     }
  3060.  
  3061.     public function last($n=1{
  3062.         if ($this->_count-$n 0{
  3063.             return null;
  3064.         }
  3065.         return $this->_stack[$this->_count-$n];
  3066.     }
  3067.  
  3068.     function __construct({
  3069.     }
  3070.  
  3071. }    //    class PHPExcel_Token_Stack

Documentation generated on Mon, 10 Aug 2009 08:02:30 +0200 by phpDocumentor 1.4.1