PageRenderTime 81ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/common/libraries/plugin/phpexcel/PHPExcel/Calculation.php

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