PageRenderTime 98ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/reports/promotion/output/plugins/PHPExcel/Calculation.php

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