Calculation.php 172 KB

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