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

Source for file Parser.php

Documentation is available at Parser.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_Writer_Excel5
  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. // Original file header of PEAR::Spreadsheet_Excel_Writer_Parser (used as the base for this class):
  29. // -----------------------------------------------------------------------------------------
  30. // *  Class for parsing Excel formulas
  31. // *
  32. // *  License Information:
  33. // *
  34. // *    Spreadsheet_Excel_Writer:  A library for generating Excel Spreadsheets
  35. // *    Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com
  36. // *
  37. // *    This library is free software; you can redistribute it and/or
  38. // *    modify it under the terms of the GNU Lesser General Public
  39. // *    License as published by the Free Software Foundation; either
  40. // *    version 2.1 of the License, or (at your option) any later version.
  41. // *
  42. // *    This library is distributed in the hope that it will be useful,
  43. // *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  44. // *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  45. // *    Lesser General Public License for more details.
  46. // *
  47. // *    You should have received a copy of the GNU Lesser General Public
  48. // *    License along with this library; if not, write to the Free Software
  49. // *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  50. // */
  51.  
  52.  
  53. /** PHPExcel root directory */
  54. if (!defined('PHPEXCEL_ROOT')) {
  55.     /**
  56.      * @ignore
  57.      */
  58.     define('PHPEXCEL_ROOT'dirname(__FILE__'/../../../');
  59. }
  60.  
  61. /** PHPExcel_Shared_String */
  62. require_once PHPEXCEL_ROOT 'PHPExcel/Shared/String.php';
  63.  
  64. /** PHPExcel_Writer_Excel5_BIFFwriter */
  65. require_once PHPEXCEL_ROOT 'PHPExcel/Writer/Excel5/BIFFwriter.php';
  66.  
  67.  
  68. /**
  69.  * PHPExcel_Writer_Excel5_Parser
  70.  *
  71.  * @category   PHPExcel
  72.  * @package    PHPExcel_Writer_Excel5
  73.  * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  74.  */
  75. {
  76.     /**
  77.      * The index of the character we are currently looking at
  78.      * @var integer 
  79.      */
  80.     var $_current_char;
  81.  
  82.     /**
  83.      * The token we are working on.
  84.      * @var string 
  85.      */
  86.     var $_current_token;
  87.  
  88.     /**
  89.      * The formula to parse
  90.      * @var string 
  91.      */
  92.     var $_formula;
  93.  
  94.     /**
  95.      * The character ahead of the current char
  96.      * @var string 
  97.      */
  98.     var $_lookahead;
  99.  
  100.     /**
  101.      * The parse tree to be generated
  102.      * @var string 
  103.      */
  104.     var $_parse_tree;
  105.  
  106.     /**
  107.      * Array of external sheets
  108.      * @var array 
  109.      */
  110.     var $_ext_sheets;
  111.  
  112.     /**
  113.      * Array of sheet references in the form of REF structures
  114.      * @var array 
  115.      */
  116.     var $_references;
  117.  
  118.     /**
  119.      * The BIFF version for the workbook
  120.      * @var integer 
  121.      */
  122.     var $_BIFF_version;
  123.  
  124.     /**
  125.      * The class constructor
  126.      *
  127.      * @param integer $byte_order The byte order (Little endian or Big endian) of the architecture
  128.      *                            (optional). 1 => big endian, 0 (default) little endian.
  129.      */
  130.     public function __construct($biff_version)
  131.     {
  132.         $this->_current_char  = 0;
  133.         $this->_BIFF_version  = $biff_version;
  134.         $this->_current_token = '';       // The token we are working on.
  135.         $this->_formula       = '';       // The formula to parse.
  136.         $this->_lookahead     = '';       // The character ahead of the current char.
  137.         $this->_parse_tree    = '';       // The parse tree to be generated.
  138.         $this->_initializeHashes();      // Initialize the hashes: ptg's and function's ptg's
  139.         $this->_ext_sheets = array();
  140.         $this->_references = array();
  141.     }
  142.  
  143.     /**
  144.      * Initialize the ptg and function hashes.
  145.      *
  146.      * @access private
  147.      */
  148.     function _initializeHashes()
  149.     {
  150.         // The Excel ptg indices
  151.         $this->ptg array(
  152.             'ptgExp'       => 0x01,
  153.             'ptgTbl'       => 0x02,
  154.             'ptgAdd'       => 0x03,
  155.             'ptgSub'       => 0x04,
  156.             'ptgMul'       => 0x05,
  157.             'ptgDiv'       => 0x06,
  158.             'ptgPower'     => 0x07,
  159.             'ptgConcat'    => 0x08,
  160.             'ptgLT'        => 0x09,
  161.             'ptgLE'        => 0x0A,
  162.             'ptgEQ'        => 0x0B,
  163.             'ptgGE'        => 0x0C,
  164.             'ptgGT'        => 0x0D,
  165.             'ptgNE'        => 0x0E,
  166.             'ptgIsect'     => 0x0F,
  167.             'ptgUnion'     => 0x10,
  168.             'ptgRange'     => 0x11,
  169.             'ptgUplus'     => 0x12,
  170.             'ptgUminus'    => 0x13,
  171.             'ptgPercent'   => 0x14,
  172.             'ptgParen'     => 0x15,
  173.             'ptgMissArg'   => 0x16,
  174.             'ptgStr'       => 0x17,
  175.             'ptgAttr'      => 0x19,
  176.             'ptgSheet'     => 0x1A,
  177.             'ptgEndSheet'  => 0x1B,
  178.             'ptgErr'       => 0x1C,
  179.             'ptgBool'      => 0x1D,
  180.             'ptgInt'       => 0x1E,
  181.             'ptgNum'       => 0x1F,
  182.             'ptgArray'     => 0x20,
  183.             'ptgFunc'      => 0x21,
  184.             'ptgFuncVar'   => 0x22,
  185.             'ptgName'      => 0x23,
  186.             'ptgRef'       => 0x24,
  187.             'ptgArea'      => 0x25,
  188.             'ptgMemArea'   => 0x26,
  189.             'ptgMemErr'    => 0x27,
  190.             'ptgMemNoMem'  => 0x28,
  191.             'ptgMemFunc'   => 0x29,
  192.             'ptgRefErr'    => 0x2A,
  193.             'ptgAreaErr'   => 0x2B,
  194.             'ptgRefN'      => 0x2C,
  195.             'ptgAreaN'     => 0x2D,
  196.             'ptgMemAreaN'  => 0x2E,
  197.             'ptgMemNoMemN' => 0x2F,
  198.             'ptgNameX'     => 0x39,
  199.             'ptgRef3d'     => 0x3A,
  200.             'ptgArea3d'    => 0x3B,
  201.             'ptgRefErr3d'  => 0x3C,
  202.             'ptgAreaErr3d' => 0x3D,
  203.             'ptgArrayV'    => 0x40,
  204.             'ptgFuncV'     => 0x41,
  205.             'ptgFuncVarV'  => 0x42,
  206.             'ptgNameV'     => 0x43,
  207.             'ptgRefV'      => 0x44,
  208.             'ptgAreaV'     => 0x45,
  209.             'ptgMemAreaV'  => 0x46,
  210.             'ptgMemErrV'   => 0x47,
  211.             'ptgMemNoMemV' => 0x48,
  212.             'ptgMemFuncV'  => 0x49,
  213.             'ptgRefErrV'   => 0x4A,
  214.             'ptgAreaErrV'  => 0x4B,
  215.             'ptgRefNV'     => 0x4C,
  216.             'ptgAreaNV'    => 0x4D,
  217.             'ptgMemAreaNV' => 0x4E,
  218.             'ptgMemNoMemN' => 0x4F,
  219.             'ptgFuncCEV'   => 0x58,
  220.             'ptgNameXV'    => 0x59,
  221.             'ptgRef3dV'    => 0x5A,
  222.             'ptgArea3dV'   => 0x5B,
  223.             'ptgRefErr3dV' => 0x5C,
  224.             'ptgAreaErr3d' => 0x5D,
  225.             'ptgArrayA'    => 0x60,
  226.             'ptgFuncA'     => 0x61,
  227.             'ptgFuncVarA'  => 0x62,
  228.             'ptgNameA'     => 0x63,
  229.             'ptgRefA'      => 0x64,
  230.             'ptgAreaA'     => 0x65,
  231.             'ptgMemAreaA'  => 0x66,
  232.             'ptgMemErrA'   => 0x67,
  233.             'ptgMemNoMemA' => 0x68,
  234.             'ptgMemFuncA'  => 0x69,
  235.             'ptgRefErrA'   => 0x6A,
  236.             'ptgAreaErrA'  => 0x6B,
  237.             'ptgRefNA'     => 0x6C,
  238.             'ptgAreaNA'    => 0x6D,
  239.             'ptgMemAreaNA' => 0x6E,
  240.             'ptgMemNoMemN' => 0x6F,
  241.             'ptgFuncCEA'   => 0x78,
  242.             'ptgNameXA'    => 0x79,
  243.             'ptgRef3dA'    => 0x7A,
  244.             'ptgArea3dA'   => 0x7B,
  245.             'ptgRefErr3dA' => 0x7C,
  246.             'ptgAreaErr3d' => 0x7D
  247.             );
  248.  
  249.         // Thanks to Michael Meeks and Gnumeric for the initial arg values.
  250.         //
  251.         // The following hash was generated by "function_locale.pl" in the distro.
  252.         // Refer to function_locale.pl for non-English function names.
  253.         //
  254.         // The array elements are as follow:
  255.         // ptg:   The Excel function ptg code.
  256.         // args:  The number of arguments that the function takes:
  257.         //           >=0 is a fixed number of arguments.
  258.         //           -1  is a variable  number of arguments.
  259.         // class: The reference, value or array class of the function args.
  260.         // vol:   The function is volatile.
  261.         //
  262.         $this->_functions array(
  263.               // function                  ptg  args  class  vol
  264.               'COUNT'           => array(   0,   -1,    0,    ),
  265.               'IF'              => array(   1,   -1,    1,    ),
  266.               'ISNA'            => array(   2,    1,    1,    ),
  267.               'ISERROR'         => array(   3,    1,    1,    ),
  268.               'SUM'             => array(   4,   -1,    0,    ),
  269.               'AVERAGE'         => array(   5,   -1,    0,    ),
  270.               'MIN'             => array(   6,   -1,    0,    ),
  271.               'MAX'             => array(   7,   -1,    0,    ),
  272.               'ROW'             => array(   8,   -1,    0,    ),
  273.               'COLUMN'          => array(   9,   -1,    0,    ),
  274.               'NA'              => array(  10,    0,    0,    ),
  275.               'NPV'             => array(  11,   -1,    1,    ),
  276.               'STDEV'           => array(  12,   -1,    0,    ),
  277.               'DOLLAR'          => array(  13,   -1,    1,    ),
  278.               'FIXED'           => array(  14,   -1,    1,    ),
  279.               'SIN'             => array(  15,    1,    1,    ),
  280.               'COS'             => array(  16,    1,    1,    ),
  281.               'TAN'             => array(  17,    1,    1,    ),
  282.               'ATAN'            => array(  18,    1,    1,    ),
  283.               'PI'              => array(  19,    0,    1,    ),
  284.               'SQRT'            => array(  20,    1,    1,    ),
  285.               'EXP'             => array(  21,    1,    1,    ),
  286.               'LN'              => array(  22,    1,    1,    ),
  287.               'LOG10'           => array(  23,    1,    1,    ),
  288.               'ABS'             => array(  24,    1,    1,    ),
  289.               'INT'             => array(  25,    1,    1,    ),
  290.               'SIGN'            => array(  26,    1,    1,    ),
  291.               'ROUND'           => array(  27,    2,    1,    ),
  292.               'LOOKUP'          => array(  28,   -1,    0,    ),
  293.               'INDEX'           => array(  29,   -1,    0,    ),
  294.               'REPT'            => array(  30,    2,    1,    ),
  295.               'MID'             => array(  31,    3,    1,    ),
  296.               'LEN'             => array(  32,    1,    1,    ),
  297.               'VALUE'           => array(  33,    1,    1,    ),
  298.               'TRUE'            => array(  34,    0,    1,    ),
  299.               'FALSE'           => array(  35,    0,    1,    ),
  300.               'AND'             => array(  36,   -1,    0,    ),
  301.               'OR'              => array(  37,   -1,    0,    ),
  302.               'NOT'             => array(  38,    1,    1,    ),
  303.               'MOD'             => array(  39,    2,    1,    ),
  304.               'DCOUNT'          => array(  40,    3,    0,    ),
  305.               'DSUM'            => array(  41,    3,    0,    ),
  306.               'DAVERAGE'        => array(  42,    3,    0,    ),
  307.               'DMIN'            => array(  43,    3,    0,    ),
  308.               'DMAX'            => array(  44,    3,    0,    ),
  309.               'DSTDEV'          => array(  45,    3,    0,    ),
  310.               'VAR'             => array(  46,   -1,    0,    ),
  311.               'DVAR'            => array(  47,    3,    0,    ),
  312.               'TEXT'            => array(  48,    2,    1,    ),
  313.               'LINEST'          => array(  49,   -1,    0,    ),
  314.               'TREND'           => array(  50,   -1,    0,    ),
  315.               'LOGEST'          => array(  51,   -1,    0,    ),
  316.               'GROWTH'          => array(  52,   -1,    0,    ),
  317.               'PV'              => array(  56,   -1,    1,    ),
  318.               'FV'              => array(  57,   -1,    1,    ),
  319.               'NPER'            => array(  58,   -1,    1,    ),
  320.               'PMT'             => array(  59,   -1,    1,    ),
  321.               'RATE'            => array(  60,   -1,    1,    ),
  322.               'MIRR'            => array(  61,    3,    0,    ),
  323.               'IRR'             => array(  62,   -1,    0,    ),
  324.               'RAND'            => array(  63,    0,    1,    ),
  325.               'MATCH'           => array(  64,   -1,    0,    ),
  326.               'DATE'            => array(  65,    3,    1,    ),
  327.               'TIME'            => array(  66,    3,    1,    ),
  328.               'DAY'             => array(  67,    1,    1,    ),
  329.               'MONTH'           => array(  68,    1,    1,    ),
  330.               'YEAR'            => array(  69,    1,    1,    ),
  331.               'WEEKDAY'         => array(  70,   -1,    1,    ),
  332.               'HOUR'            => array(  71,    1,    1,    ),
  333.               'MINUTE'          => array(  72,    1,    1,    ),
  334.               'SECOND'          => array(  73,    1,    1,    ),
  335.               'NOW'             => array(  74,    0,    1,    ),
  336.               'AREAS'           => array(  75,    1,    0,    ),
  337.               'ROWS'            => array(  76,    1,    0,    ),
  338.               'COLUMNS'         => array(  77,    1,    0,    ),
  339.               'OFFSET'          => array(  78,   -1,    0,    ),
  340.               'SEARCH'          => array(  82,   -1,    1,    ),
  341.               'TRANSPOSE'       => array(  83,    1,    1,    ),
  342.               'TYPE'            => array(  86,    1,    1,    ),
  343.               'ATAN2'           => array(  97,    2,    1,    ),
  344.               'ASIN'            => array(  98,    1,    1,    ),
  345.               'ACOS'            => array(  99,    1,    1,    ),
  346.               'CHOOSE'          => array100,   -1,    1,    ),
  347.               'HLOOKUP'         => array101,   -1,    0,    ),
  348.               'VLOOKUP'         => array102,   -1,    0,    ),
  349.               'ISREF'           => array105,    1,    0,    ),
  350.               'LOG'             => array109,   -1,    1,    ),
  351.               'CHAR'            => array111,    1,    1,    ),
  352.               'LOWER'           => array112,    1,    1,    ),
  353.               'UPPER'           => array113,    1,    1,    ),
  354.               'PROPER'          => array114,    1,    1,    ),
  355.               'LEFT'            => array115,   -1,    1,    ),
  356.               'RIGHT'           => array116,   -1,    1,    ),
  357.               'EXACT'           => array117,    2,    1,    ),
  358.               'TRIM'            => array118,    1,    1,    ),
  359.               'REPLACE'         => array119,    4,    1,    ),
  360.               'SUBSTITUTE'      => array120,   -1,    1,    ),
  361.               'CODE'            => array121,    1,    1,    ),
  362.               'FIND'            => array124,   -1,    1,    ),
  363.               'CELL'            => array125,   -1,    0,    ),
  364.               'ISERR'           => array126,    1,    1,    ),
  365.               'ISTEXT'          => array127,    1,    1,    ),
  366.               'ISNUMBER'        => array128,    1,    1,    ),
  367.               'ISBLANK'         => array129,    1,    1,    ),
  368.               'T'               => array130,    1,    0,    ),
  369.               'N'               => array131,    1,    0,    ),
  370.               'DATEVALUE'       => array140,    1,    1,    ),
  371.               'TIMEVALUE'       => array141,    1,    1,    ),
  372.               'SLN'             => array142,    3,    1,    ),
  373.               'SYD'             => array143,    4,    1,    ),
  374.               'DDB'             => array144,   -1,    1,    ),
  375.               'INDIRECT'        => array148,   -1,    1,    ),
  376.               'CALL'            => array150,   -1,    1,    ),
  377.               'CLEAN'           => array162,    1,    1,    ),
  378.               'MDETERM'         => array163,    1,    2,    ),
  379.               'MINVERSE'        => array164,    1,    2,    ),
  380.               'MMULT'           => array165,    2,    2,    ),
  381.               'IPMT'            => array167,   -1,    1,    ),
  382.               'PPMT'            => array168,   -1,    1,    ),
  383.               'COUNTA'          => array169,   -1,    0,    ),
  384.               'PRODUCT'         => array183,   -1,    0,    ),
  385.               'FACT'            => array184,    1,    1,    ),
  386.               'DPRODUCT'        => array189,    3,    0,    ),
  387.               'ISNONTEXT'       => array190,    1,    1,    ),
  388.               'STDEVP'          => array193,   -1,    0,    ),
  389.               'VARP'            => array194,   -1,    0,    ),
  390.               'DSTDEVP'         => array195,    3,    0,    ),
  391.               'DVARP'           => array196,    3,    0,    ),
  392.               'TRUNC'           => array197,   -1,    1,    ),
  393.               'ISLOGICAL'       => array198,    1,    1,    ),
  394.               'DCOUNTA'         => array199,    3,    0,    ),
  395.               'USDOLLAR'        => array204,   -1,    1,    ),
  396.               'FINDB'           => array205,   -1,    1,    ),
  397.               'SEARCHB'         => array206,   -1,    1,    ),
  398.               'REPLACEB'        => array207,    4,    1,    ),
  399.               'LEFTB'           => array208,   -1,    1,    ),
  400.               'RIGHTB'          => array209,   -1,    1,    ),
  401.               'MIDB'            => array210,    3,    1,    ),
  402.               'LENB'            => array211,    1,    1,    ),
  403.               'ROUNDUP'         => array212,    2,    1,    ),
  404.               'ROUNDDOWN'       => array213,    2,    1,    ),
  405.               'ASC'             => array214,    1,    1,    ),
  406.               'DBCS'            => array215,    1,    1,    ),
  407.               'RANK'            => array216,   -1,    0,    ),
  408.               'ADDRESS'         => array219,   -1,    1,    ),
  409.               'DAYS360'         => array220,   -1,    1,    ),
  410.               'TODAY'           => array221,    0,    1,    ),
  411.               'VDB'             => array222,   -1,    1,    ),
  412.               'MEDIAN'          => array227,   -1,    0,    ),
  413.               'SUMPRODUCT'      => array228,   -1,    2,    ),
  414.               'SINH'            => array229,    1,    1,    ),
  415.               'COSH'            => array230,    1,    1,    ),
  416.               'TANH'            => array231,    1,    1,    ),
  417.               'ASINH'           => array232,    1,    1,    ),
  418.               'ACOSH'           => array233,    1,    1,    ),
  419.               'ATANH'           => array234,    1,    1,    ),
  420.               'DGET'            => array235,    3,    0,    ),
  421.               'INFO'            => array244,    1,    1,    ),
  422.               'DB'              => array247,   -1,    1,    ),
  423.               'FREQUENCY'       => array252,    2,    0,    ),
  424.               'ERROR.TYPE'      => array261,    1,    1,    ),
  425.               'REGISTER.ID'     => array267,   -1,    1,    ),
  426.               'AVEDEV'          => array269,   -1,    0,    ),
  427.               'BETADIST'        => array270,   -1,    1,    ),
  428.               'GAMMALN'         => array271,    1,    1,    ),
  429.               'BETAINV'         => array272,   -1,    1,    ),
  430.               'BINOMDIST'       => array273,    4,    1,    ),
  431.               'CHIDIST'         => array274,    2,    1,    ),
  432.               'CHIINV'          => array275,    2,    1,    ),
  433.               'COMBIN'          => array276,    2,    1,    ),
  434.               'CONFIDENCE'      => array277,    3,    1,    ),
  435.               'CRITBINOM'       => array278,    3,    1,    ),
  436.               'EVEN'            => array279,    1,    1,    ),
  437.               'EXPONDIST'       => array280,    3,    1,    ),
  438.               'FDIST'           => array281,    3,    1,    ),
  439.               'FINV'            => array282,    3,    1,    ),
  440.               'FISHER'          => array283,    1,    1,    ),
  441.               'FISHERINV'       => array284,    1,    1,    ),
  442.               'FLOOR'           => array285,    2,    1,    ),
  443.               'GAMMADIST'       => array286,    4,    1,    ),
  444.               'GAMMAINV'        => array287,    3,    1,    ),
  445.               'CEILING'         => array288,    2,    1,    ),
  446.               'HYPGEOMDIST'     => array289,    4,    1,    ),
  447.               'LOGNORMDIST'     => array290,    3,    1,    ),
  448.               'LOGINV'          => array291,    3,    1,    ),
  449.               'NEGBINOMDIST'    => array292,    3,    1,    ),
  450.               'NORMDIST'        => array293,    4,    1,    ),
  451.               'NORMSDIST'       => array294,    1,    1,    ),
  452.               'NORMINV'         => array295,    3,    1,    ),
  453.               'NORMSINV'        => array296,    1,    1,    ),
  454.               'STANDARDIZE'     => array297,    3,    1,    ),
  455.               'ODD'             => array298,    1,    1,    ),
  456.               'PERMUT'          => array299,    2,    1,    ),
  457.               'POISSON'         => array300,    3,    1,    ),
  458.               'TDIST'           => array301,    3,    1,    ),
  459.               'WEIBULL'         => array302,    4,    1,    ),
  460.               'SUMXMY2'         => array303,    2,    2,    ),
  461.               'SUMX2MY2'        => array304,    2,    2,    ),
  462.               'SUMX2PY2'        => array305,    2,    2,    ),
  463.               'CHITEST'         => array306,    2,    2,    ),
  464.               'CORREL'          => array307,    2,    2,    ),
  465.               'COVAR'           => array308,    2,    2,    ),
  466.               'FORECAST'        => array309,    3,    2,    ),
  467.               'FTEST'           => array310,    2,    2,    ),
  468.               'INTERCEPT'       => array311,    2,    2,    ),
  469.               'PEARSON'         => array312,    2,    2,    ),
  470.               'RSQ'             => array313,    2,    2,    ),
  471.               'STEYX'           => array314,    2,    2,    ),
  472.               'SLOPE'           => array315,    2,    2,    ),
  473.               'TTEST'           => array316,    4,    2,    ),
  474.               'PROB'            => array317,   -1,    2,    ),
  475.               'DEVSQ'           => array318,   -1,    0,    ),
  476.               'GEOMEAN'         => array319,   -1,    0,    ),
  477.               'HARMEAN'         => array320,   -1,    0,    ),
  478.               'SUMSQ'           => array321,   -1,    0,    ),
  479.               'KURT'            => array322,   -1,    0,    ),
  480.               'SKEW'            => array323,   -1,    0,    ),
  481.               'ZTEST'           => array324,   -1,    0,    ),
  482.               'LARGE'           => array325,    2,    0,    ),
  483.               'SMALL'           => array326,    2,    0,    ),
  484.               'QUARTILE'        => array327,    2,    0,    ),
  485.               'PERCENTILE'      => array328,    2,    0,    ),
  486.               'PERCENTRANK'     => array329,   -1,    0,    ),
  487.               'MODE'            => array330,   -1,    2,    ),
  488.               'TRIMMEAN'        => array331,    2,    0,    ),
  489.               'TINV'            => array332,    2,    1,    ),
  490.               'CONCATENATE'     => array336,   -1,    1,    ),
  491.               'POWER'           => array337,    2,    1,    ),
  492.               'RADIANS'         => array342,    1,    1,    ),
  493.               'DEGREES'         => array343,    1,    1,    ),
  494.               'SUBTOTAL'        => array344,   -1,    0,    ),
  495.               'SUMIF'           => array345,   -1,    0,    ),
  496.               'COUNTIF'         => array346,    2,    0,    ),
  497.               'COUNTBLANK'      => array347,    1,    0,    ),
  498.               'ISPMT'           => array350,    4,    1,    ),
  499.               'DATEDIF'         => array351,    3,    1,    ),
  500.               'DATESTRING'      => array352,    1,    1,    ),
  501.               'NUMBERSTRING'    => array353,    2,    1,    ),
  502.               'ROMAN'           => array354,   -1,    1,    ),
  503.               'GETPIVOTDATA'    => array358,   -1,    0,    ),
  504.               'HYPERLINK'       => array359,   -1,    1,    ),
  505.               'PHONETIC'        => array360,    1,    0,    ),
  506.               'AVERAGEA'        => array361,   -1,    0,    ),
  507.               'MAXA'            => array362,   -1,    0,    ),
  508.               'MINA'            => array363,   -1,    0,    ),
  509.               'STDEVPA'         => array364,   -1,    0,    ),
  510.               'VARPA'           => array365,   -1,    0,    ),
  511.               'STDEVA'          => array366,   -1,    0,    ),
  512.               'VARA'            => array367,   -1,    0,    ),
  513.               );
  514.     }
  515.  
  516.     /**
  517.      * Convert a token to the proper ptg value.
  518.      *
  519.      * @access private
  520.      * @param mixed $token The token to convert.
  521.      * @return mixed the converted token on success
  522.      */
  523.     function _convert($token)
  524.     {
  525.         if (preg_match("/^\"[^\"]{0,255}\"$/"$token)) {
  526.             return $this->_convertString($token);
  527.  
  528.         elseif (is_numeric($token)) {
  529.             return $this->_convertNumber($token);
  530.  
  531.         // match references like A1 or $A$1
  532.         elseif (preg_match('/^\$?([A-Ia-i]?[A-Za-z])\$?(\d+)$/',$token)) {
  533.             return $this->_convertRef2d($token);
  534.  
  535.         // match external references like Sheet1!A1 or Sheet1:Sheet2!A1 or Sheet1!$A$1 or Sheet1:Sheet2!$A$1
  536.         elseif (preg_match("/^\w+(\:\w+)?\!\\$?[A-Ia-i]?[A-Za-z]\\$?(\d+)$/u",$token)) {
  537.             return $this->_convertRef3d($token);
  538.  
  539.         // match external references like 'Sheet1'!A1 or 'Sheet1:Sheet2'!A1 or 'Sheet1'!$A$1 or 'Sheet1:Sheet2'!$A$1
  540.         elseif (preg_match("/^'[\w -]+(\:[\w -]+)?'\!\\$?[A-Ia-i]?[A-Za-z]\\$?(\d+)$/u",$token)) {
  541.             return $this->_convertRef3d($token);
  542.  
  543.         // match ranges like A1:B2
  544.         elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)\:(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)$/",$token)) {
  545.             return $this->_convertRange2d($token);
  546.  
  547.         // match ranges like A1..B2
  548.         elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?(\d+)$/",$token)) {
  549.             return $this->_convertRange2d($token);
  550.  
  551.         // match external ranges like Sheet1!A1:B2 or Sheet1:Sheet2!A1:B2 or Sheet1!$A$1:$B$2 or Sheet1:Sheet2!$A$1:$B$2
  552.         elseif (preg_match("/^\w+(\:\w+)?\!\\$?([A-Ia-i]?[A-Za-z])?\\$?(\d+)\:\\$?([A-Ia-i]?[A-Za-z])?\\$?(\d+)$/u",$token)) {
  553.             return $this->_convertRange3d($token);
  554.  
  555.         // match external ranges like 'Sheet1'!A1:B2 or 'Sheet1:Sheet2'!A1:B2 or 'Sheet1'!$A$1:$B$2 or 'Sheet1:Sheet2'!$A$1:$B$2
  556.         elseif (preg_match("/^'[\w -]+(\:[\w -]+)?'\!\\$?([A-Ia-i]?[A-Za-z])?\\$?(\d+)\:\\$?([A-Ia-i]?[A-Za-z])?\\$?(\d+)$/u",$token)) {
  557.             return $this->_convertRange3d($token);
  558.  
  559.         // operators (including parentheses)
  560.         elseif (isset($this->ptg[$token])) {
  561.             return pack("C"$this->ptg[$token]);
  562.  
  563.         // commented so argument number can be processed correctly. See toReversePolish().
  564.         /*elseif (preg_match("/[A-Z0-9\xc0-\xdc\.]+/",$token))
  565.         {
  566.             return($this->_convertFunction($token,$this->_func_args));
  567.         }*/
  568.  
  569.         // if it's an argument, ignore the token (the argument remains)
  570.         elseif ($token == 'arg'{
  571.             return '';
  572.         }
  573.         // TODO: use real error codes
  574.         throw new Exception("Unknown token $token");
  575.     }
  576.  
  577.     /**
  578.      * Convert a number token to ptgInt or ptgNum
  579.      *
  580.      * @access private
  581.      * @param mixed $num an integer or double for conversion to its ptg value
  582.      */
  583.     function _convertNumber($num)
  584.     {
  585.         // Integer in the range 0..2**16-1
  586.         if ((preg_match("/^\d+$/"$num)) and ($num <= 65535)) {
  587.             return pack("Cv"$this->ptg['ptgInt']$num);
  588.         else // A float
  589.             if (PHPExcel_Writer_Excel5_BIFFwriter::getByteOrder()) // if it's Big Endian
  590.                 $num strrev($num);
  591.             }
  592.             return pack("Cd"$this->ptg['ptgNum']$num);
  593.         }
  594.     }
  595.  
  596.     /**
  597.      * Convert a string token to ptgStr
  598.      *
  599.      * @access private
  600.      * @param string $string A string for conversion to its ptg value.
  601.      * @return mixed the converted token on success
  602.      */
  603.     function _convertString($string)
  604.     {
  605.         // chop away beggining and ending quotes
  606.         $string substr($string1strlen($string2);
  607.         if (strlen($string255{
  608.             throw new Exception("String is too long");
  609.         }
  610.  
  611.         if ($this->_BIFF_version == 0x0500{
  612.             return pack("CC"$this->ptg['ptgStr']strlen($string)).$string;
  613.         elseif ($this->_BIFF_version == 0x0600{
  614.             return pack('C'$this->ptg['ptgStr']PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort($string);
  615.         }
  616.     }
  617.  
  618.     /**
  619.      * Convert a function to a ptgFunc or ptgFuncVarV depending on the number of
  620.      * args that it takes.
  621.      *
  622.      * @access private
  623.      * @param string  $token    The name of the function for convertion to ptg value.
  624.      * @param integer $num_args The number of arguments the function receives.
  625.      * @return string The packed ptg for the function
  626.      */
  627.     function _convertFunction($token$num_args)
  628.     {
  629.         $args     $this->_functions[$token][1];
  630.         $volatile $this->_functions[$token][3];
  631.  
  632.         // Fixed number of args eg. TIME($i,$j,$k).
  633.         if ($args >= 0{
  634.             return pack("Cv"$this->ptg['ptgFuncV']$this->_functions[$token][0]);
  635.         }
  636.         // Variable number of args eg. SUM($i,$j,$k, ..).
  637.         if ($args == -1{
  638.             return pack("CCv"$this->ptg['ptgFuncVarV']$num_args$this->_functions[$token][0]);
  639.         }
  640.     }
  641.  
  642.     /**
  643.      * Convert an Excel range such as A1:D4 to a ptgRefV.
  644.      *
  645.      * @access private
  646.      * @param string $range An Excel range in the A1:A2 or A1..A2 format.
  647.      */
  648.     function _convertRange2d($range$class=0)
  649.     {
  650.  
  651.         // TODO: possible class value 0,1,2 check Formula.pm
  652.         // Split the range into 2 cell refs
  653.         if (preg_match("/^([A-Ia-i]?[A-Za-z])(\d+)\:([A-Ia-i]?[A-Za-z])(\d+)$/"$range)) {
  654.             list($cell1$cell2explode(':'$range);
  655.         elseif (preg_match("/^([A-Ia-i]?[A-Za-z])(\d+)\.\.([A-Ia-i]?[A-Za-z])(\d+)$/"$range)) {
  656.             list($cell1$cell2explode('..'$range);
  657.  
  658.         else {
  659.             // TODO: use real error codes
  660.             throw new Exception("Unknown range separator");
  661.         }
  662.  
  663.         // Convert the cell references
  664.         $cell_array1 $this->_cellToPackedRowcol($cell1);
  665.         list($row1$col1$cell_array1;
  666.         $cell_array2 $this->_cellToPackedRowcol($cell2);
  667.         list($row2$col2$cell_array2;
  668.  
  669.         // The ptg value depends on the class of the ptg.
  670.         if ($class == 0{
  671.             $ptgArea pack("C"$this->ptg['ptgArea']);
  672.         elseif ($class == 1{
  673.             $ptgArea pack("C"$this->ptg['ptgAreaV']);
  674.         elseif ($class == 2{
  675.             $ptgArea pack("C"$this->ptg['ptgAreaA']);
  676.         else {
  677.             // TODO: use real error codes
  678.             throw new Exception("Unknown class $class");
  679.         }
  680.         return $ptgArea $row1 $row2 $col1$col2;
  681.     }
  682.  
  683.     /**
  684.      * Convert an Excel 3d range such as "Sheet1!A1:D4" or "Sheet1:Sheet2!A1:D4" to
  685.      * a ptgArea3d.
  686.      *
  687.      * @access private
  688.      * @param string $token An Excel range in the Sheet1!A1:A2 format.
  689.      * @return mixed The packed ptgArea3d token on success.
  690.      */
  691.     function _convertRange3d($token)
  692.     {
  693.         $class 2// as far as I know, this is magick.
  694.  
  695.         // Split the ref at the ! symbol
  696.         list($ext_ref$rangeexplode('!'$token);
  697.  
  698.         // Convert the external reference part (different for BIFF8)
  699.         if ($this->_BIFF_version == 0x0500{
  700.             $ext_ref $this->_packExtRef($ext_ref);
  701.         elseif ($this->_BIFF_version == 0x0600{
  702.              $ext_ref $this->_getRefIndex($ext_ref);
  703.         }
  704.  
  705.         // Split the range into 2 cell refs
  706.         list($cell1$cell2explode(':'$range);
  707.  
  708.         // Convert the cell references
  709.         if (preg_match("/^(\\$)?[A-Ia-i]?[A-Za-z](\\$)?(\d+)$/"$cell1)) {
  710.             $cell_array1 $this->_cellToPackedRowcol($cell1);
  711.             list($row1$col1$cell_array1;
  712.             $cell_array2 $this->_cellToPackedRowcol($cell2);
  713.             list($row2$col2$cell_array2;
  714.         else // It's a rows range (like 26:27)
  715.              $cells_array $this->_rangeToPackedRange($cell1.':'.$cell2);
  716.              list($row1$col1$row2$col2$cells_array;
  717.         }
  718.  
  719.         // The ptg value depends on the class of the ptg.
  720.         if ($class == 0{
  721.             $ptgArea pack("C"$this->ptg['ptgArea3d']);
  722.         elseif ($class == 1{
  723.             $ptgArea pack("C"$this->ptg['ptgArea3dV']);
  724.         elseif ($class == 2{
  725.             $ptgArea pack("C"$this->ptg['ptgArea3dA']);
  726.         else {
  727.             throw new Exception("Unknown class $class");
  728.         }
  729.  
  730.         return $ptgArea $ext_ref $row1 $row2 $col1$col2;
  731.     }
  732.  
  733.     /**
  734.      * Convert an Excel reference such as A1, $B2, C$3 or $D$4 to a ptgRefV.
  735.      *
  736.      * @access private
  737.      * @param string $cell An Excel cell reference
  738.      * @return string The cell in packed() format with the corresponding ptg
  739.      */
  740.     function _convertRef2d($cell)
  741.     {
  742.         $class 2// as far as I know, this is magick.
  743.  
  744.         // Convert the cell reference
  745.         $cell_array $this->_cellToPackedRowcol($cell);
  746.         list($row$col$cell_array;
  747.  
  748.         // The ptg value depends on the class of the ptg.
  749.         if ($class == 0{
  750.             $ptgRef pack("C"$this->ptg['ptgRef']);
  751.         elseif ($class == 1{
  752.             $ptgRef pack("C"$this->ptg['ptgRefV']);
  753.         elseif ($class == 2{
  754.             $ptgRef pack("C"$this->ptg['ptgRefA']);
  755.         else {
  756.             // TODO: use real error codes
  757.             throw new Exception("Unknown class $class");
  758.         }
  759.         return $ptgRef.$row.$col;
  760.     }
  761.  
  762.     /**
  763.      * Convert an Excel 3d reference such as "Sheet1!A1" or "Sheet1:Sheet2!A1" to a
  764.      * ptgRef3d.
  765.      *
  766.      * @access private
  767.      * @param string $cell An Excel cell reference
  768.      * @return mixed The packed ptgRef3d token on success.
  769.      */
  770.     function _convertRef3d($cell)
  771.     {
  772.         $class 2// as far as I know, this is magick.
  773.  
  774.         // Split the ref at the ! symbol
  775.         list($ext_ref$cellexplode('!'$cell);
  776.  
  777.         // Convert the external reference part (different for BIFF8)
  778.         if ($this->_BIFF_version == 0x0500{
  779.             $ext_ref $this->_packExtRef($ext_ref);
  780.         elseif ($this->_BIFF_version == 0x0600{
  781.             $ext_ref $this->_getRefIndex($ext_ref);
  782.         }
  783.  
  784.         // Convert the cell reference part
  785.         list($row$col$this->_cellToPackedRowcol($cell);
  786.  
  787.         // The ptg value depends on the class of the ptg.
  788.         if ($class == 0{
  789.             $ptgRef pack("C"$this->ptg['ptgRef3d']);
  790.         elseif ($class == 1{
  791.             $ptgRef pack("C"$this->ptg['ptgRef3dV']);
  792.         elseif ($class == 2{
  793.             $ptgRef pack("C"$this->ptg['ptgRef3dA']);
  794.         else {
  795.             throw new Exception("Unknown class $class");
  796.         }
  797.  
  798.         return $ptgRef $ext_ref$row $col;
  799.     }
  800.  
  801.     /**
  802.      * Convert the sheet name part of an external reference, for example "Sheet1" or
  803.      * "Sheet1:Sheet2", to a packed structure.
  804.      *
  805.      * @access private
  806.      * @param string $ext_ref The name of the external reference
  807.      * @return string The reference index in packed() format
  808.      */
  809.     function _packExtRef($ext_ref)
  810.     {
  811.         $ext_ref preg_replace("/^'/"''$ext_ref)// Remove leading  ' if any.
  812.         $ext_ref preg_replace("/'$/"''$ext_ref)// Remove trailing ' if any.
  813.  
  814.         // Check if there is a sheet range eg., Sheet1:Sheet2.
  815.         if (preg_match("/:/"$ext_ref)) {
  816.             list($sheet_name1$sheet_name2explode(':'$ext_ref);
  817.  
  818.             $sheet1 $this->_getSheetIndex($sheet_name1);
  819.             if ($sheet1 == -1{
  820.                 throw new Exception("Unknown sheet name $sheet_name1 in formula");
  821.             }
  822.             $sheet2 $this->_getSheetIndex($sheet_name2);
  823.             if ($sheet2 == -1{
  824.                 throw new Exception("Unknown sheet name $sheet_name2 in formula");
  825.             }
  826.  
  827.             // Reverse max and min sheet numbers if necessary
  828.             if ($sheet1 $sheet2{
  829.                 list($sheet1$sheet2array($sheet2$sheet1);
  830.             }
  831.         else // Single sheet name only.
  832.             $sheet1 $this->_getSheetIndex($ext_ref);
  833.             if ($sheet1 == -1{
  834.                 throw new Exception("Unknown sheet name $ext_ref in formula");
  835.             }
  836.             $sheet2 $sheet1;
  837.         }
  838.  
  839.         // References are stored relative to 0xFFFF.
  840.         $offset = -$sheet1;
  841.  
  842.         return pack('vdvv'$offset0x00$sheet1$sheet2);
  843.     }
  844.  
  845.     /**
  846.      * Look up the REF index that corresponds to an external sheet name
  847.      * (or range). If it doesn't exist yet add it to the workbook's references
  848.      * array. It assumes all sheet names given must exist.
  849.      *
  850.      * @access private
  851.      * @param string $ext_ref The name of the external reference
  852.      * @return mixed The reference index in packed() format on success
  853.      */
  854.     function _getRefIndex($ext_ref)
  855.     {
  856.         $ext_ref preg_replace("/^'/"''$ext_ref)// Remove leading  ' if any.
  857.         $ext_ref preg_replace("/'$/"''$ext_ref)// Remove trailing ' if any.
  858.  
  859.         // Check if there is a sheet range eg., Sheet1:Sheet2.
  860.         if (preg_match("/:/"$ext_ref)) {
  861.             list($sheet_name1$sheet_name2explode(':'$ext_ref);
  862.  
  863.             $sheet1 $this->_getSheetIndex($sheet_name1);
  864.             if ($sheet1 == -1{
  865.                 throw new Exception("Unknown sheet name $sheet_name1 in formula");
  866.             }
  867.             $sheet2 $this->_getSheetIndex($sheet_name2);
  868.             if ($sheet2 == -1{
  869.                 throw new Exception("Unknown sheet name $sheet_name2 in formula");
  870.             }
  871.  
  872.             // Reverse max and min sheet numbers if necessary
  873.             if ($sheet1 $sheet2{
  874.                 list($sheet1$sheet2array($sheet2$sheet1);
  875.             }
  876.         else // Single sheet name only.
  877.             $sheet1 $this->_getSheetIndex($ext_ref);
  878.             if ($sheet1 == -1{
  879.                 throw new Exception("Unknown sheet name $ext_ref in formula");
  880.             }
  881.             $sheet2 $sheet1;
  882.         }
  883.  
  884.         // assume all references belong to this document
  885.         $supbook_index 0x00;
  886.         $ref pack('vvv'$supbook_index$sheet1$sheet2);
  887.         $total_references count($this->_references);
  888.         $index = -1;
  889.         for ($i 0$i $total_references++$i{
  890.             if ($ref == $this->_references[$i]{
  891.                 $index $i;
  892.                 break;
  893.             }
  894.         }
  895.         // if REF was not found add it to references array
  896.         if ($index == -1{
  897.             $this->_references[$total_references$ref;
  898.             $index $total_references;
  899.         }
  900.  
  901.         return pack('v'$index);
  902.     }
  903.  
  904.     /**
  905.      * Look up the index that corresponds to an external sheet name. The hash of
  906.      * sheet names is updated by the addworksheet() method of the
  907.      * PHPExcel_Writer_Excel5_Workbook class.
  908.      *
  909.      * @access private
  910.      * @return integer The sheet index, -1 if the sheet was not found
  911.      */
  912.     function _getSheetIndex($sheet_name)
  913.     {
  914.         if (!isset($this->_ext_sheets[$sheet_name])) {
  915.             return -1;
  916.         else {
  917.             return $this->_ext_sheets[$sheet_name];
  918.         }
  919.     }
  920.  
  921.     /**
  922.      * This method is used to update the array of sheet names. It is
  923.      * called by the addWorksheet() method of the
  924.      * PHPExcel_Writer_Excel5_Workbook class.
  925.      *
  926.      * @access public
  927.      * @see PHPExcel_Writer_Excel5_Workbook::addWorksheet()
  928.      * @param string  $name  The name of the worksheet being added
  929.      * @param integer $index The index of the worksheet being added
  930.      */
  931.     function setExtSheet($name$index)
  932.     {
  933.         $this->_ext_sheets[$name$index;
  934.     }
  935.  
  936.     /**
  937.      * pack() row and column into the required 3 or 4 byte format.
  938.      *
  939.      * @access private
  940.      * @param string $cell The Excel cell reference to be packed
  941.      * @return array Array containing the row and column in packed() format
  942.      */
  943.     function _cellToPackedRowcol($cell)
  944.     {
  945.         $cell strtoupper($cell);
  946.         list($row$col$row_rel$col_rel$this->_cellToRowcol($cell);
  947.         if ($col >= 256{
  948.             throw new Exception("Column in: $cell greater than 255");
  949.         }
  950.         // FIXME: change for BIFF8
  951.         if ($row >= 16384{
  952.             throw new Exception("Row in: $cell greater than 16384 ");
  953.         }
  954.  
  955.         // Set the high bits to indicate if row or col are relative.
  956.         if ($this->_BIFF_version == 0x0500{
  957.             $row    |= $col_rel << 14;
  958.             $row    |= $row_rel << 15;
  959.             $col     pack('C'$col);
  960.         elseif ($this->_BIFF_version == 0x0600{
  961.             $col    |= $col_rel << 14;
  962.             $col    |= $row_rel << 15;
  963.             $col     pack('v'$col);
  964.         }
  965.         $row     pack('v'$row);
  966.  
  967.         return array($row$col);
  968.     }
  969.  
  970.     /**
  971.      * pack() row range into the required 3 or 4 byte format.
  972.      * Just using maximum col/rows, which is probably not the correct solution
  973.      *
  974.      * @access private
  975.      * @param string $range The Excel range to be packed
  976.      * @return array Array containing (row1,col1,row2,col2) in packed() format
  977.      */
  978.     function _rangeToPackedRange($range)
  979.     {
  980.         preg_match('/(\$)?(\d+)\:(\$)?(\d+)/'$range$match);
  981.         // return absolute rows if there is a $ in the ref
  982.         $row1_rel empty($match[1]0;
  983.         $row1     $match[2];
  984.         $row2_rel empty($match[3]0;
  985.         $row2     $match[4];
  986.         // Convert 1-index to zero-index
  987.         --$row1;
  988.         --$row2;
  989.         // Trick poor inocent Excel
  990.         $col1 0;
  991.         $col2 16383// FIXME: maximum possible value for Excel 5 (change this!!!)
  992.  
  993.         // FIXME: this changes for BIFF8
  994.         if (($row1 >= 16384or ($row2 >= 16384)) {
  995.             throw new Exception("Row in: $range greater than 16384 ");
  996.         }
  997.  
  998.         // Set the high bits to indicate if rows are relative.
  999.         if ($this->_BIFF_version == 0x0500{
  1000.             $row1    |= $row1_rel << 14// FIXME: probably a bug
  1001.             $row2    |= $row2_rel << 15;
  1002.             $col1     pack('C'$col1);
  1003.             $col2     pack('C'$col2);
  1004.         elseif ($this->_BIFF_version == 0x0600{
  1005.             $col1    |= $row1_rel << 15;
  1006.             $col2    |= $row2_rel << 15;
  1007.             $col1     pack('v'$col1);
  1008.             $col2     pack('v'$col2);
  1009.         }
  1010.         $row1     pack('v'$row1);
  1011.         $row2     pack('v'$row2);
  1012.  
  1013.         return array($row1$col1$row2$col2);
  1014.     }
  1015.  
  1016.     /**
  1017.      * Convert an Excel cell reference such as A1 or $B2 or C$3 or $D$4 to a zero
  1018.      * indexed row and column number. Also returns two (0,1) values to indicate
  1019.      * whether the row or column are relative references.
  1020.      *
  1021.      * @access private
  1022.      * @param string $cell The Excel cell reference in A1 format.
  1023.      * @return array 
  1024.      */
  1025.     function _cellToRowcol($cell)
  1026.     {
  1027.         preg_match('/(\$)?([A-I]?[A-Z])(\$)?(\d+)/',$cell,$match);
  1028.         // return absolute column if there is a $ in the ref
  1029.         $col_rel empty($match[1]0;
  1030.         $col_ref $match[2];
  1031.         $row_rel empty($match[3]0;
  1032.         $row     $match[4];
  1033.  
  1034.         // Convert base26 column string to a number.
  1035.         $expn   strlen($col_ref1;
  1036.         $col    0;
  1037.         $col_ref_length strlen($col_ref);
  1038.         for ($i 0$i $col_ref_length++$i{
  1039.             $col += (ord($col_ref{$i}ord('A'1pow(26$expn);
  1040.             --$expn;
  1041.         }
  1042.  
  1043.         // Convert 1-index to zero-index
  1044.         --$row;
  1045.         --$col;
  1046.  
  1047.         return array($row$col$row_rel$col_rel);
  1048.     }
  1049.  
  1050.     /**
  1051.      * Advance to the next valid token.
  1052.      *
  1053.      * @access private
  1054.      */
  1055.     function _advance()
  1056.     {
  1057.         $i $this->_current_char;
  1058.         $formula_length strlen($this->_formula);
  1059.         // eat up white spaces
  1060.         if ($i $formula_length{
  1061.             while ($this->_formula{$i== " "{
  1062.                 ++$i;
  1063.             }
  1064.  
  1065.             if ($i ($formula_length 1)) {
  1066.                 $this->_lookahead = $this->_formula{$i+1};
  1067.             }
  1068.             $token '';
  1069.         }
  1070.  
  1071.         while ($i $formula_length{
  1072.             $token .= $this->_formula{$i};
  1073.             if ($i ($formula_length 1)) {
  1074.                 $this->_lookahead $this->_formula{$i+1};
  1075.             else {
  1076.                 $this->_lookahead '';
  1077.             }
  1078.  
  1079.             if ($this->_match($token!= ''{
  1080.                 //if ($i < strlen($this->_formula) - 1) {
  1081.                 //    $this->_lookahead = $this->_formula{$i+1};
  1082.                 //}
  1083.                 $this->_current_char $i 1;
  1084.                 $this->_current_token $token;
  1085.                 return 1;
  1086.             }
  1087.  
  1088.             if ($i ($formula_length 2)) {
  1089.                 $this->_lookahead $this->_formula{$i+2};
  1090.             else // if we run out of characters _lookahead becomes empty
  1091.                 $this->_lookahead '';
  1092.             }
  1093.             ++$i;
  1094.         }
  1095.         //die("Lexical error ".$this->_current_char);
  1096.     }
  1097.  
  1098.     /**
  1099.      * Checks if it's a valid token.
  1100.      *
  1101.      * @access private
  1102.      * @param mixed $token The token to check.
  1103.      * @return mixed       The checked token or false on failure
  1104.      */
  1105.     function _match($token)
  1106.     {
  1107.         switch($token{
  1108.             case "+":
  1109.                 return $token;
  1110.                 break;
  1111.             case "-":
  1112.                 return $token;
  1113.                 break;
  1114.             case "*":
  1115.                 return $token;
  1116.                 break;
  1117.             case "/":
  1118.                 return $token;
  1119.                 break;
  1120.             case "(":
  1121.                 return $token;
  1122.                 break;
  1123.             case ")":
  1124.                 return $token;
  1125.                 break;
  1126.             case ",":
  1127.                 return $token;
  1128.                 break;
  1129.             case ";":
  1130.                 return $token;
  1131.                 break;
  1132.             case ">":
  1133.                 if ($this->_lookahead == '='// it's a GE token
  1134.                     break;
  1135.                 }
  1136.                 return $token;
  1137.                 break;
  1138.             case "<":
  1139.                 // it's a LE or a NE token
  1140.                 if (($this->_lookahead == '='or ($this->_lookahead == '>')) {
  1141.                     break;
  1142.                 }
  1143.                 return $token;
  1144.                 break;
  1145.             case ">=":
  1146.                 return $token;
  1147.                 break;
  1148.             case "<=":
  1149.                 return $token;
  1150.                 break;
  1151.             case "=":
  1152.                 return $token;
  1153.                 break;
  1154.             case "<>":
  1155.                 return $token;
  1156.                 break;
  1157.             default:
  1158.                 // if it's a reference
  1159.                 if (preg_match('/^\$?[A-Ia-i]?[A-Za-z]\$?[0-9]+$/',$tokenand
  1160.                    !preg_match("/[0-9]/",$this->_lookaheadand
  1161.                    ($this->_lookahead != ':'and ($this->_lookahead != '.'and
  1162.                    ($this->_lookahead != '!'))
  1163.                 {
  1164.                     return $token;
  1165.                 }
  1166.                 // If it's an external reference (Sheet1!A1 or Sheet1:Sheet2!A1 or Sheet1!$A$1 or Sheet1:Sheet2!$A$1)
  1167.                 elseif (preg_match("/^\w+(\:\w+)?\!\\$?[A-Ia-i]?[A-Za-z]\\$?[0-9]+$/u",$tokenand
  1168.                        !preg_match("/[0-9]/",$this->_lookaheadand
  1169.                        ($this->_lookahead != ':'and ($this->_lookahead != '.'))
  1170.                 {
  1171.                     return $token;
  1172.                 }
  1173.                 // If it's an external reference ('Sheet1'!A1 or 'Sheet1:Sheet2'!A1)
  1174.                 elseif (preg_match("/^'[\w -]+(\:[\w -]+)?'\!\\$?[A-Ia-i]?[A-Za-z]\\$?[0-9]+$/u",$tokenand
  1175.                        !preg_match("/[0-9]/",$this->_lookaheadand
  1176.                        ($this->_lookahead != ':'and ($this->_lookahead != '.'))
  1177.                 {
  1178.                     return $token;
  1179.                 }
  1180.                 // if it's a range (A1:A2)
  1181.                 elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$tokenand
  1182.                        !preg_match("/[0-9]/",$this->_lookahead))
  1183.                 {
  1184.                     return $token;
  1185.                 }
  1186.                 // if it's a range (A1..A2)
  1187.                 elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$tokenand
  1188.                        !preg_match("/[0-9]/",$this->_lookahead))
  1189.                 {
  1190.                     return $token;
  1191.                 }
  1192.                 // If it's an external range like Sheet1!A1:B2 or Sheet1:Sheet2!A1:B2 or Sheet1!$A$1:$B$2 or Sheet1:Sheet2!$A$1:$B$2
  1193.                 elseif (preg_match("/^\w+(\:\w+)?\!\\$?([A-Ia-i]?[A-Za-z])?\\$?[0-9]+:\\$?([A-Ia-i]?[A-Za-z])?\\$?[0-9]+$/u",$tokenand
  1194.                        !preg_match("/[0-9]/",$this->_lookahead))
  1195.                 {
  1196.                     return $token;
  1197.                 }
  1198.                 // If it's an external range like 'Sheet1'!A1:B2 or 'Sheet1:Sheet2'!A1:B2 or 'Sheet1'!$A$1:$B$2 or 'Sheet1:Sheet2'!$A$1:$B$2
  1199.                 elseif (preg_match("/^'[\w -]+(\:[\w -]+)?'\!\\$?([A-Ia-i]?[A-Za-z])?\\$?[0-9]+:\\$?([A-Ia-i]?[A-Za-z])?\\$?[0-9]+$/u",$tokenand
  1200.                        !preg_match("/[0-9]/",$this->_lookahead))
  1201.                 {
  1202.                     return $token;
  1203.                 }
  1204.                 // If it's a number (check that it's not a sheet name or range)
  1205.                 elseif (is_numeric($tokenand
  1206.                         (!is_numeric($token.$this->_lookaheador ($this->_lookahead == '')) and
  1207.                         ($this->_lookahead != '!'and ($this->_lookahead != ':'))
  1208.                 {
  1209.                     return $token;
  1210.                 }
  1211.                 // If it's a string (of maximum 255 characters)
  1212.                 elseif (preg_match("/^\"[^\"]{0,255}\"$/",$token))
  1213.                 {
  1214.                     return $token;
  1215.                 }
  1216.                 // if it's a function call
  1217.                 elseif (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/i",$tokenand ($this->_lookahead == "("))
  1218.                 {
  1219.                     return $token;
  1220.                 }
  1221.                 return '';
  1222.         }
  1223.     }
  1224.  
  1225.     /**
  1226.      * The parsing method. It parses a formula.
  1227.      *
  1228.      * @access public
  1229.      * @param string $formula The formula to parse, without the initial equal
  1230.      *                         sign (=).
  1231.      * @return mixed true on success
  1232.      */
  1233.     function parse($formula)
  1234.     {
  1235.         $this->_current_char 0;
  1236.         $this->_formula      $formula;
  1237.         $this->_lookahead    $formula{1};
  1238.         $this->_advance();
  1239.         $this->_parse_tree   $this->_condition();
  1240.         return true;
  1241.     }
  1242.  
  1243.     /**
  1244.      * It parses a condition. It assumes the following rule:
  1245.      * Cond -> Expr [(">" | "<") Expr]
  1246.      *
  1247.      * @access private
  1248.      * @return mixed The parsed ptg'd tree on success
  1249.      */
  1250.     function _condition()
  1251.     {
  1252.         $result $this->_expression();
  1253.         if ($this->_current_token == "<"{
  1254.             $this->_advance();
  1255.             $result2 $this->_expression();
  1256.             $result $this->_createTree('ptgLT'$result$result2);
  1257.         elseif ($this->_current_token == ">"{
  1258.             $this->_advance();
  1259.             $result2 $this->_expression();
  1260.             $result $this->_createTree('ptgGT'$result$result2);
  1261.         elseif ($this->_current_token == "<="{
  1262.             $this->_advance();
  1263.             $result2 $this->_expression();
  1264.             $result $this->_createTree('ptgLE'$result$result2);
  1265.         elseif ($this->_current_token == ">="{
  1266.             $this->_advance();
  1267.             $result2 $this->_expression();
  1268.             $result $this->_createTree('ptgGE'$result$result2);
  1269.         elseif ($this->_current_token == "="{
  1270.             $this->_advance();
  1271.             $result2 $this->_expression();
  1272.             $result $this->_createTree('ptgEQ'$result$result2);
  1273.         elseif ($this->_current_token == "<>"{
  1274.             $this->_advance();
  1275.             $result2 $this->_expression();
  1276.             $result $this->_createTree('ptgNE'$result$result2);
  1277.         }
  1278.         return $result;
  1279.     }
  1280.  
  1281.     /**
  1282.      * It parses a expression. It assumes the following rule:
  1283.      * Expr -> Term [("+" | "-") Term]
  1284.      *      -> "string"
  1285.      *      -> "-" Term
  1286.      *
  1287.      * @access private
  1288.      * @return mixed The parsed ptg'd tree on success
  1289.      */
  1290.     function _expression()
  1291.     {
  1292.         // If it's a string return a string node
  1293.         if (preg_match("/^\"[^\"]{0,255}\"$/"$this->_current_token)) {
  1294.             $result $this->_createTree($this->_current_token'''');
  1295.             $this->_advance();
  1296.             return $result;
  1297.         elseif ($this->_current_token == "-"{
  1298.             // catch "-" Term
  1299.             $this->_advance();
  1300.             $result2 $this->_expression();
  1301.             $result $this->_createTree('ptgUminus'$result2'');
  1302.             return $result;
  1303.         }
  1304.         $result $this->_term();
  1305.         while (($this->_current_token == "+"or
  1306.                ($this->_current_token == "-")) {
  1307.         /**/
  1308.             if ($this->_current_token == "+"{
  1309.                 $this->_advance();
  1310.                 $result2 $this->_term();
  1311.                 $result $this->_createTree('ptgAdd'$result$result2);
  1312.             else {
  1313.                 $this->_advance();
  1314.                 $result2 $this->_term();
  1315.                 $result $this->_createTree('ptgSub'$result$result2);
  1316.             }
  1317.         }
  1318.         return $result;
  1319.     }
  1320.  
  1321.     /**
  1322.      * This function just introduces a ptgParen element in the tree, so that Excel
  1323.      * doesn't get confused when working with a parenthesized formula afterwards.
  1324.      *
  1325.      * @access private
  1326.      * @see _fact()
  1327.      * @return array The parsed ptg'd tree
  1328.      */
  1329.     function _parenthesizedExpression()
  1330.     {
  1331.         $result $this->_createTree('ptgParen'$this->_expression()'');
  1332.         return $result;
  1333.     }
  1334.  
  1335.     /**
  1336.      * It parses a term. It assumes the following rule:
  1337.      * Term -> Fact [("*" | "/") Fact]
  1338.      *
  1339.      * @access private
  1340.      * @return mixed The parsed ptg'd tree on success
  1341.      */
  1342.     function _term()
  1343.     {
  1344.         $result $this->_fact();
  1345.         while (($this->_current_token == "*"or
  1346.                ($this->_current_token == "/")) {
  1347.         /**/
  1348.             if ($this->_current_token == "*"{
  1349.                 $this->_advance();
  1350.                 $result2 $this->_fact();
  1351.                 $result $this->_createTree('ptgMul'$result$result2);
  1352.             else {
  1353.                 $this->_advance();
  1354.                 $result2 $this->_fact();
  1355.                 $result $this->_createTree('ptgDiv'$result$result2);
  1356.             }
  1357.         }
  1358.         return $result;
  1359.     }
  1360.  
  1361.     /**
  1362.      * It parses a factor. It assumes the following rule:
  1363.      * Fact -> ( Expr )
  1364.      *       | CellRef
  1365.      *       | CellRange
  1366.      *       | Number
  1367.      *       | Function
  1368.      *
  1369.      * @access private
  1370.      * @return mixed The parsed ptg'd tree on success
  1371.      */
  1372.     function _fact()
  1373.     {
  1374.         if ($this->_current_token == "("{
  1375.             $this->_advance();         // eat the "("
  1376.             $result $this->_parenthesizedExpression();
  1377.             if ($this->_current_token != ")"{
  1378.                 throw new Exception("')' token expected.");
  1379.             }
  1380.             $this->_advance();         // eat the ")"
  1381.             return $result;
  1382.         }
  1383.         // if it's a reference
  1384.         if (preg_match('/^\$?[A-Ia-i]?[A-Za-z]\$?[0-9]+$/',$this->_current_token))
  1385.         {
  1386.             $result $this->_createTree($this->_current_token'''');
  1387.             $this->_advance();
  1388.             return $result;
  1389.         }
  1390.         // If it's an external reference (Sheet1!A1 or Sheet1:Sheet2!A1 or Sheet1!$A$1 or Sheet1:Sheet2!$A$1)
  1391.         elseif (preg_match("/^\w+(\:\w+)?\!\\$?[A-Ia-i]?[A-Za-z]\\$?[0-9]+$/u",$this->_current_token))
  1392.         {
  1393.             $result $this->_createTree($this->_current_token'''');
  1394.             $this->_advance();
  1395.             return $result;
  1396.         }
  1397.         // If it's an external reference ('Sheet1'!A1 or 'Sheet1:Sheet2'!A1 or 'Sheet1'!$A$1 or 'Sheet1:Sheet2'!$A$1)
  1398.         elseif (preg_match("/^'[\w -]+(\:[\w -]+)?'\!\\$?[A-Ia-i]?[A-Za-z]\\$?[0-9]+$/u",$this->_current_token))
  1399.         {
  1400.             $result $this->_createTree($this->_current_token'''');
  1401.             $this->_advance();
  1402.             return $result;
  1403.         }
  1404.         // if it's a range A1:B2 or $A$1:$B$2
  1405.         elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$this->_current_tokenor
  1406.                 preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$this->_current_token))
  1407.         {
  1408.             $result $this->_current_token;
  1409.             $this->_advance();
  1410.             return $result;
  1411.         }
  1412.         // If it's an external range (Sheet1!A1:B2 or Sheet1:Sheet2!A1:B2 or Sheet1!$A$1:$B$2 or Sheet1:Sheet2!$A$1:$B$2)
  1413.         elseif (preg_match("/^\w+(\:\w+)?\!\\$?([A-Ia-i]?[A-Za-z])?\\$?[0-9]+:\\$?([A-Ia-i]?[A-Za-z])?\\$?[0-9]+$/u",$this->_current_token))
  1414.         {
  1415.             // must be an error?
  1416.             //$result = $this->_current_token;
  1417.             $result $this->_createTree($this->_current_token'''');
  1418.             $this->_advance();
  1419.             return $result;
  1420.         }
  1421.         // If it's an external range ('Sheet1'!A1:B2 or 'Sheet1'!A1:B2 or 'Sheet1'!$A$1:$B$2 or 'Sheet1'!$A$1:$B$2)
  1422.         elseif (preg_match("/^'[\w -]+(\:[\w -]+)?'\!\\$?([A-Ia-i]?[A-Za-z])?\\$?[0-9]+:\\$?([A-Ia-i]?[A-Za-z])?\\$?[0-9]+$/u",$this->_current_token))
  1423.         {
  1424.             // must be an error?
  1425.             //$result = $this->_current_token;
  1426.             $result $this->_createTree($this->_current_token'''');
  1427.             $this->_advance();
  1428.             return $result;
  1429.         }
  1430.         elseif (is_numeric($this->_current_token))
  1431.         {
  1432.             $result $this->_createTree($this->_current_token'''');
  1433.             $this->_advance();
  1434.             return $result;
  1435.         }
  1436.         // if it's a function call
  1437.         elseif (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/i",$this->_current_token))
  1438.         {
  1439.             $result $this->_func();
  1440.             return $result;
  1441.         }
  1442.         throw new Exception("Syntax error: ".$this->_current_token.
  1443.                                  ", lookahead: ".$this->_lookahead.
  1444.                                  ", current char: ".$this->_current_char);
  1445.     }
  1446.  
  1447.     /**
  1448.      * It parses a function call. It assumes the following rule:
  1449.      * Func -> ( Expr [,Expr]* )
  1450.      *
  1451.      * @access private
  1452.      * @return mixed The parsed ptg'd tree on success
  1453.      */
  1454.     function _func()
  1455.     {
  1456.         $num_args 0// number of arguments received
  1457.         $function strtoupper($this->_current_token);
  1458.         $result   ''// initialize result
  1459.         $this->_advance();
  1460.         $this->_advance();         // eat the "("
  1461.         while ($this->_current_token != ')'{
  1462.         /**/
  1463.             if ($num_args 0{
  1464.                 if ($this->_current_token == "," or
  1465.                     $this->_current_token == ";")
  1466.                 {
  1467.                     $this->_advance();  // eat the "," or ";"
  1468.                 else {
  1469.                     throw new Exception("Syntax error: comma expected in ".
  1470.                                       "function $function, arg #{$num_args}");
  1471.                 }
  1472.                 $result2 $this->_condition();
  1473.                 $result $this->_createTree('arg'$result$result2);
  1474.             else // first argument
  1475.                 $result2 $this->_condition();
  1476.                 $result $this->_createTree('arg'''$result2);
  1477.             }
  1478.             ++$num_args;
  1479.         }
  1480.         if (!isset($this->_functions[$function])) {
  1481.             throw new Exception("Function $function() doesn't exist");
  1482.         }
  1483.         $args $this->_functions[$function][1];
  1484.         // If fixed number of args eg. TIME($i,$j,$k). Check that the number of args is valid.
  1485.         if (($args >= 0and ($args != $num_args)) {
  1486.             throw new Exception("Incorrect number of arguments in function $function() ");
  1487.         }
  1488.  
  1489.         $result $this->_createTree($function$result$num_args);
  1490.         $this->_advance();         // eat the ")"
  1491.         return $result;
  1492.     }
  1493.  
  1494.     /**
  1495.      * Creates a tree. In fact an array which may have one or two arrays (sub-trees)
  1496.      * as elements.
  1497.      *
  1498.      * @access private
  1499.      * @param mixed $value The value of this node.
  1500.      * @param mixed $left  The left array (sub-tree) or a final node.
  1501.      * @param mixed $right The right array (sub-tree) or a final node.
  1502.      * @return array A tree
  1503.      */
  1504.     function _createTree($value$left$right)
  1505.     {
  1506.         return array('value' => $value'left' => $left'right' => $right);
  1507.     }
  1508.  
  1509.     /**
  1510.      * Builds a string containing the tree in reverse polish notation (What you
  1511.      * would use in a HP calculator stack).
  1512.      * The following tree:
  1513.      *
  1514.      *    +
  1515.      *   / \
  1516.      *  2   3
  1517.      *
  1518.      * produces: "23+"
  1519.      *
  1520.      * The following tree:
  1521.      *
  1522.      *    +
  1523.      *   / \
  1524.      *  3   *
  1525.      *     / \
  1526.      *    6   A1
  1527.      *
  1528.      * produces: "36A1*+"
  1529.      *
  1530.      * In fact all operands, functions, references, etc... are written as ptg's
  1531.      *
  1532.      * @access public
  1533.      * @param array $tree The optional tree to convert.
  1534.      * @return string The tree in reverse polish notation
  1535.      */
  1536.     function toReversePolish($tree array())
  1537.     {
  1538.         $polish ""// the string we are going to return
  1539.         if (empty($tree)) // If it's the first call use _parse_tree
  1540.             $tree $this->_parse_tree;
  1541.         }
  1542.         if (is_array($tree['left'])) {
  1543.             $converted_tree $this->toReversePolish($tree['left']);
  1544.             $polish .= $converted_tree;
  1545.         elseif ($tree['left'!= ''// It's a final node
  1546.             $converted_tree $this->_convert($tree['left']);
  1547.             $polish .= $converted_tree;
  1548.         }
  1549.         if (is_array($tree['right'])) {
  1550.             $converted_tree $this->toReversePolish($tree['right']);
  1551.             $polish .= $converted_tree;
  1552.         elseif ($tree['right'!= ''// It's a final node
  1553.             $converted_tree $this->_convert($tree['right']);
  1554.             $polish .= $converted_tree;
  1555.         }
  1556.         // if it's a function convert it here (so we can set it's arguments)
  1557.         if (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/",$tree['value']and
  1558.             !preg_match('/^([A-Ia-i]?[A-Za-z])(\d+)$/',$tree['value']and
  1559.             !preg_match("/^[A-Ia-i]?[A-Za-z](\d+)\.\.[A-Ia-i]?[A-Za-z](\d+)$/",$tree['value']and
  1560.             !is_numeric($tree['value']and
  1561.             !isset($this->ptg[$tree['value']]))
  1562.         {
  1563.             // left subtree for a function is always an array.
  1564.             if ($tree['left'!= ''{
  1565.                 $left_tree $this->toReversePolish($tree['left']);
  1566.             else {
  1567.                 $left_tree '';
  1568.             }
  1569.             // add it's left subtree and return.
  1570.             return $left_tree.$this->_convertFunction($tree['value']$tree['right']);
  1571.         else {
  1572.             $converted_tree $this->_convert($tree['value']);
  1573.         }
  1574.         $polish .= $converted_tree;
  1575.         return $polish;
  1576.     }
  1577.  
  1578. }

Documentation generated on Mon, 11 Jan 2010 08:12:48 +0100 by phpDocumentor 1.4.1