File Source for Calculation.php

PHPExcel_Calculation

# Source for file Calculation.php

Documentation is available at Calculation.php

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

Documentation generated on Sun, 27 Feb 2011 16:28:53 -0800 by phpDocumentor 1.4.3