Calculation.php 198 KB

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