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

/application/third_party/PHPExcel/Calculation.php

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