PageRenderTime 38ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/add-ons/PHPExcel/PHPExcel/Calculation.php

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