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

Documentation generated on Mon, 11 Jan 2010 08:06:58 +0100 by phpDocumentor 1.4.1