PageRenderTime 39ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/geodata/modules/geodata/classes/PHPExcel/Calculation.php

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