| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491 |
- <?php
- namespace PhpOffice\PhpSpreadsheet\Calculation;
- use PhpOffice\PhpSpreadsheet\Calculation\Engine\CyclicReferenceStack;
- use PhpOffice\PhpSpreadsheet\Calculation\Engine\Logger;
- use PhpOffice\PhpSpreadsheet\Calculation\Token\Stack;
- use PhpOffice\PhpSpreadsheet\Cell\Cell;
- use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
- use PhpOffice\PhpSpreadsheet\DefinedName;
- use PhpOffice\PhpSpreadsheet\ReferenceHelper;
- use PhpOffice\PhpSpreadsheet\Shared;
- use PhpOffice\PhpSpreadsheet\Spreadsheet;
- use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
- use ReflectionMethod;
- class Calculation
- {
- /** Constants */
- /** Regular Expressions */
- // Numeric operand
- const CALCULATION_REGEXP_NUMBER = '[-+]?\d*\.?\d+(e[-+]?\d+)?';
- // String operand
- const CALCULATION_REGEXP_STRING = '"(?:[^"]|"")*"';
- // Opening bracket
- const CALCULATION_REGEXP_OPENBRACE = '\(';
- // Function (allow for the old @ symbol that could be used to prefix a function, but we'll ignore it)
- const CALCULATION_REGEXP_FUNCTION = '@?(?:_xlfn\.)?([\p{L}][\p{L}\p{N}\.]*)[\s]*\(';
- // Cell reference (cell or range of cells, with or without a sheet reference)
- const CALCULATION_REGEXP_CELLREF = '((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?\b([a-z]{1,3})\$?(\d{1,7})(?![\w.])';
- // Cell reference (with or without a sheet reference) ensuring absolute/relative
- const CALCULATION_REGEXP_CELLREF_RELATIVE = '((([^\s\(,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?(\$?\b[a-z]{1,3})(\$?\d{1,7})(?![\w.])';
- const CALCULATION_REGEXP_COLUMN_RANGE = '(((([^\s\(,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?(\$?[a-z]{1,3})):(?![.*])';
- const CALCULATION_REGEXP_ROW_RANGE = '(((([^\s\(,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?(\$?[1-9][0-9]{0,6})):(?![.*])';
- // Cell reference (with or without a sheet reference) ensuring absolute/relative
- // Cell ranges ensuring absolute/relative
- const CALCULATION_REGEXP_COLUMNRANGE_RELATIVE = '(\$?[a-z]{1,3}):(\$?[a-z]{1,3})';
- const CALCULATION_REGEXP_ROWRANGE_RELATIVE = '(\$?\d{1,7}):(\$?\d{1,7})';
- // Defined Names: Named Range of cells, or Named Formulae
- const CALCULATION_REGEXP_DEFINEDNAME = '((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?([_\p{L}][_\p{L}\p{N}\.]*)';
- // Error
- const CALCULATION_REGEXP_ERROR = '\#[A-Z][A-Z0_\/]*[!\?]?';
- /** constants */
- const RETURN_ARRAY_AS_ERROR = 'error';
- const RETURN_ARRAY_AS_VALUE = 'value';
- const RETURN_ARRAY_AS_ARRAY = 'array';
- const FORMULA_OPEN_FUNCTION_BRACE = '{';
- const FORMULA_CLOSE_FUNCTION_BRACE = '}';
- const FORMULA_STRING_QUOTE = '"';
- private static $returnArrayAsType = self::RETURN_ARRAY_AS_VALUE;
- /**
- * Instance of this class.
- *
- * @var Calculation
- */
- private static $instance;
- /**
- * Instance of the spreadsheet this Calculation Engine is using.
- *
- * @var Spreadsheet
- */
- private $spreadsheet;
- /**
- * Calculation cache.
- *
- * @var array
- */
- private $calculationCache = [];
- /**
- * Calculation cache enabled.
- *
- * @var bool
- */
- private $calculationCacheEnabled = true;
- /**
- * Used to generate unique store keys.
- *
- * @var int
- */
- private $branchStoreKeyCounter = 0;
- private $branchPruningEnabled = true;
- /**
- * List of operators that can be used within formulae
- * The true/false value indicates whether it is a binary operator or a unary operator.
- *
- * @var array
- */
- private static $operators = [
- '+' => true, '-' => true, '*' => true, '/' => true,
- '^' => true, '&' => true, '%' => false, '~' => false,
- '>' => true, '<' => true, '=' => true, '>=' => true,
- '<=' => true, '<>' => true, '|' => true, ':' => true,
- ];
- /**
- * List of binary operators (those that expect two operands).
- *
- * @var array
- */
- private static $binaryOperators = [
- '+' => true, '-' => true, '*' => true, '/' => true,
- '^' => true, '&' => true, '>' => true, '<' => true,
- '=' => true, '>=' => true, '<=' => true, '<>' => true,
- '|' => true, ':' => true,
- ];
- /**
- * The debug log generated by the calculation engine.
- *
- * @var Logger
- */
- private $debugLog;
- /**
- * Flag to determine how formula errors should be handled
- * If true, then a user error will be triggered
- * If false, then an exception will be thrown.
- *
- * @var bool
- */
- public $suppressFormulaErrors = false;
- /**
- * Error message for any error that was raised/thrown by the calculation engine.
- *
- * @var null|string
- */
- public $formulaError;
- /**
- * Reference Helper.
- *
- * @var ReferenceHelper
- */
- private static $referenceHelper;
- /**
- * An array of the nested cell references accessed by the calculation engine, used for the debug log.
- *
- * @var CyclicReferenceStack
- */
- private $cyclicReferenceStack;
- private $cellStack = [];
- /**
- * Current iteration counter for cyclic formulae
- * If the value is 0 (or less) then cyclic formulae will throw an exception,
- * otherwise they will iterate to the limit defined here before returning a result.
- *
- * @var int
- */
- private $cyclicFormulaCounter = 1;
- private $cyclicFormulaCell = '';
- /**
- * Number of iterations for cyclic formulae.
- *
- * @var int
- */
- public $cyclicFormulaCount = 1;
- /**
- * Epsilon Precision used for comparisons in calculations.
- *
- * @var float
- */
- private $delta = 0.1e-12;
- /**
- * The current locale setting.
- *
- * @var string
- */
- private static $localeLanguage = 'en_us'; // US English (default locale)
- /**
- * List of available locale settings
- * Note that this is read for the locale subdirectory only when requested.
- *
- * @var string[]
- */
- private static $validLocaleLanguages = [
- 'en', // English (default language)
- ];
- /**
- * Locale-specific argument separator for function arguments.
- *
- * @var string
- */
- private static $localeArgumentSeparator = ',';
- private static $localeFunctions = [];
- /**
- * Locale-specific translations for Excel constants (True, False and Null).
- *
- * @var array<string, string>
- */
- public static $localeBoolean = [
- 'TRUE' => 'TRUE',
- 'FALSE' => 'FALSE',
- 'NULL' => 'NULL',
- ];
- /**
- * Excel constant string translations to their PHP equivalents
- * Constant conversion from text name/value to actual (datatyped) value.
- *
- * @var array<string, mixed>
- */
- private static $excelConstants = [
- 'TRUE' => true,
- 'FALSE' => false,
- 'NULL' => null,
- ];
- // PhpSpreadsheet functions
- private static $phpSpreadsheetFunctions = [
- 'ABS' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Absolute::class, 'evaluate'],
- 'argumentCount' => '1',
- ],
- 'ACCRINT' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Securities\AccruedInterest::class, 'periodic'],
- 'argumentCount' => '4-8',
- ],
- 'ACCRINTM' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Securities\AccruedInterest::class, 'atMaturity'],
- 'argumentCount' => '3-5',
- ],
- 'ACOS' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Cosine::class, 'acos'],
- 'argumentCount' => '1',
- ],
- 'ACOSH' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Cosine::class, 'acosh'],
- 'argumentCount' => '1',
- ],
- 'ACOT' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Cotangent::class, 'acot'],
- 'argumentCount' => '1',
- ],
- 'ACOTH' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Cotangent::class, 'acoth'],
- 'argumentCount' => '1',
- ],
- 'ADDRESS' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [LookupRef\Address::class, 'cell'],
- 'argumentCount' => '2-5',
- ],
- 'AGGREGATE' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '3+',
- ],
- 'AMORDEGRC' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Amortization::class, 'AMORDEGRC'],
- 'argumentCount' => '6,7',
- ],
- 'AMORLINC' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Amortization::class, 'AMORLINC'],
- 'argumentCount' => '6,7',
- ],
- 'AND' => [
- 'category' => Category::CATEGORY_LOGICAL,
- 'functionCall' => [Logical\Operations::class, 'logicalAnd'],
- 'argumentCount' => '1+',
- ],
- 'ARABIC' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Arabic::class, 'evaluate'],
- 'argumentCount' => '1',
- ],
- 'AREAS' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '1',
- ],
- 'ARRAYTOTEXT' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'ASC' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '1',
- ],
- 'ASIN' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Sine::class, 'asin'],
- 'argumentCount' => '1',
- ],
- 'ASINH' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Sine::class, 'asinh'],
- 'argumentCount' => '1',
- ],
- 'ATAN' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Tangent::class, 'atan'],
- 'argumentCount' => '1',
- ],
- 'ATAN2' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Tangent::class, 'atan2'],
- 'argumentCount' => '2',
- ],
- 'ATANH' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Tangent::class, 'atanh'],
- 'argumentCount' => '1',
- ],
- 'AVEDEV' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Averages::class, 'averageDeviations'],
- 'argumentCount' => '1+',
- ],
- 'AVERAGE' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Averages::class, 'average'],
- 'argumentCount' => '1+',
- ],
- 'AVERAGEA' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Averages::class, 'averageA'],
- 'argumentCount' => '1+',
- ],
- 'AVERAGEIF' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Conditional::class, 'AVERAGEIF'],
- 'argumentCount' => '2,3',
- ],
- 'AVERAGEIFS' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Conditional::class, 'AVERAGEIFS'],
- 'argumentCount' => '3+',
- ],
- 'BAHTTEXT' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '1',
- ],
- 'BASE' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Base::class, 'evaluate'],
- 'argumentCount' => '2,3',
- ],
- 'BESSELI' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\BesselI::class, 'BESSELI'],
- 'argumentCount' => '2',
- ],
- 'BESSELJ' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\BesselJ::class, 'BESSELJ'],
- 'argumentCount' => '2',
- ],
- 'BESSELK' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\BesselK::class, 'BESSELK'],
- 'argumentCount' => '2',
- ],
- 'BESSELY' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\BesselY::class, 'BESSELY'],
- 'argumentCount' => '2',
- ],
- 'BETADIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Beta::class, 'distribution'],
- 'argumentCount' => '3-5',
- ],
- 'BETA.DIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '4-6',
- ],
- 'BETAINV' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Beta::class, 'inverse'],
- 'argumentCount' => '3-5',
- ],
- 'BETA.INV' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Beta::class, 'inverse'],
- 'argumentCount' => '3-5',
- ],
- 'BIN2DEC' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ConvertBinary::class, 'toDecimal'],
- 'argumentCount' => '1',
- ],
- 'BIN2HEX' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ConvertBinary::class, 'toHex'],
- 'argumentCount' => '1,2',
- ],
- 'BIN2OCT' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ConvertBinary::class, 'toOctal'],
- 'argumentCount' => '1,2',
- ],
- 'BINOMDIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Binomial::class, 'distribution'],
- 'argumentCount' => '4',
- ],
- 'BINOM.DIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Binomial::class, 'distribution'],
- 'argumentCount' => '4',
- ],
- 'BINOM.DIST.RANGE' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Binomial::class, 'range'],
- 'argumentCount' => '3,4',
- ],
- 'BINOM.INV' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Binomial::class, 'inverse'],
- 'argumentCount' => '3',
- ],
- 'BITAND' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\BitWise::class, 'BITAND'],
- 'argumentCount' => '2',
- ],
- 'BITOR' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\BitWise::class, 'BITOR'],
- 'argumentCount' => '2',
- ],
- 'BITXOR' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\BitWise::class, 'BITXOR'],
- 'argumentCount' => '2',
- ],
- 'BITLSHIFT' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\BitWise::class, 'BITLSHIFT'],
- 'argumentCount' => '2',
- ],
- 'BITRSHIFT' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\BitWise::class, 'BITRSHIFT'],
- 'argumentCount' => '2',
- ],
- 'CEILING' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Ceiling::class, 'ceiling'],
- 'argumentCount' => '1-2', // 2 for Excel, 1-2 for Ods/Gnumeric
- ],
- 'CEILING.MATH' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Ceiling::class, 'math'],
- 'argumentCount' => '1-3',
- ],
- 'CEILING.PRECISE' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Ceiling::class, 'precise'],
- 'argumentCount' => '1,2',
- ],
- 'CELL' => [
- 'category' => Category::CATEGORY_INFORMATION,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '1,2',
- ],
- 'CHAR' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\CharacterConvert::class, 'character'],
- 'argumentCount' => '1',
- ],
- 'CHIDIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\ChiSquared::class, 'distributionRightTail'],
- 'argumentCount' => '2',
- ],
- 'CHISQ.DIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\ChiSquared::class, 'distributionLeftTail'],
- 'argumentCount' => '3',
- ],
- 'CHISQ.DIST.RT' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\ChiSquared::class, 'distributionRightTail'],
- 'argumentCount' => '2',
- ],
- 'CHIINV' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\ChiSquared::class, 'inverseRightTail'],
- 'argumentCount' => '2',
- ],
- 'CHISQ.INV' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\ChiSquared::class, 'inverseLeftTail'],
- 'argumentCount' => '2',
- ],
- 'CHISQ.INV.RT' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\ChiSquared::class, 'inverseRightTail'],
- 'argumentCount' => '2',
- ],
- 'CHITEST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\ChiSquared::class, 'test'],
- 'argumentCount' => '2',
- ],
- 'CHISQ.TEST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\ChiSquared::class, 'test'],
- 'argumentCount' => '2',
- ],
- 'CHOOSE' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [LookupRef\Selection::class, 'CHOOSE'],
- 'argumentCount' => '2+',
- ],
- 'CLEAN' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Trim::class, 'nonPrintable'],
- 'argumentCount' => '1',
- ],
- 'CODE' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\CharacterConvert::class, 'code'],
- 'argumentCount' => '1',
- ],
- 'COLUMN' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [LookupRef\RowColumnInformation::class, 'COLUMN'],
- 'argumentCount' => '-1',
- 'passCellReference' => true,
- 'passByReference' => [true],
- ],
- 'COLUMNS' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [LookupRef\RowColumnInformation::class, 'COLUMNS'],
- 'argumentCount' => '1',
- ],
- 'COMBIN' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Combinations::class, 'withoutRepetition'],
- 'argumentCount' => '2',
- ],
- 'COMBINA' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Combinations::class, 'withRepetition'],
- 'argumentCount' => '2',
- ],
- 'COMPLEX' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\Complex::class, 'COMPLEX'],
- 'argumentCount' => '2,3',
- ],
- 'CONCAT' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Concatenate::class, 'CONCATENATE'],
- 'argumentCount' => '1+',
- ],
- 'CONCATENATE' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Concatenate::class, 'CONCATENATE'],
- 'argumentCount' => '1+',
- ],
- 'CONFIDENCE' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Confidence::class, 'CONFIDENCE'],
- 'argumentCount' => '3',
- ],
- 'CONFIDENCE.NORM' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Confidence::class, 'CONFIDENCE'],
- 'argumentCount' => '3',
- ],
- 'CONFIDENCE.T' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '3',
- ],
- 'CONVERT' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ConvertUOM::class, 'CONVERT'],
- 'argumentCount' => '3',
- ],
- 'CORREL' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Trends::class, 'CORREL'],
- 'argumentCount' => '2',
- ],
- 'COS' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Cosine::class, 'cos'],
- 'argumentCount' => '1',
- ],
- 'COSH' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Cosine::class, 'cosh'],
- 'argumentCount' => '1',
- ],
- 'COT' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Cotangent::class, 'cot'],
- 'argumentCount' => '1',
- ],
- 'COTH' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Cotangent::class, 'coth'],
- 'argumentCount' => '1',
- ],
- 'COUNT' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Counts::class, 'COUNT'],
- 'argumentCount' => '1+',
- ],
- 'COUNTA' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Counts::class, 'COUNTA'],
- 'argumentCount' => '1+',
- ],
- 'COUNTBLANK' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Counts::class, 'COUNTBLANK'],
- 'argumentCount' => '1',
- ],
- 'COUNTIF' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Conditional::class, 'COUNTIF'],
- 'argumentCount' => '2',
- ],
- 'COUNTIFS' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Conditional::class, 'COUNTIFS'],
- 'argumentCount' => '2+',
- ],
- 'COUPDAYBS' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Coupons::class, 'COUPDAYBS'],
- 'argumentCount' => '3,4',
- ],
- 'COUPDAYS' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Coupons::class, 'COUPDAYS'],
- 'argumentCount' => '3,4',
- ],
- 'COUPDAYSNC' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Coupons::class, 'COUPDAYSNC'],
- 'argumentCount' => '3,4',
- ],
- 'COUPNCD' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Coupons::class, 'COUPNCD'],
- 'argumentCount' => '3,4',
- ],
- 'COUPNUM' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Coupons::class, 'COUPNUM'],
- 'argumentCount' => '3,4',
- ],
- 'COUPPCD' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Coupons::class, 'COUPPCD'],
- 'argumentCount' => '3,4',
- ],
- 'COVAR' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Trends::class, 'COVAR'],
- 'argumentCount' => '2',
- ],
- 'COVARIANCE.P' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Trends::class, 'COVAR'],
- 'argumentCount' => '2',
- ],
- 'COVARIANCE.S' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2',
- ],
- 'CRITBINOM' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Binomial::class, 'inverse'],
- 'argumentCount' => '3',
- ],
- 'CSC' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Cosecant::class, 'csc'],
- 'argumentCount' => '1',
- ],
- 'CSCH' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Cosecant::class, 'csch'],
- 'argumentCount' => '1',
- ],
- 'CUBEKPIMEMBER' => [
- 'category' => Category::CATEGORY_CUBE,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'CUBEMEMBER' => [
- 'category' => Category::CATEGORY_CUBE,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'CUBEMEMBERPROPERTY' => [
- 'category' => Category::CATEGORY_CUBE,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'CUBERANKEDMEMBER' => [
- 'category' => Category::CATEGORY_CUBE,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'CUBESET' => [
- 'category' => Category::CATEGORY_CUBE,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'CUBESETCOUNT' => [
- 'category' => Category::CATEGORY_CUBE,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'CUBEVALUE' => [
- 'category' => Category::CATEGORY_CUBE,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'CUMIPMT' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\CashFlow\Constant\Periodic\Cumulative::class, 'interest'],
- 'argumentCount' => '6',
- ],
- 'CUMPRINC' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\CashFlow\Constant\Periodic\Cumulative::class, 'principal'],
- 'argumentCount' => '6',
- ],
- 'DATE' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Date::class, 'fromYMD'],
- 'argumentCount' => '3',
- ],
- 'DATEDIF' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Difference::class, 'interval'],
- 'argumentCount' => '2,3',
- ],
- 'DATESTRING' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'DATEVALUE' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\DateValue::class, 'fromString'],
- 'argumentCount' => '1',
- ],
- 'DAVERAGE' => [
- 'category' => Category::CATEGORY_DATABASE,
- 'functionCall' => [Database\DAverage::class, 'evaluate'],
- 'argumentCount' => '3',
- ],
- 'DAY' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\DateParts::class, 'day'],
- 'argumentCount' => '1',
- ],
- 'DAYS' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Days::class, 'between'],
- 'argumentCount' => '2',
- ],
- 'DAYS360' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Days360::class, 'between'],
- 'argumentCount' => '2,3',
- ],
- 'DB' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Depreciation::class, 'DB'],
- 'argumentCount' => '4,5',
- ],
- 'DBCS' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '1',
- ],
- 'DCOUNT' => [
- 'category' => Category::CATEGORY_DATABASE,
- 'functionCall' => [Database\DCount::class, 'evaluate'],
- 'argumentCount' => '3',
- ],
- 'DCOUNTA' => [
- 'category' => Category::CATEGORY_DATABASE,
- 'functionCall' => [Database\DCountA::class, 'evaluate'],
- 'argumentCount' => '3',
- ],
- 'DDB' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Depreciation::class, 'DDB'],
- 'argumentCount' => '4,5',
- ],
- 'DEC2BIN' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ConvertDecimal::class, 'toBinary'],
- 'argumentCount' => '1,2',
- ],
- 'DEC2HEX' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ConvertDecimal::class, 'toHex'],
- 'argumentCount' => '1,2',
- ],
- 'DEC2OCT' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ConvertDecimal::class, 'toOctal'],
- 'argumentCount' => '1,2',
- ],
- 'DECIMAL' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2',
- ],
- 'DEGREES' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Angle::class, 'toDegrees'],
- 'argumentCount' => '1',
- ],
- 'DELTA' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\Compare::class, 'DELTA'],
- 'argumentCount' => '1,2',
- ],
- 'DEVSQ' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Deviations::class, 'sumSquares'],
- 'argumentCount' => '1+',
- ],
- 'DGET' => [
- 'category' => Category::CATEGORY_DATABASE,
- 'functionCall' => [Database\DGet::class, 'evaluate'],
- 'argumentCount' => '3',
- ],
- 'DISC' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Securities\Rates::class, 'discount'],
- 'argumentCount' => '4,5',
- ],
- 'DMAX' => [
- 'category' => Category::CATEGORY_DATABASE,
- 'functionCall' => [Database\DMax::class, 'evaluate'],
- 'argumentCount' => '3',
- ],
- 'DMIN' => [
- 'category' => Category::CATEGORY_DATABASE,
- 'functionCall' => [Database\DMin::class, 'evaluate'],
- 'argumentCount' => '3',
- ],
- 'DOLLAR' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Format::class, 'DOLLAR'],
- 'argumentCount' => '1,2',
- ],
- 'DOLLARDE' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Dollar::class, 'decimal'],
- 'argumentCount' => '2',
- ],
- 'DOLLARFR' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Dollar::class, 'fractional'],
- 'argumentCount' => '2',
- ],
- 'DPRODUCT' => [
- 'category' => Category::CATEGORY_DATABASE,
- 'functionCall' => [Database\DProduct::class, 'evaluate'],
- 'argumentCount' => '3',
- ],
- 'DSTDEV' => [
- 'category' => Category::CATEGORY_DATABASE,
- 'functionCall' => [Database\DStDev::class, 'evaluate'],
- 'argumentCount' => '3',
- ],
- 'DSTDEVP' => [
- 'category' => Category::CATEGORY_DATABASE,
- 'functionCall' => [Database\DStDevP::class, 'evaluate'],
- 'argumentCount' => '3',
- ],
- 'DSUM' => [
- 'category' => Category::CATEGORY_DATABASE,
- 'functionCall' => [Database\DSum::class, 'evaluate'],
- 'argumentCount' => '3',
- ],
- 'DURATION' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '5,6',
- ],
- 'DVAR' => [
- 'category' => Category::CATEGORY_DATABASE,
- 'functionCall' => [Database\DVar::class, 'evaluate'],
- 'argumentCount' => '3',
- ],
- 'DVARP' => [
- 'category' => Category::CATEGORY_DATABASE,
- 'functionCall' => [Database\DVarP::class, 'evaluate'],
- 'argumentCount' => '3',
- ],
- 'ECMA.CEILING' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '1,2',
- ],
- 'EDATE' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Month::class, 'adjust'],
- 'argumentCount' => '2',
- ],
- 'EFFECT' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\InterestRate::class, 'effective'],
- 'argumentCount' => '2',
- ],
- 'ENCODEURL' => [
- 'category' => Category::CATEGORY_WEB,
- 'functionCall' => [Web\Service::class, 'urlEncode'],
- 'argumentCount' => '1',
- ],
- 'EOMONTH' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Month::class, 'lastDay'],
- 'argumentCount' => '2',
- ],
- 'ERF' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\Erf::class, 'ERF'],
- 'argumentCount' => '1,2',
- ],
- 'ERF.PRECISE' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\Erf::class, 'ERFPRECISE'],
- 'argumentCount' => '1',
- ],
- 'ERFC' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ErfC::class, 'ERFC'],
- 'argumentCount' => '1',
- ],
- 'ERFC.PRECISE' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ErfC::class, 'ERFC'],
- 'argumentCount' => '1',
- ],
- 'ERROR.TYPE' => [
- 'category' => Category::CATEGORY_INFORMATION,
- 'functionCall' => [Functions::class, 'errorType'],
- 'argumentCount' => '1',
- ],
- 'EVEN' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Round::class, 'even'],
- 'argumentCount' => '1',
- ],
- 'EXACT' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Text::class, 'exact'],
- 'argumentCount' => '2',
- ],
- 'EXP' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Exp::class, 'evaluate'],
- 'argumentCount' => '1',
- ],
- 'EXPONDIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Exponential::class, 'distribution'],
- 'argumentCount' => '3',
- ],
- 'EXPON.DIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Exponential::class, 'distribution'],
- 'argumentCount' => '3',
- ],
- 'FACT' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Factorial::class, 'fact'],
- 'argumentCount' => '1',
- ],
- 'FACTDOUBLE' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Factorial::class, 'factDouble'],
- 'argumentCount' => '1',
- ],
- 'FALSE' => [
- 'category' => Category::CATEGORY_LOGICAL,
- 'functionCall' => [Logical\Boolean::class, 'FALSE'],
- 'argumentCount' => '0',
- ],
- 'FDIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '3',
- ],
- 'F.DIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\F::class, 'distribution'],
- 'argumentCount' => '4',
- ],
- 'F.DIST.RT' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '3',
- ],
- 'FILTER' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '3+',
- ],
- 'FILTERXML' => [
- 'category' => Category::CATEGORY_WEB,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2',
- ],
- 'FIND' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Search::class, 'sensitive'],
- 'argumentCount' => '2,3',
- ],
- 'FINDB' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Search::class, 'sensitive'],
- 'argumentCount' => '2,3',
- ],
- 'FINV' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '3',
- ],
- 'F.INV' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '3',
- ],
- 'F.INV.RT' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '3',
- ],
- 'FISHER' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Fisher::class, 'distribution'],
- 'argumentCount' => '1',
- ],
- 'FISHERINV' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Fisher::class, 'inverse'],
- 'argumentCount' => '1',
- ],
- 'FIXED' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Format::class, 'FIXEDFORMAT'],
- 'argumentCount' => '1-3',
- ],
- 'FLOOR' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Floor::class, 'floor'],
- 'argumentCount' => '1-2', // Excel requries 2, Ods/Gnumeric 1-2
- ],
- 'FLOOR.MATH' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Floor::class, 'math'],
- 'argumentCount' => '1-3',
- ],
- 'FLOOR.PRECISE' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Floor::class, 'precise'],
- 'argumentCount' => '1-2',
- ],
- 'FORECAST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Trends::class, 'FORECAST'],
- 'argumentCount' => '3',
- ],
- 'FORECAST.ETS' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '3-6',
- ],
- 'FORECAST.ETS.CONFINT' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '3-6',
- ],
- 'FORECAST.ETS.SEASONALITY' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2-4',
- ],
- 'FORECAST.ETS.STAT' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '3-6',
- ],
- 'FORECAST.LINEAR' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Trends::class, 'FORECAST'],
- 'argumentCount' => '3',
- ],
- 'FORMULATEXT' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [LookupRef\Formula::class, 'text'],
- 'argumentCount' => '1',
- 'passCellReference' => true,
- 'passByReference' => [true],
- ],
- 'FREQUENCY' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2',
- ],
- 'FTEST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2',
- ],
- 'F.TEST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2',
- ],
- 'FV' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\CashFlow\Constant\Periodic::class, 'futureValue'],
- 'argumentCount' => '3-5',
- ],
- 'FVSCHEDULE' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\CashFlow\Single::class, 'futureValue'],
- 'argumentCount' => '2',
- ],
- 'GAMMA' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Gamma::class, 'gamma'],
- 'argumentCount' => '1',
- ],
- 'GAMMADIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Gamma::class, 'distribution'],
- 'argumentCount' => '4',
- ],
- 'GAMMA.DIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Gamma::class, 'distribution'],
- 'argumentCount' => '4',
- ],
- 'GAMMAINV' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Gamma::class, 'inverse'],
- 'argumentCount' => '3',
- ],
- 'GAMMA.INV' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Gamma::class, 'inverse'],
- 'argumentCount' => '3',
- ],
- 'GAMMALN' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Gamma::class, 'ln'],
- 'argumentCount' => '1',
- ],
- 'GAMMALN.PRECISE' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Gamma::class, 'ln'],
- 'argumentCount' => '1',
- ],
- 'GAUSS' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\StandardNormal::class, 'gauss'],
- 'argumentCount' => '1',
- ],
- 'GCD' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Gcd::class, 'evaluate'],
- 'argumentCount' => '1+',
- ],
- 'GEOMEAN' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Averages\Mean::class, 'geometric'],
- 'argumentCount' => '1+',
- ],
- 'GESTEP' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\Compare::class, 'GESTEP'],
- 'argumentCount' => '1,2',
- ],
- 'GETPIVOTDATA' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2+',
- ],
- 'GROWTH' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Trends::class, 'GROWTH'],
- 'argumentCount' => '1-4',
- ],
- 'HARMEAN' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Averages\Mean::class, 'harmonic'],
- 'argumentCount' => '1+',
- ],
- 'HEX2BIN' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ConvertHex::class, 'toBinary'],
- 'argumentCount' => '1,2',
- ],
- 'HEX2DEC' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ConvertHex::class, 'toDecimal'],
- 'argumentCount' => '1',
- ],
- 'HEX2OCT' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ConvertHex::class, 'toOctal'],
- 'argumentCount' => '1,2',
- ],
- 'HLOOKUP' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [LookupRef\HLookup::class, 'lookup'],
- 'argumentCount' => '3,4',
- ],
- 'HOUR' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\TimeParts::class, 'hour'],
- 'argumentCount' => '1',
- ],
- 'HYPERLINK' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [LookupRef\Hyperlink::class, 'set'],
- 'argumentCount' => '1,2',
- 'passCellReference' => true,
- ],
- 'HYPGEOMDIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\HyperGeometric::class, 'distribution'],
- 'argumentCount' => '4',
- ],
- 'HYPGEOM.DIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '5',
- ],
- 'IF' => [
- 'category' => Category::CATEGORY_LOGICAL,
- 'functionCall' => [Logical\Conditional::class, 'statementIf'],
- 'argumentCount' => '1-3',
- ],
- 'IFERROR' => [
- 'category' => Category::CATEGORY_LOGICAL,
- 'functionCall' => [Logical\Conditional::class, 'IFERROR'],
- 'argumentCount' => '2',
- ],
- 'IFNA' => [
- 'category' => Category::CATEGORY_LOGICAL,
- 'functionCall' => [Logical\Conditional::class, 'IFNA'],
- 'argumentCount' => '2',
- ],
- 'IFS' => [
- 'category' => Category::CATEGORY_LOGICAL,
- 'functionCall' => [Logical\Conditional::class, 'IFS'],
- 'argumentCount' => '2+',
- ],
- 'IMABS' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexFunctions::class, 'IMABS'],
- 'argumentCount' => '1',
- ],
- 'IMAGINARY' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\Complex::class, 'IMAGINARY'],
- 'argumentCount' => '1',
- ],
- 'IMARGUMENT' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexFunctions::class, 'IMARGUMENT'],
- 'argumentCount' => '1',
- ],
- 'IMCONJUGATE' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexFunctions::class, 'IMCONJUGATE'],
- 'argumentCount' => '1',
- ],
- 'IMCOS' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexFunctions::class, 'IMCOS'],
- 'argumentCount' => '1',
- ],
- 'IMCOSH' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexFunctions::class, 'IMCOSH'],
- 'argumentCount' => '1',
- ],
- 'IMCOT' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexFunctions::class, 'IMCOT'],
- 'argumentCount' => '1',
- ],
- 'IMCSC' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexFunctions::class, 'IMCSC'],
- 'argumentCount' => '1',
- ],
- 'IMCSCH' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexFunctions::class, 'IMCSCH'],
- 'argumentCount' => '1',
- ],
- 'IMDIV' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexOperations::class, 'IMDIV'],
- 'argumentCount' => '2',
- ],
- 'IMEXP' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexFunctions::class, 'IMEXP'],
- 'argumentCount' => '1',
- ],
- 'IMLN' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexFunctions::class, 'IMLN'],
- 'argumentCount' => '1',
- ],
- 'IMLOG10' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexFunctions::class, 'IMLOG10'],
- 'argumentCount' => '1',
- ],
- 'IMLOG2' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexFunctions::class, 'IMLOG2'],
- 'argumentCount' => '1',
- ],
- 'IMPOWER' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexFunctions::class, 'IMPOWER'],
- 'argumentCount' => '2',
- ],
- 'IMPRODUCT' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexOperations::class, 'IMPRODUCT'],
- 'argumentCount' => '1+',
- ],
- 'IMREAL' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\Complex::class, 'IMREAL'],
- 'argumentCount' => '1',
- ],
- 'IMSEC' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexFunctions::class, 'IMSEC'],
- 'argumentCount' => '1',
- ],
- 'IMSECH' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexFunctions::class, 'IMSECH'],
- 'argumentCount' => '1',
- ],
- 'IMSIN' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexFunctions::class, 'IMSIN'],
- 'argumentCount' => '1',
- ],
- 'IMSINH' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexFunctions::class, 'IMSINH'],
- 'argumentCount' => '1',
- ],
- 'IMSQRT' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexFunctions::class, 'IMSQRT'],
- 'argumentCount' => '1',
- ],
- 'IMSUB' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexOperations::class, 'IMSUB'],
- 'argumentCount' => '2',
- ],
- 'IMSUM' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexOperations::class, 'IMSUM'],
- 'argumentCount' => '1+',
- ],
- 'IMTAN' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ComplexFunctions::class, 'IMTAN'],
- 'argumentCount' => '1',
- ],
- 'INDEX' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [LookupRef\Matrix::class, 'index'],
- 'argumentCount' => '1-4',
- ],
- 'INDIRECT' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [LookupRef\Indirect::class, 'INDIRECT'],
- 'argumentCount' => '1,2',
- 'passCellReference' => true,
- ],
- 'INFO' => [
- 'category' => Category::CATEGORY_INFORMATION,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '1',
- ],
- 'INT' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\IntClass::class, 'evaluate'],
- 'argumentCount' => '1',
- ],
- 'INTERCEPT' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Trends::class, 'INTERCEPT'],
- 'argumentCount' => '2',
- ],
- 'INTRATE' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Securities\Rates::class, 'interest'],
- 'argumentCount' => '4,5',
- ],
- 'IPMT' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\CashFlow\Constant\Periodic\Interest::class, 'payment'],
- 'argumentCount' => '4-6',
- ],
- 'IRR' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\CashFlow\Variable\Periodic::class, 'rate'],
- 'argumentCount' => '1,2',
- ],
- 'ISBLANK' => [
- 'category' => Category::CATEGORY_INFORMATION,
- 'functionCall' => [Functions::class, 'isBlank'],
- 'argumentCount' => '1',
- ],
- 'ISERR' => [
- 'category' => Category::CATEGORY_INFORMATION,
- 'functionCall' => [Functions::class, 'isErr'],
- 'argumentCount' => '1',
- ],
- 'ISERROR' => [
- 'category' => Category::CATEGORY_INFORMATION,
- 'functionCall' => [Functions::class, 'isError'],
- 'argumentCount' => '1',
- ],
- 'ISEVEN' => [
- 'category' => Category::CATEGORY_INFORMATION,
- 'functionCall' => [Functions::class, 'isEven'],
- 'argumentCount' => '1',
- ],
- 'ISFORMULA' => [
- 'category' => Category::CATEGORY_INFORMATION,
- 'functionCall' => [Functions::class, 'isFormula'],
- 'argumentCount' => '1',
- 'passCellReference' => true,
- 'passByReference' => [true],
- ],
- 'ISLOGICAL' => [
- 'category' => Category::CATEGORY_INFORMATION,
- 'functionCall' => [Functions::class, 'isLogical'],
- 'argumentCount' => '1',
- ],
- 'ISNA' => [
- 'category' => Category::CATEGORY_INFORMATION,
- 'functionCall' => [Functions::class, 'isNa'],
- 'argumentCount' => '1',
- ],
- 'ISNONTEXT' => [
- 'category' => Category::CATEGORY_INFORMATION,
- 'functionCall' => [Functions::class, 'isNonText'],
- 'argumentCount' => '1',
- ],
- 'ISNUMBER' => [
- 'category' => Category::CATEGORY_INFORMATION,
- 'functionCall' => [Functions::class, 'isNumber'],
- 'argumentCount' => '1',
- ],
- 'ISO.CEILING' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '1,2',
- ],
- 'ISODD' => [
- 'category' => Category::CATEGORY_INFORMATION,
- 'functionCall' => [Functions::class, 'isOdd'],
- 'argumentCount' => '1',
- ],
- 'ISOWEEKNUM' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Week::class, 'isoWeekNumber'],
- 'argumentCount' => '1',
- ],
- 'ISPMT' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\CashFlow\Constant\Periodic\Interest::class, 'schedulePayment'],
- 'argumentCount' => '4',
- ],
- 'ISREF' => [
- 'category' => Category::CATEGORY_INFORMATION,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '1',
- ],
- 'ISTEXT' => [
- 'category' => Category::CATEGORY_INFORMATION,
- 'functionCall' => [Functions::class, 'isText'],
- 'argumentCount' => '1',
- ],
- 'ISTHAIDIGIT' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'JIS' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '1',
- ],
- 'KURT' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Deviations::class, 'kurtosis'],
- 'argumentCount' => '1+',
- ],
- 'LARGE' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Size::class, 'large'],
- 'argumentCount' => '2',
- ],
- 'LCM' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Lcm::class, 'evaluate'],
- 'argumentCount' => '1+',
- ],
- 'LEFT' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Extract::class, 'left'],
- 'argumentCount' => '1,2',
- ],
- 'LEFTB' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Extract::class, 'left'],
- 'argumentCount' => '1,2',
- ],
- 'LEN' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Text::class, 'length'],
- 'argumentCount' => '1',
- ],
- 'LENB' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Text::class, 'length'],
- 'argumentCount' => '1',
- ],
- 'LINEST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Trends::class, 'LINEST'],
- 'argumentCount' => '1-4',
- ],
- 'LN' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Logarithms::class, 'natural'],
- 'argumentCount' => '1',
- ],
- 'LOG' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Logarithms::class, 'withBase'],
- 'argumentCount' => '1,2',
- ],
- 'LOG10' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Logarithms::class, 'base10'],
- 'argumentCount' => '1',
- ],
- 'LOGEST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Trends::class, 'LOGEST'],
- 'argumentCount' => '1-4',
- ],
- 'LOGINV' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\LogNormal::class, 'inverse'],
- 'argumentCount' => '3',
- ],
- 'LOGNORMDIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\LogNormal::class, 'cumulative'],
- 'argumentCount' => '3',
- ],
- 'LOGNORM.DIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\LogNormal::class, 'distribution'],
- 'argumentCount' => '4',
- ],
- 'LOGNORM.INV' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\LogNormal::class, 'inverse'],
- 'argumentCount' => '3',
- ],
- 'LOOKUP' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [LookupRef\Lookup::class, 'lookup'],
- 'argumentCount' => '2,3',
- ],
- 'LOWER' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\CaseConvert::class, 'lower'],
- 'argumentCount' => '1',
- ],
- 'MATCH' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [LookupRef\ExcelMatch::class, 'MATCH'],
- 'argumentCount' => '2,3',
- ],
- 'MAX' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Maximum::class, 'max'],
- 'argumentCount' => '1+',
- ],
- 'MAXA' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Maximum::class, 'maxA'],
- 'argumentCount' => '1+',
- ],
- 'MAXIFS' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Conditional::class, 'MAXIFS'],
- 'argumentCount' => '3+',
- ],
- 'MDETERM' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\MatrixFunctions::class, 'determinant'],
- 'argumentCount' => '1',
- ],
- 'MDURATION' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '5,6',
- ],
- 'MEDIAN' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Averages::class, 'median'],
- 'argumentCount' => '1+',
- ],
- 'MEDIANIF' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2+',
- ],
- 'MID' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Extract::class, 'mid'],
- 'argumentCount' => '3',
- ],
- 'MIDB' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Extract::class, 'mid'],
- 'argumentCount' => '3',
- ],
- 'MIN' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Minimum::class, 'min'],
- 'argumentCount' => '1+',
- ],
- 'MINA' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Minimum::class, 'minA'],
- 'argumentCount' => '1+',
- ],
- 'MINIFS' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Conditional::class, 'MINIFS'],
- 'argumentCount' => '3+',
- ],
- 'MINUTE' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\TimeParts::class, 'minute'],
- 'argumentCount' => '1',
- ],
- 'MINVERSE' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\MatrixFunctions::class, 'inverse'],
- 'argumentCount' => '1',
- ],
- 'MIRR' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\CashFlow\Variable\Periodic::class, 'modifiedRate'],
- 'argumentCount' => '3',
- ],
- 'MMULT' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\MatrixFunctions::class, 'multiply'],
- 'argumentCount' => '2',
- ],
- 'MOD' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Operations::class, 'mod'],
- 'argumentCount' => '2',
- ],
- 'MODE' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Averages::class, 'mode'],
- 'argumentCount' => '1+',
- ],
- 'MODE.MULT' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '1+',
- ],
- 'MODE.SNGL' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Averages::class, 'mode'],
- 'argumentCount' => '1+',
- ],
- 'MONTH' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\DateParts::class, 'month'],
- 'argumentCount' => '1',
- ],
- 'MROUND' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Round::class, 'multiple'],
- 'argumentCount' => '2',
- ],
- 'MULTINOMIAL' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Factorial::class, 'multinomial'],
- 'argumentCount' => '1+',
- ],
- 'MUNIT' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\MatrixFunctions::class, 'identity'],
- 'argumentCount' => '1',
- ],
- 'N' => [
- 'category' => Category::CATEGORY_INFORMATION,
- 'functionCall' => [Functions::class, 'n'],
- 'argumentCount' => '1',
- ],
- 'NA' => [
- 'category' => Category::CATEGORY_INFORMATION,
- 'functionCall' => [Functions::class, 'NA'],
- 'argumentCount' => '0',
- ],
- 'NEGBINOMDIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Binomial::class, 'negative'],
- 'argumentCount' => '3',
- ],
- 'NEGBINOM.DIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '4',
- ],
- 'NETWORKDAYS' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\NetworkDays::class, 'count'],
- 'argumentCount' => '2-3',
- ],
- 'NETWORKDAYS.INTL' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2-4',
- ],
- 'NOMINAL' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\InterestRate::class, 'nominal'],
- 'argumentCount' => '2',
- ],
- 'NORMDIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Normal::class, 'distribution'],
- 'argumentCount' => '4',
- ],
- 'NORM.DIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Normal::class, 'distribution'],
- 'argumentCount' => '4',
- ],
- 'NORMINV' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Normal::class, 'inverse'],
- 'argumentCount' => '3',
- ],
- 'NORM.INV' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Normal::class, 'inverse'],
- 'argumentCount' => '3',
- ],
- 'NORMSDIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\StandardNormal::class, 'cumulative'],
- 'argumentCount' => '1',
- ],
- 'NORM.S.DIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\StandardNormal::class, 'distribution'],
- 'argumentCount' => '1,2',
- ],
- 'NORMSINV' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\StandardNormal::class, 'inverse'],
- 'argumentCount' => '1',
- ],
- 'NORM.S.INV' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\StandardNormal::class, 'inverse'],
- 'argumentCount' => '1',
- ],
- 'NOT' => [
- 'category' => Category::CATEGORY_LOGICAL,
- 'functionCall' => [Logical\Operations::class, 'NOT'],
- 'argumentCount' => '1',
- ],
- 'NOW' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Current::class, 'now'],
- 'argumentCount' => '0',
- ],
- 'NPER' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\CashFlow\Constant\Periodic::class, 'periods'],
- 'argumentCount' => '3-5',
- ],
- 'NPV' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\CashFlow\Variable\Periodic::class, 'presentValue'],
- 'argumentCount' => '2+',
- ],
- 'NUMBERSTRING' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'NUMBERVALUE' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Format::class, 'NUMBERVALUE'],
- 'argumentCount' => '1+',
- ],
- 'OCT2BIN' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ConvertOctal::class, 'toBinary'],
- 'argumentCount' => '1,2',
- ],
- 'OCT2DEC' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ConvertOctal::class, 'toDecimal'],
- 'argumentCount' => '1',
- ],
- 'OCT2HEX' => [
- 'category' => Category::CATEGORY_ENGINEERING,
- 'functionCall' => [Engineering\ConvertOctal::class, 'toHex'],
- 'argumentCount' => '1,2',
- ],
- 'ODD' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Round::class, 'odd'],
- 'argumentCount' => '1',
- ],
- 'ODDFPRICE' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '8,9',
- ],
- 'ODDFYIELD' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '8,9',
- ],
- 'ODDLPRICE' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '7,8',
- ],
- 'ODDLYIELD' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '7,8',
- ],
- 'OFFSET' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [LookupRef\Offset::class, 'OFFSET'],
- 'argumentCount' => '3-5',
- 'passCellReference' => true,
- 'passByReference' => [true],
- ],
- 'OR' => [
- 'category' => Category::CATEGORY_LOGICAL,
- 'functionCall' => [Logical\Operations::class, 'logicalOr'],
- 'argumentCount' => '1+',
- ],
- 'PDURATION' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\CashFlow\Single::class, 'periods'],
- 'argumentCount' => '3',
- ],
- 'PEARSON' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Trends::class, 'CORREL'],
- 'argumentCount' => '2',
- ],
- 'PERCENTILE' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Percentiles::class, 'PERCENTILE'],
- 'argumentCount' => '2',
- ],
- 'PERCENTILE.EXC' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2',
- ],
- 'PERCENTILE.INC' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Percentiles::class, 'PERCENTILE'],
- 'argumentCount' => '2',
- ],
- 'PERCENTRANK' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Percentiles::class, 'PERCENTRANK'],
- 'argumentCount' => '2,3',
- ],
- 'PERCENTRANK.EXC' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2,3',
- ],
- 'PERCENTRANK.INC' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Percentiles::class, 'PERCENTRANK'],
- 'argumentCount' => '2,3',
- ],
- 'PERMUT' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Permutations::class, 'PERMUT'],
- 'argumentCount' => '2',
- ],
- 'PERMUTATIONA' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Permutations::class, 'PERMUTATIONA'],
- 'argumentCount' => '2',
- ],
- 'PHONETIC' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '1',
- ],
- 'PHI' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '1',
- ],
- 'PI' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => 'pi',
- 'argumentCount' => '0',
- ],
- 'PMT' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\CashFlow\Constant\Periodic\Payments::class, 'annuity'],
- 'argumentCount' => '3-5',
- ],
- 'POISSON' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Poisson::class, 'distribution'],
- 'argumentCount' => '3',
- ],
- 'POISSON.DIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Poisson::class, 'distribution'],
- 'argumentCount' => '3',
- ],
- 'POWER' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Operations::class, 'power'],
- 'argumentCount' => '2',
- ],
- 'PPMT' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\CashFlow\Constant\Periodic\Payments::class, 'interestPayment'],
- 'argumentCount' => '4-6',
- ],
- 'PRICE' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Securities\Price::class, 'price'],
- 'argumentCount' => '6,7',
- ],
- 'PRICEDISC' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Securities\Price::class, 'priceDiscounted'],
- 'argumentCount' => '4,5',
- ],
- 'PRICEMAT' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Securities\Price::class, 'priceAtMaturity'],
- 'argumentCount' => '5,6',
- ],
- 'PROB' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '3,4',
- ],
- 'PRODUCT' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Operations::class, 'product'],
- 'argumentCount' => '1+',
- ],
- 'PROPER' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\CaseConvert::class, 'proper'],
- 'argumentCount' => '1',
- ],
- 'PV' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\CashFlow\Constant\Periodic::class, 'presentValue'],
- 'argumentCount' => '3-5',
- ],
- 'QUARTILE' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Percentiles::class, 'QUARTILE'],
- 'argumentCount' => '2',
- ],
- 'QUARTILE.EXC' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2',
- ],
- 'QUARTILE.INC' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Percentiles::class, 'QUARTILE'],
- 'argumentCount' => '2',
- ],
- 'QUOTIENT' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Operations::class, 'quotient'],
- 'argumentCount' => '2',
- ],
- 'RADIANS' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Angle::class, 'toRadians'],
- 'argumentCount' => '1',
- ],
- 'RAND' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Random::class, 'rand'],
- 'argumentCount' => '0',
- ],
- 'RANDARRAY' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '0-5',
- ],
- 'RANDBETWEEN' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Random::class, 'randBetween'],
- 'argumentCount' => '2',
- ],
- 'RANK' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Percentiles::class, 'RANK'],
- 'argumentCount' => '2,3',
- ],
- 'RANK.AVG' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2,3',
- ],
- 'RANK.EQ' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Percentiles::class, 'RANK'],
- 'argumentCount' => '2,3',
- ],
- 'RATE' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\CashFlow\Constant\Periodic\Interest::class, 'rate'],
- 'argumentCount' => '3-6',
- ],
- 'RECEIVED' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Securities\Price::class, 'received'],
- 'argumentCount' => '4-5',
- ],
- 'REPLACE' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Replace::class, 'replace'],
- 'argumentCount' => '4',
- ],
- 'REPLACEB' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Replace::class, 'replace'],
- 'argumentCount' => '4',
- ],
- 'REPT' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Concatenate::class, 'builtinREPT'],
- 'argumentCount' => '2',
- ],
- 'RIGHT' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Extract::class, 'right'],
- 'argumentCount' => '1,2',
- ],
- 'RIGHTB' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Extract::class, 'right'],
- 'argumentCount' => '1,2',
- ],
- 'ROMAN' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Roman::class, 'evaluate'],
- 'argumentCount' => '1,2',
- ],
- 'ROUND' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Round::class, 'round'],
- 'argumentCount' => '2',
- ],
- 'ROUNDBAHTDOWN' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'ROUNDBAHTUP' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'ROUNDDOWN' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Round::class, 'down'],
- 'argumentCount' => '2',
- ],
- 'ROUNDUP' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Round::class, 'up'],
- 'argumentCount' => '2',
- ],
- 'ROW' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [LookupRef\RowColumnInformation::class, 'ROW'],
- 'argumentCount' => '-1',
- 'passCellReference' => true,
- 'passByReference' => [true],
- ],
- 'ROWS' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [LookupRef\RowColumnInformation::class, 'ROWS'],
- 'argumentCount' => '1',
- ],
- 'RRI' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\CashFlow\Single::class, 'interestRate'],
- 'argumentCount' => '3',
- ],
- 'RSQ' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Trends::class, 'RSQ'],
- 'argumentCount' => '2',
- ],
- 'RTD' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '1+',
- ],
- 'SEARCH' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Search::class, 'insensitive'],
- 'argumentCount' => '2,3',
- ],
- 'SEARCHB' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Search::class, 'insensitive'],
- 'argumentCount' => '2,3',
- ],
- 'SEC' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Secant::class, 'sec'],
- 'argumentCount' => '1',
- ],
- 'SECH' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Secant::class, 'sech'],
- 'argumentCount' => '1',
- ],
- 'SECOND' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\TimeParts::class, 'second'],
- 'argumentCount' => '1',
- ],
- 'SEQUENCE' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2',
- ],
- 'SERIESSUM' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\SeriesSum::class, 'evaluate'],
- 'argumentCount' => '4',
- ],
- 'SHEET' => [
- 'category' => Category::CATEGORY_INFORMATION,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '0,1',
- ],
- 'SHEETS' => [
- 'category' => Category::CATEGORY_INFORMATION,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '0,1',
- ],
- 'SIGN' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Sign::class, 'evaluate'],
- 'argumentCount' => '1',
- ],
- 'SIN' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Sine::class, 'sin'],
- 'argumentCount' => '1',
- ],
- 'SINH' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Sine::class, 'sinh'],
- 'argumentCount' => '1',
- ],
- 'SKEW' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Deviations::class, 'skew'],
- 'argumentCount' => '1+',
- ],
- 'SKEW.P' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '1+',
- ],
- 'SLN' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Depreciation::class, 'SLN'],
- 'argumentCount' => '3',
- ],
- 'SLOPE' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Trends::class, 'SLOPE'],
- 'argumentCount' => '2',
- ],
- 'SMALL' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Size::class, 'small'],
- 'argumentCount' => '2',
- ],
- 'SORT' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '1+',
- ],
- 'SORTBY' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2+',
- ],
- 'SQRT' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Sqrt::class, 'sqrt'],
- 'argumentCount' => '1',
- ],
- 'SQRTPI' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Sqrt::class, 'pi'],
- 'argumentCount' => '1',
- ],
- 'STANDARDIZE' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Standardize::class, 'execute'],
- 'argumentCount' => '3',
- ],
- 'STDEV' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\StandardDeviations::class, 'STDEV'],
- 'argumentCount' => '1+',
- ],
- 'STDEV.S' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\StandardDeviations::class, 'STDEV'],
- 'argumentCount' => '1+',
- ],
- 'STDEV.P' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\StandardDeviations::class, 'STDEVP'],
- 'argumentCount' => '1+',
- ],
- 'STDEVA' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\StandardDeviations::class, 'STDEVA'],
- 'argumentCount' => '1+',
- ],
- 'STDEVP' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\StandardDeviations::class, 'STDEVP'],
- 'argumentCount' => '1+',
- ],
- 'STDEVPA' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\StandardDeviations::class, 'STDEVPA'],
- 'argumentCount' => '1+',
- ],
- 'STEYX' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Trends::class, 'STEYX'],
- 'argumentCount' => '2',
- ],
- 'SUBSTITUTE' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Replace::class, 'substitute'],
- 'argumentCount' => '3,4',
- ],
- 'SUBTOTAL' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Subtotal::class, 'evaluate'],
- 'argumentCount' => '2+',
- 'passCellReference' => true,
- ],
- 'SUM' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Sum::class, 'sumErroringStrings'],
- 'argumentCount' => '1+',
- ],
- 'SUMIF' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [Statistical\Conditional::class, 'SUMIF'],
- 'argumentCount' => '2,3',
- ],
- 'SUMIFS' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [Statistical\Conditional::class, 'SUMIFS'],
- 'argumentCount' => '3+',
- ],
- 'SUMPRODUCT' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Sum::class, 'product'],
- 'argumentCount' => '1+',
- ],
- 'SUMSQ' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\SumSquares::class, 'sumSquare'],
- 'argumentCount' => '1+',
- ],
- 'SUMX2MY2' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\SumSquares::class, 'sumXSquaredMinusYSquared'],
- 'argumentCount' => '2',
- ],
- 'SUMX2PY2' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\SumSquares::class, 'sumXSquaredPlusYSquared'],
- 'argumentCount' => '2',
- ],
- 'SUMXMY2' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\SumSquares::class, 'sumXMinusYSquared'],
- 'argumentCount' => '2',
- ],
- 'SWITCH' => [
- 'category' => Category::CATEGORY_LOGICAL,
- 'functionCall' => [Logical\Conditional::class, 'statementSwitch'],
- 'argumentCount' => '3+',
- ],
- 'SYD' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Depreciation::class, 'SYD'],
- 'argumentCount' => '4',
- ],
- 'T' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Text::class, 'test'],
- 'argumentCount' => '1',
- ],
- 'TAN' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Tangent::class, 'tan'],
- 'argumentCount' => '1',
- ],
- 'TANH' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trig\Tangent::class, 'tanh'],
- 'argumentCount' => '1',
- ],
- 'TBILLEQ' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\TreasuryBill::class, 'bondEquivalentYield'],
- 'argumentCount' => '3',
- ],
- 'TBILLPRICE' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\TreasuryBill::class, 'price'],
- 'argumentCount' => '3',
- ],
- 'TBILLYIELD' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\TreasuryBill::class, 'yield'],
- 'argumentCount' => '3',
- ],
- 'TDIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\StudentT::class, 'distribution'],
- 'argumentCount' => '3',
- ],
- 'T.DIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '3',
- ],
- 'T.DIST.2T' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2',
- ],
- 'T.DIST.RT' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2',
- ],
- 'TEXT' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Format::class, 'TEXTFORMAT'],
- 'argumentCount' => '2',
- ],
- 'TEXTJOIN' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Concatenate::class, 'TEXTJOIN'],
- 'argumentCount' => '3+',
- ],
- 'THAIDAYOFWEEK' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'THAIDIGIT' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'THAIMONTHOFYEAR' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'THAINUMSOUND' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'THAINUMSTRING' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'THAISTRINGLENGTH' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'THAIYEAR' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'TIME' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Time::class, 'fromHMS'],
- 'argumentCount' => '3',
- ],
- 'TIMEVALUE' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\TimeValue::class, 'fromString'],
- 'argumentCount' => '1',
- ],
- 'TINV' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\StudentT::class, 'inverse'],
- 'argumentCount' => '2',
- ],
- 'T.INV' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\StudentT::class, 'inverse'],
- 'argumentCount' => '2',
- ],
- 'T.INV.2T' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2',
- ],
- 'TODAY' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Current::class, 'today'],
- 'argumentCount' => '0',
- ],
- 'TRANSPOSE' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [LookupRef\Matrix::class, 'transpose'],
- 'argumentCount' => '1',
- ],
- 'TREND' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Trends::class, 'TREND'],
- 'argumentCount' => '1-4',
- ],
- 'TRIM' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Trim::class, 'spaces'],
- 'argumentCount' => '1',
- ],
- 'TRIMMEAN' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Averages\Mean::class, 'trim'],
- 'argumentCount' => '2',
- ],
- 'TRUE' => [
- 'category' => Category::CATEGORY_LOGICAL,
- 'functionCall' => [Logical\Boolean::class, 'TRUE'],
- 'argumentCount' => '0',
- ],
- 'TRUNC' => [
- 'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Trunc::class, 'evaluate'],
- 'argumentCount' => '1,2',
- ],
- 'TTEST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '4',
- ],
- 'T.TEST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '4',
- ],
- 'TYPE' => [
- 'category' => Category::CATEGORY_INFORMATION,
- 'functionCall' => [Functions::class, 'TYPE'],
- 'argumentCount' => '1',
- ],
- 'UNICHAR' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\CharacterConvert::class, 'character'],
- 'argumentCount' => '1',
- ],
- 'UNICODE' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\CharacterConvert::class, 'code'],
- 'argumentCount' => '1',
- ],
- 'UNIQUE' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '1+',
- ],
- 'UPPER' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\CaseConvert::class, 'upper'],
- 'argumentCount' => '1',
- ],
- 'USDOLLAR' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Dollar::class, 'format'],
- 'argumentCount' => '2',
- ],
- 'VALUE' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData\Format::class, 'VALUE'],
- 'argumentCount' => '1',
- ],
- 'VALUETOTEXT' => [
- 'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '?',
- ],
- 'VAR' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Variances::class, 'VAR'],
- 'argumentCount' => '1+',
- ],
- 'VAR.P' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Variances::class, 'VARP'],
- 'argumentCount' => '1+',
- ],
- 'VAR.S' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Variances::class, 'VAR'],
- 'argumentCount' => '1+',
- ],
- 'VARA' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Variances::class, 'VARA'],
- 'argumentCount' => '1+',
- ],
- 'VARP' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Variances::class, 'VARP'],
- 'argumentCount' => '1+',
- ],
- 'VARPA' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Variances::class, 'VARPA'],
- 'argumentCount' => '1+',
- ],
- 'VDB' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '5-7',
- ],
- 'VLOOKUP' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [LookupRef\VLookup::class, 'lookup'],
- 'argumentCount' => '3,4',
- ],
- 'WEBSERVICE' => [
- 'category' => Category::CATEGORY_WEB,
- 'functionCall' => [Web\Service::class, 'webService'],
- 'argumentCount' => '1',
- ],
- 'WEEKDAY' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Week::class, 'day'],
- 'argumentCount' => '1,2',
- ],
- 'WEEKNUM' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Week::class, 'number'],
- 'argumentCount' => '1,2',
- ],
- 'WEIBULL' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Weibull::class, 'distribution'],
- 'argumentCount' => '4',
- ],
- 'WEIBULL.DIST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\Weibull::class, 'distribution'],
- 'argumentCount' => '4',
- ],
- 'WORKDAY' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\WorkDay::class, 'date'],
- 'argumentCount' => '2-3',
- ],
- 'WORKDAY.INTL' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2-4',
- ],
- 'XIRR' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\CashFlow\Variable\NonPeriodic::class, 'rate'],
- 'argumentCount' => '2,3',
- ],
- 'XLOOKUP' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '3-6',
- ],
- 'XNPV' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\CashFlow\Variable\NonPeriodic::class, 'presentValue'],
- 'argumentCount' => '3',
- ],
- 'XMATCH' => [
- 'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '2,3',
- ],
- 'XOR' => [
- 'category' => Category::CATEGORY_LOGICAL,
- 'functionCall' => [Logical\Operations::class, 'logicalXor'],
- 'argumentCount' => '1+',
- ],
- 'YEAR' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\DateParts::class, 'year'],
- 'argumentCount' => '1',
- ],
- 'YEARFRAC' => [
- 'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\YearFrac::class, 'fraction'],
- 'argumentCount' => '2,3',
- ],
- 'YIELD' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Functions::class, 'DUMMY'],
- 'argumentCount' => '6,7',
- ],
- 'YIELDDISC' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Securities\Yields::class, 'yieldDiscounted'],
- 'argumentCount' => '4,5',
- ],
- 'YIELDMAT' => [
- 'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial\Securities\Yields::class, 'yieldAtMaturity'],
- 'argumentCount' => '5,6',
- ],
- 'ZTEST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\StandardNormal::class, 'zTest'],
- 'argumentCount' => '2-3',
- ],
- 'Z.TEST' => [
- 'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Distributions\StandardNormal::class, 'zTest'],
- 'argumentCount' => '2-3',
- ],
- ];
- // Internal functions used for special control purposes
- private static $controlFunctions = [
- 'MKMATRIX' => [
- 'argumentCount' => '*',
- 'functionCall' => [Internal\MakeMatrix::class, 'make'],
- ],
- 'NAME.ERROR' => [
- 'argumentCount' => '*',
- 'functionCall' => [Functions::class, 'NAME'],
- ],
- 'WILDCARDMATCH' => [
- 'argumentCount' => '2',
- 'functionCall' => [Internal\WildcardMatch::class, 'compare'],
- ],
- ];
- public function __construct(?Spreadsheet $spreadsheet = null)
- {
- $this->delta = 1 * 10 ** (0 - ini_get('precision'));
- $this->spreadsheet = $spreadsheet;
- $this->cyclicReferenceStack = new CyclicReferenceStack();
- $this->debugLog = new Logger($this->cyclicReferenceStack);
- self::$referenceHelper = ReferenceHelper::getInstance();
- }
- private static function loadLocales(): void
- {
- $localeFileDirectory = __DIR__ . '/locale/';
- foreach (glob($localeFileDirectory . '*', GLOB_ONLYDIR) as $filename) {
- $filename = substr($filename, strlen($localeFileDirectory));
- if ($filename != 'en') {
- self::$validLocaleLanguages[] = $filename;
- }
- }
- }
- /**
- * Get an instance of this class.
- *
- * @param ?Spreadsheet $spreadsheet Injected spreadsheet for working with a PhpSpreadsheet Spreadsheet object,
- * or NULL to create a standalone calculation engine
- */
- public static function getInstance(?Spreadsheet $spreadsheet = null): self
- {
- if ($spreadsheet !== null) {
- $instance = $spreadsheet->getCalculationEngine();
- if (isset($instance)) {
- return $instance;
- }
- }
- if (!isset(self::$instance) || (self::$instance === null)) {
- self::$instance = new self();
- }
- return self::$instance;
- }
- /**
- * Flush the calculation cache for any existing instance of this class
- * but only if a Calculation instance exists.
- */
- public function flushInstance(): void
- {
- $this->clearCalculationCache();
- $this->clearBranchStore();
- }
- /**
- * Get the Logger for this calculation engine instance.
- *
- * @return Logger
- */
- public function getDebugLog()
- {
- return $this->debugLog;
- }
- /**
- * __clone implementation. Cloning should not be allowed in a Singleton!
- */
- final public function __clone()
- {
- throw new Exception('Cloning the calculation engine is not allowed!');
- }
- /**
- * Return the locale-specific translation of TRUE.
- *
- * @return string locale-specific translation of TRUE
- */
- public static function getTRUE(): string
- {
- return self::$localeBoolean['TRUE'];
- }
- /**
- * Return the locale-specific translation of FALSE.
- *
- * @return string locale-specific translation of FALSE
- */
- public static function getFALSE(): string
- {
- return self::$localeBoolean['FALSE'];
- }
- /**
- * Set the Array Return Type (Array or Value of first element in the array).
- *
- * @param string $returnType Array return type
- *
- * @return bool Success or failure
- */
- public static function setArrayReturnType($returnType)
- {
- if (
- ($returnType == self::RETURN_ARRAY_AS_VALUE) ||
- ($returnType == self::RETURN_ARRAY_AS_ERROR) ||
- ($returnType == self::RETURN_ARRAY_AS_ARRAY)
- ) {
- self::$returnArrayAsType = $returnType;
- return true;
- }
- return false;
- }
- /**
- * Return the Array Return Type (Array or Value of first element in the array).
- *
- * @return string $returnType Array return type
- */
- public static function getArrayReturnType()
- {
- return self::$returnArrayAsType;
- }
- /**
- * Is calculation caching enabled?
- *
- * @return bool
- */
- public function getCalculationCacheEnabled()
- {
- return $this->calculationCacheEnabled;
- }
- /**
- * Enable/disable calculation cache.
- *
- * @param bool $pValue
- */
- public function setCalculationCacheEnabled($pValue): void
- {
- $this->calculationCacheEnabled = $pValue;
- $this->clearCalculationCache();
- }
- /**
- * Enable calculation cache.
- */
- public function enableCalculationCache(): void
- {
- $this->setCalculationCacheEnabled(true);
- }
- /**
- * Disable calculation cache.
- */
- public function disableCalculationCache(): void
- {
- $this->setCalculationCacheEnabled(false);
- }
- /**
- * Clear calculation cache.
- */
- public function clearCalculationCache(): void
- {
- $this->calculationCache = [];
- }
- /**
- * Clear calculation cache for a specified worksheet.
- *
- * @param string $worksheetName
- */
- public function clearCalculationCacheForWorksheet($worksheetName): void
- {
- if (isset($this->calculationCache[$worksheetName])) {
- unset($this->calculationCache[$worksheetName]);
- }
- }
- /**
- * Rename calculation cache for a specified worksheet.
- *
- * @param string $fromWorksheetName
- * @param string $toWorksheetName
- */
- public function renameCalculationCacheForWorksheet($fromWorksheetName, $toWorksheetName): void
- {
- if (isset($this->calculationCache[$fromWorksheetName])) {
- $this->calculationCache[$toWorksheetName] = &$this->calculationCache[$fromWorksheetName];
- unset($this->calculationCache[$fromWorksheetName]);
- }
- }
- /**
- * Enable/disable calculation cache.
- *
- * @param mixed $enabled
- */
- public function setBranchPruningEnabled($enabled): void
- {
- $this->branchPruningEnabled = $enabled;
- }
- public function enableBranchPruning(): void
- {
- $this->setBranchPruningEnabled(true);
- }
- public function disableBranchPruning(): void
- {
- $this->setBranchPruningEnabled(false);
- }
- public function clearBranchStore(): void
- {
- $this->branchStoreKeyCounter = 0;
- }
- /**
- * Get the currently defined locale code.
- *
- * @return string
- */
- public function getLocale()
- {
- return self::$localeLanguage;
- }
- private function getLocaleFile(string $localeDir, string $locale, string $language, string $file): string
- {
- $localeFileName = $localeDir . str_replace('_', DIRECTORY_SEPARATOR, $locale) .
- DIRECTORY_SEPARATOR . $file;
- if (!file_exists($localeFileName)) {
- // If there isn't a locale specific file, look for a language specific file
- $localeFileName = $localeDir . $language . DIRECTORY_SEPARATOR . $file;
- if (!file_exists($localeFileName)) {
- throw new Exception('Locale file not found');
- }
- }
- return $localeFileName;
- }
- /**
- * Set the locale code.
- *
- * @param string $locale The locale to use for formula translation, eg: 'en_us'
- *
- * @return bool
- */
- public function setLocale(string $locale)
- {
- // Identify our locale and language
- $language = $locale = strtolower($locale);
- if (strpos($locale, '_') !== false) {
- [$language] = explode('_', $locale);
- }
- if (count(self::$validLocaleLanguages) == 1) {
- self::loadLocales();
- }
- // Test whether we have any language data for this language (any locale)
- if (in_array($language, self::$validLocaleLanguages)) {
- // initialise language/locale settings
- self::$localeFunctions = [];
- self::$localeArgumentSeparator = ',';
- self::$localeBoolean = ['TRUE' => 'TRUE', 'FALSE' => 'FALSE', 'NULL' => 'NULL'];
- // Default is US English, if user isn't requesting US english, then read the necessary data from the locale files
- if ($locale !== 'en_us') {
- $localeDir = implode(DIRECTORY_SEPARATOR, [__DIR__, 'locale', null]);
- // Search for a file with a list of function names for locale
- try {
- $functionNamesFile = $this->getLocaleFile($localeDir, $locale, $language, 'functions');
- } catch (Exception $e) {
- return false;
- }
- // Retrieve the list of locale or language specific function names
- $localeFunctions = file($functionNamesFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
- foreach ($localeFunctions as $localeFunction) {
- [$localeFunction] = explode('##', $localeFunction); // Strip out comments
- if (strpos($localeFunction, '=') !== false) {
- [$fName, $lfName] = array_map('trim', explode('=', $localeFunction));
- if ((isset(self::$phpSpreadsheetFunctions[$fName])) && ($lfName != '') && ($fName != $lfName)) {
- self::$localeFunctions[$fName] = $lfName;
- }
- }
- }
- // Default the TRUE and FALSE constants to the locale names of the TRUE() and FALSE() functions
- if (isset(self::$localeFunctions['TRUE'])) {
- self::$localeBoolean['TRUE'] = self::$localeFunctions['TRUE'];
- }
- if (isset(self::$localeFunctions['FALSE'])) {
- self::$localeBoolean['FALSE'] = self::$localeFunctions['FALSE'];
- }
- try {
- $configFile = $this->getLocaleFile($localeDir, $locale, $language, 'config');
- } catch (Exception $e) {
- return false;
- }
- $localeSettings = file($configFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
- foreach ($localeSettings as $localeSetting) {
- [$localeSetting] = explode('##', $localeSetting); // Strip out comments
- if (strpos($localeSetting, '=') !== false) {
- [$settingName, $settingValue] = array_map('trim', explode('=', $localeSetting));
- $settingName = strtoupper($settingName);
- if ($settingValue !== '') {
- switch ($settingName) {
- case 'ARGUMENTSEPARATOR':
- self::$localeArgumentSeparator = $settingValue;
- break;
- }
- }
- }
- }
- }
- self::$functionReplaceFromExcel = self::$functionReplaceToExcel =
- self::$functionReplaceFromLocale = self::$functionReplaceToLocale = null;
- self::$localeLanguage = $locale;
- return true;
- }
- return false;
- }
- /**
- * @param string $fromSeparator
- * @param string $toSeparator
- * @param string $formula
- * @param bool $inBraces
- *
- * @return string
- */
- public static function translateSeparator($fromSeparator, $toSeparator, $formula, &$inBraces)
- {
- $strlen = mb_strlen($formula);
- for ($i = 0; $i < $strlen; ++$i) {
- $chr = mb_substr($formula, $i, 1);
- switch ($chr) {
- case self::FORMULA_OPEN_FUNCTION_BRACE:
- $inBraces = true;
- break;
- case self::FORMULA_CLOSE_FUNCTION_BRACE:
- $inBraces = false;
- break;
- case $fromSeparator:
- if (!$inBraces) {
- $formula = mb_substr($formula, 0, $i) . $toSeparator . mb_substr($formula, $i + 1);
- }
- }
- }
- return $formula;
- }
- /**
- * @param string[] $from
- * @param string[] $to
- * @param string $formula
- * @param string $fromSeparator
- * @param string $toSeparator
- *
- * @return string
- */
- private static function translateFormula(array $from, array $to, $formula, $fromSeparator, $toSeparator)
- {
- // Convert any Excel function names to the required language
- if (self::$localeLanguage !== 'en_us') {
- $inBraces = false;
- // If there is the possibility of braces within a quoted string, then we don't treat those as matrix indicators
- if (strpos($formula, self::FORMULA_STRING_QUOTE) !== false) {
- // So instead we skip replacing in any quoted strings by only replacing in every other array element after we've exploded
- // the formula
- $temp = explode(self::FORMULA_STRING_QUOTE, $formula);
- $i = false;
- foreach ($temp as &$value) {
- // Only count/replace in alternating array entries
- if ($i = !$i) {
- $value = preg_replace($from, $to, $value);
- $value = self::translateSeparator($fromSeparator, $toSeparator, $value, $inBraces);
- }
- }
- unset($value);
- // Then rebuild the formula string
- $formula = implode(self::FORMULA_STRING_QUOTE, $temp);
- } else {
- // If there's no quoted strings, then we do a simple count/replace
- $formula = preg_replace($from, $to, $formula);
- $formula = self::translateSeparator($fromSeparator, $toSeparator, $formula, $inBraces);
- }
- }
- return $formula;
- }
- private static $functionReplaceFromExcel = null;
- private static $functionReplaceToLocale = null;
- public function _translateFormulaToLocale($formula)
- {
- if (self::$functionReplaceFromExcel === null) {
- self::$functionReplaceFromExcel = [];
- foreach (array_keys(self::$localeFunctions) as $excelFunctionName) {
- self::$functionReplaceFromExcel[] = '/(@?[^\w\.])' . preg_quote($excelFunctionName, '/') . '([\s]*\()/Ui';
- }
- foreach (array_keys(self::$localeBoolean) as $excelBoolean) {
- self::$functionReplaceFromExcel[] = '/(@?[^\w\.])' . preg_quote($excelBoolean, '/') . '([^\w\.])/Ui';
- }
- }
- if (self::$functionReplaceToLocale === null) {
- self::$functionReplaceToLocale = [];
- foreach (self::$localeFunctions as $localeFunctionName) {
- self::$functionReplaceToLocale[] = '$1' . trim($localeFunctionName) . '$2';
- }
- foreach (self::$localeBoolean as $localeBoolean) {
- self::$functionReplaceToLocale[] = '$1' . trim($localeBoolean) . '$2';
- }
- }
- return self::translateFormula(self::$functionReplaceFromExcel, self::$functionReplaceToLocale, $formula, ',', self::$localeArgumentSeparator);
- }
- private static $functionReplaceFromLocale = null;
- private static $functionReplaceToExcel = null;
- public function _translateFormulaToEnglish($formula)
- {
- if (self::$functionReplaceFromLocale === null) {
- self::$functionReplaceFromLocale = [];
- foreach (self::$localeFunctions as $localeFunctionName) {
- self::$functionReplaceFromLocale[] = '/(@?[^\w\.])' . preg_quote($localeFunctionName, '/') . '([\s]*\()/Ui';
- }
- foreach (self::$localeBoolean as $excelBoolean) {
- self::$functionReplaceFromLocale[] = '/(@?[^\w\.])' . preg_quote($excelBoolean, '/') . '([^\w\.])/Ui';
- }
- }
- if (self::$functionReplaceToExcel === null) {
- self::$functionReplaceToExcel = [];
- foreach (array_keys(self::$localeFunctions) as $excelFunctionName) {
- self::$functionReplaceToExcel[] = '$1' . trim($excelFunctionName) . '$2';
- }
- foreach (array_keys(self::$localeBoolean) as $excelBoolean) {
- self::$functionReplaceToExcel[] = '$1' . trim($excelBoolean) . '$2';
- }
- }
- return self::translateFormula(self::$functionReplaceFromLocale, self::$functionReplaceToExcel, $formula, self::$localeArgumentSeparator, ',');
- }
- public static function localeFunc($function)
- {
- if (self::$localeLanguage !== 'en_us') {
- $functionName = trim($function, '(');
- if (isset(self::$localeFunctions[$functionName])) {
- $brace = ($functionName != $function);
- $function = self::$localeFunctions[$functionName];
- if ($brace) {
- $function .= '(';
- }
- }
- }
- return $function;
- }
- /**
- * Wrap string values in quotes.
- *
- * @param mixed $value
- *
- * @return mixed
- */
- public static function wrapResult($value)
- {
- if (is_string($value)) {
- // Error values cannot be "wrapped"
- if (preg_match('/^' . self::CALCULATION_REGEXP_ERROR . '$/i', $value, $match)) {
- // Return Excel errors "as is"
- return $value;
- }
- // Return strings wrapped in quotes
- return self::FORMULA_STRING_QUOTE . $value . self::FORMULA_STRING_QUOTE;
- } elseif ((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) {
- // Convert numeric errors to NaN error
- return Functions::NAN();
- }
- return $value;
- }
- /**
- * Remove quotes used as a wrapper to identify string values.
- *
- * @param mixed $value
- *
- * @return mixed
- */
- public static function unwrapResult($value)
- {
- if (is_string($value)) {
- if ((isset($value[0])) && ($value[0] == self::FORMULA_STRING_QUOTE) && (substr($value, -1) == self::FORMULA_STRING_QUOTE)) {
- return substr($value, 1, -1);
- }
- // Convert numeric errors to NAN error
- } elseif ((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) {
- return Functions::NAN();
- }
- return $value;
- }
- /**
- * Calculate cell value (using formula from a cell ID)
- * Retained for backward compatibility.
- *
- * @param Cell $pCell Cell to calculate
- *
- * @return mixed
- */
- public function calculate(?Cell $pCell = null)
- {
- try {
- return $this->calculateCellValue($pCell);
- } catch (\Exception $e) {
- throw new Exception($e->getMessage());
- }
- }
- /**
- * Calculate the value of a cell formula.
- *
- * @param Cell $pCell Cell to calculate
- * @param bool $resetLog Flag indicating whether the debug log should be reset or not
- *
- * @return mixed
- */
- public function calculateCellValue(?Cell $pCell = null, $resetLog = true)
- {
- if ($pCell === null) {
- return null;
- }
- $returnArrayAsType = self::$returnArrayAsType;
- if ($resetLog) {
- // Initialise the logging settings if requested
- $this->formulaError = null;
- $this->debugLog->clearLog();
- $this->cyclicReferenceStack->clear();
- $this->cyclicFormulaCounter = 1;
- self::$returnArrayAsType = self::RETURN_ARRAY_AS_ARRAY;
- }
- // Execute the calculation for the cell formula
- $this->cellStack[] = [
- 'sheet' => $pCell->getWorksheet()->getTitle(),
- 'cell' => $pCell->getCoordinate(),
- ];
- try {
- $result = self::unwrapResult($this->_calculateFormulaValue($pCell->getValue(), $pCell->getCoordinate(), $pCell));
- $cellAddress = array_pop($this->cellStack);
- $this->spreadsheet->getSheetByName($cellAddress['sheet'])->getCell($cellAddress['cell']);
- } catch (\Exception $e) {
- $cellAddress = array_pop($this->cellStack);
- $this->spreadsheet->getSheetByName($cellAddress['sheet'])->getCell($cellAddress['cell']);
- throw new Exception($e->getMessage());
- }
- if ((is_array($result)) && (self::$returnArrayAsType != self::RETURN_ARRAY_AS_ARRAY)) {
- self::$returnArrayAsType = $returnArrayAsType;
- $testResult = Functions::flattenArray($result);
- if (self::$returnArrayAsType == self::RETURN_ARRAY_AS_ERROR) {
- return Functions::VALUE();
- }
- // If there's only a single cell in the array, then we allow it
- if (count($testResult) != 1) {
- // If keys are numeric, then it's a matrix result rather than a cell range result, so we permit it
- $r = array_keys($result);
- $r = array_shift($r);
- if (!is_numeric($r)) {
- return Functions::VALUE();
- }
- if (is_array($result[$r])) {
- $c = array_keys($result[$r]);
- $c = array_shift($c);
- if (!is_numeric($c)) {
- return Functions::VALUE();
- }
- }
- }
- $result = array_shift($testResult);
- }
- self::$returnArrayAsType = $returnArrayAsType;
- if ($result === null && $pCell->getWorksheet()->getSheetView()->getShowZeros()) {
- return 0;
- } elseif ((is_float($result)) && ((is_nan($result)) || (is_infinite($result)))) {
- return Functions::NAN();
- }
- return $result;
- }
- /**
- * Validate and parse a formula string.
- *
- * @param string $formula Formula to parse
- *
- * @return array|bool
- */
- public function parseFormula($formula)
- {
- // Basic validation that this is indeed a formula
- // We return an empty array if not
- $formula = trim($formula);
- if ((!isset($formula[0])) || ($formula[0] != '=')) {
- return [];
- }
- $formula = ltrim(substr($formula, 1));
- if (!isset($formula[0])) {
- return [];
- }
- // Parse the formula and return the token stack
- return $this->internalParseFormula($formula);
- }
- /**
- * Calculate the value of a formula.
- *
- * @param string $formula Formula to parse
- * @param string $cellID Address of the cell to calculate
- * @param Cell $pCell Cell to calculate
- *
- * @return mixed
- */
- public function calculateFormula($formula, $cellID = null, ?Cell $pCell = null)
- {
- // Initialise the logging settings
- $this->formulaError = null;
- $this->debugLog->clearLog();
- $this->cyclicReferenceStack->clear();
- $resetCache = $this->getCalculationCacheEnabled();
- if ($this->spreadsheet !== null && $cellID === null && $pCell === null) {
- $cellID = 'A1';
- $pCell = $this->spreadsheet->getActiveSheet()->getCell($cellID);
- } else {
- // Disable calculation cacheing because it only applies to cell calculations, not straight formulae
- // But don't actually flush any cache
- $this->calculationCacheEnabled = false;
- }
- // Execute the calculation
- try {
- $result = self::unwrapResult($this->_calculateFormulaValue($formula, $cellID, $pCell));
- } catch (\Exception $e) {
- throw new Exception($e->getMessage());
- }
- if ($this->spreadsheet === null) {
- // Reset calculation cacheing to its previous state
- $this->calculationCacheEnabled = $resetCache;
- }
- return $result;
- }
- /**
- * @param mixed $cellValue
- */
- public function getValueFromCache(string $cellReference, &$cellValue): bool
- {
- $this->debugLog->writeDebugLog("Testing cache value for cell {$cellReference}");
- // Is calculation cacheing enabled?
- // If so, is the required value present in calculation cache?
- if (($this->calculationCacheEnabled) && (isset($this->calculationCache[$cellReference]))) {
- $this->debugLog->writeDebugLog("Retrieving value for cell {$cellReference} from cache");
- // Return the cached result
- $cellValue = $this->calculationCache[$cellReference];
- return true;
- }
- return false;
- }
- /**
- * @param string $cellReference
- * @param mixed $cellValue
- */
- public function saveValueToCache($cellReference, $cellValue): void
- {
- if ($this->calculationCacheEnabled) {
- $this->calculationCache[$cellReference] = $cellValue;
- }
- }
- /**
- * Parse a cell formula and calculate its value.
- *
- * @param string $formula The formula to parse and calculate
- * @param string $cellID The ID (e.g. A3) of the cell that we are calculating
- * @param Cell $pCell Cell to calculate
- *
- * @return mixed
- */
- public function _calculateFormulaValue($formula, $cellID = null, ?Cell $pCell = null)
- {
- $cellValue = null;
- // Quote-Prefixed cell values cannot be formulae, but are treated as strings
- if ($pCell !== null && $pCell->getStyle()->getQuotePrefix() === true) {
- return self::wrapResult((string) $formula);
- }
- if (preg_match('/^=\s*cmd\s*\|/miu', $formula) !== 0) {
- return self::wrapResult($formula);
- }
- // Basic validation that this is indeed a formula
- // We simply return the cell value if not
- $formula = trim($formula);
- if ($formula[0] != '=') {
- return self::wrapResult($formula);
- }
- $formula = ltrim(substr($formula, 1));
- if (!isset($formula[0])) {
- return self::wrapResult($formula);
- }
- $pCellParent = ($pCell !== null) ? $pCell->getWorksheet() : null;
- $wsTitle = ($pCellParent !== null) ? $pCellParent->getTitle() : "\x00Wrk";
- $wsCellReference = $wsTitle . '!' . $cellID;
- if (($cellID !== null) && ($this->getValueFromCache($wsCellReference, $cellValue))) {
- return $cellValue;
- }
- $this->debugLog->writeDebugLog("Evaluating formula for cell {$wsCellReference}");
- if (($wsTitle[0] !== "\x00") && ($this->cyclicReferenceStack->onStack($wsCellReference))) {
- if ($this->cyclicFormulaCount <= 0) {
- $this->cyclicFormulaCell = '';
- return $this->raiseFormulaError('Cyclic Reference in Formula');
- } elseif ($this->cyclicFormulaCell === $wsCellReference) {
- ++$this->cyclicFormulaCounter;
- if ($this->cyclicFormulaCounter >= $this->cyclicFormulaCount) {
- $this->cyclicFormulaCell = '';
- return $cellValue;
- }
- } elseif ($this->cyclicFormulaCell == '') {
- if ($this->cyclicFormulaCounter >= $this->cyclicFormulaCount) {
- return $cellValue;
- }
- $this->cyclicFormulaCell = $wsCellReference;
- }
- }
- $this->debugLog->writeDebugLog("Formula for cell {$wsCellReference} is {$formula}");
- // Parse the formula onto the token stack and calculate the value
- $this->cyclicReferenceStack->push($wsCellReference);
- $cellValue = $this->processTokenStack($this->internalParseFormula($formula, $pCell), $cellID, $pCell);
- $this->cyclicReferenceStack->pop();
- // Save to calculation cache
- if ($cellID !== null) {
- $this->saveValueToCache($wsCellReference, $cellValue);
- }
- // Return the calculated value
- return $cellValue;
- }
- /**
- * Ensure that paired matrix operands are both matrices and of the same size.
- *
- * @param mixed $operand1 First matrix operand
- * @param mixed $operand2 Second matrix operand
- * @param int $resize Flag indicating whether the matrices should be resized to match
- * and (if so), whether the smaller dimension should grow or the
- * larger should shrink.
- * 0 = no resize
- * 1 = shrink to fit
- * 2 = extend to fit
- *
- * @return array
- */
- private static function checkMatrixOperands(&$operand1, &$operand2, $resize = 1)
- {
- // Examine each of the two operands, and turn them into an array if they aren't one already
- // Note that this function should only be called if one or both of the operand is already an array
- if (!is_array($operand1)) {
- [$matrixRows, $matrixColumns] = self::getMatrixDimensions($operand2);
- $operand1 = array_fill(0, $matrixRows, array_fill(0, $matrixColumns, $operand1));
- $resize = 0;
- } elseif (!is_array($operand2)) {
- [$matrixRows, $matrixColumns] = self::getMatrixDimensions($operand1);
- $operand2 = array_fill(0, $matrixRows, array_fill(0, $matrixColumns, $operand2));
- $resize = 0;
- }
- [$matrix1Rows, $matrix1Columns] = self::getMatrixDimensions($operand1);
- [$matrix2Rows, $matrix2Columns] = self::getMatrixDimensions($operand2);
- if (($matrix1Rows == $matrix2Columns) && ($matrix2Rows == $matrix1Columns)) {
- $resize = 1;
- }
- if ($resize == 2) {
- // Given two matrices of (potentially) unequal size, convert the smaller in each dimension to match the larger
- self::resizeMatricesExtend($operand1, $operand2, $matrix1Rows, $matrix1Columns, $matrix2Rows, $matrix2Columns);
- } elseif ($resize == 1) {
- // Given two matrices of (potentially) unequal size, convert the larger in each dimension to match the smaller
- self::resizeMatricesShrink($operand1, $operand2, $matrix1Rows, $matrix1Columns, $matrix2Rows, $matrix2Columns);
- }
- return [$matrix1Rows, $matrix1Columns, $matrix2Rows, $matrix2Columns];
- }
- /**
- * Read the dimensions of a matrix, and re-index it with straight numeric keys starting from row 0, column 0.
- *
- * @param array $matrix matrix operand
- *
- * @return int[] An array comprising the number of rows, and number of columns
- */
- public static function getMatrixDimensions(array &$matrix)
- {
- $matrixRows = count($matrix);
- $matrixColumns = 0;
- foreach ($matrix as $rowKey => $rowValue) {
- if (!is_array($rowValue)) {
- $matrix[$rowKey] = [$rowValue];
- $matrixColumns = max(1, $matrixColumns);
- } else {
- $matrix[$rowKey] = array_values($rowValue);
- $matrixColumns = max(count($rowValue), $matrixColumns);
- }
- }
- $matrix = array_values($matrix);
- return [$matrixRows, $matrixColumns];
- }
- /**
- * Ensure that paired matrix operands are both matrices of the same size.
- *
- * @param mixed $matrix1 First matrix operand
- * @param mixed $matrix2 Second matrix operand
- * @param int $matrix1Rows Row size of first matrix operand
- * @param int $matrix1Columns Column size of first matrix operand
- * @param int $matrix2Rows Row size of second matrix operand
- * @param int $matrix2Columns Column size of second matrix operand
- */
- private static function resizeMatricesShrink(&$matrix1, &$matrix2, $matrix1Rows, $matrix1Columns, $matrix2Rows, $matrix2Columns): void
- {
- if (($matrix2Columns < $matrix1Columns) || ($matrix2Rows < $matrix1Rows)) {
- if ($matrix2Rows < $matrix1Rows) {
- for ($i = $matrix2Rows; $i < $matrix1Rows; ++$i) {
- unset($matrix1[$i]);
- }
- }
- if ($matrix2Columns < $matrix1Columns) {
- for ($i = 0; $i < $matrix1Rows; ++$i) {
- for ($j = $matrix2Columns; $j < $matrix1Columns; ++$j) {
- unset($matrix1[$i][$j]);
- }
- }
- }
- }
- if (($matrix1Columns < $matrix2Columns) || ($matrix1Rows < $matrix2Rows)) {
- if ($matrix1Rows < $matrix2Rows) {
- for ($i = $matrix1Rows; $i < $matrix2Rows; ++$i) {
- unset($matrix2[$i]);
- }
- }
- if ($matrix1Columns < $matrix2Columns) {
- for ($i = 0; $i < $matrix2Rows; ++$i) {
- for ($j = $matrix1Columns; $j < $matrix2Columns; ++$j) {
- unset($matrix2[$i][$j]);
- }
- }
- }
- }
- }
- /**
- * Ensure that paired matrix operands are both matrices of the same size.
- *
- * @param mixed $matrix1 First matrix operand
- * @param mixed $matrix2 Second matrix operand
- * @param int $matrix1Rows Row size of first matrix operand
- * @param int $matrix1Columns Column size of first matrix operand
- * @param int $matrix2Rows Row size of second matrix operand
- * @param int $matrix2Columns Column size of second matrix operand
- */
- private static function resizeMatricesExtend(&$matrix1, &$matrix2, $matrix1Rows, $matrix1Columns, $matrix2Rows, $matrix2Columns): void
- {
- if (($matrix2Columns < $matrix1Columns) || ($matrix2Rows < $matrix1Rows)) {
- if ($matrix2Columns < $matrix1Columns) {
- for ($i = 0; $i < $matrix2Rows; ++$i) {
- $x = $matrix2[$i][$matrix2Columns - 1];
- for ($j = $matrix2Columns; $j < $matrix1Columns; ++$j) {
- $matrix2[$i][$j] = $x;
- }
- }
- }
- if ($matrix2Rows < $matrix1Rows) {
- $x = $matrix2[$matrix2Rows - 1];
- for ($i = 0; $i < $matrix1Rows; ++$i) {
- $matrix2[$i] = $x;
- }
- }
- }
- if (($matrix1Columns < $matrix2Columns) || ($matrix1Rows < $matrix2Rows)) {
- if ($matrix1Columns < $matrix2Columns) {
- for ($i = 0; $i < $matrix1Rows; ++$i) {
- $x = $matrix1[$i][$matrix1Columns - 1];
- for ($j = $matrix1Columns; $j < $matrix2Columns; ++$j) {
- $matrix1[$i][$j] = $x;
- }
- }
- }
- if ($matrix1Rows < $matrix2Rows) {
- $x = $matrix1[$matrix1Rows - 1];
- for ($i = 0; $i < $matrix2Rows; ++$i) {
- $matrix1[$i] = $x;
- }
- }
- }
- }
- /**
- * Format details of an operand for display in the log (based on operand type).
- *
- * @param mixed $value First matrix operand
- *
- * @return mixed
- */
- private function showValue($value)
- {
- if ($this->debugLog->getWriteDebugLog()) {
- $testArray = Functions::flattenArray($value);
- if (count($testArray) == 1) {
- $value = array_pop($testArray);
- }
- if (is_array($value)) {
- $returnMatrix = [];
- $pad = $rpad = ', ';
- foreach ($value as $row) {
- if (is_array($row)) {
- $returnMatrix[] = implode($pad, array_map([$this, 'showValue'], $row));
- $rpad = '; ';
- } else {
- $returnMatrix[] = $this->showValue($row);
- }
- }
- return '{ ' . implode($rpad, $returnMatrix) . ' }';
- } elseif (is_string($value) && (trim($value, self::FORMULA_STRING_QUOTE) == $value)) {
- return self::FORMULA_STRING_QUOTE . $value . self::FORMULA_STRING_QUOTE;
- } elseif (is_bool($value)) {
- return ($value) ? self::$localeBoolean['TRUE'] : self::$localeBoolean['FALSE'];
- }
- }
- return Functions::flattenSingleValue($value);
- }
- /**
- * Format type and details of an operand for display in the log (based on operand type).
- *
- * @param mixed $value First matrix operand
- *
- * @return null|string
- */
- private function showTypeDetails($value)
- {
- if ($this->debugLog->getWriteDebugLog()) {
- $testArray = Functions::flattenArray($value);
- if (count($testArray) == 1) {
- $value = array_pop($testArray);
- }
- if ($value === null) {
- return 'a NULL value';
- } elseif (is_float($value)) {
- $typeString = 'a floating point number';
- } elseif (is_int($value)) {
- $typeString = 'an integer number';
- } elseif (is_bool($value)) {
- $typeString = 'a boolean';
- } elseif (is_array($value)) {
- $typeString = 'a matrix';
- } else {
- if ($value == '') {
- return 'an empty string';
- } elseif ($value[0] == '#') {
- return 'a ' . $value . ' error';
- }
- $typeString = 'a string';
- }
- return $typeString . ' with a value of ' . $this->showValue($value);
- }
- return null;
- }
- /**
- * @param string $formula
- *
- * @return false|string False indicates an error
- */
- private function convertMatrixReferences($formula)
- {
- static $matrixReplaceFrom = [self::FORMULA_OPEN_FUNCTION_BRACE, ';', self::FORMULA_CLOSE_FUNCTION_BRACE];
- static $matrixReplaceTo = ['MKMATRIX(MKMATRIX(', '),MKMATRIX(', '))'];
- // Convert any Excel matrix references to the MKMATRIX() function
- if (strpos($formula, self::FORMULA_OPEN_FUNCTION_BRACE) !== false) {
- // If there is the possibility of braces within a quoted string, then we don't treat those as matrix indicators
- if (strpos($formula, self::FORMULA_STRING_QUOTE) !== false) {
- // So instead we skip replacing in any quoted strings by only replacing in every other array element after we've exploded
- // the formula
- $temp = explode(self::FORMULA_STRING_QUOTE, $formula);
- // Open and Closed counts used for trapping mismatched braces in the formula
- $openCount = $closeCount = 0;
- $i = false;
- foreach ($temp as &$value) {
- // Only count/replace in alternating array entries
- if ($i = !$i) {
- $openCount += substr_count($value, self::FORMULA_OPEN_FUNCTION_BRACE);
- $closeCount += substr_count($value, self::FORMULA_CLOSE_FUNCTION_BRACE);
- $value = str_replace($matrixReplaceFrom, $matrixReplaceTo, $value);
- }
- }
- unset($value);
- // Then rebuild the formula string
- $formula = implode(self::FORMULA_STRING_QUOTE, $temp);
- } else {
- // If there's no quoted strings, then we do a simple count/replace
- $openCount = substr_count($formula, self::FORMULA_OPEN_FUNCTION_BRACE);
- $closeCount = substr_count($formula, self::FORMULA_CLOSE_FUNCTION_BRACE);
- $formula = str_replace($matrixReplaceFrom, $matrixReplaceTo, $formula);
- }
- // Trap for mismatched braces and trigger an appropriate error
- if ($openCount < $closeCount) {
- if ($openCount > 0) {
- return $this->raiseFormulaError("Formula Error: Mismatched matrix braces '}'");
- }
- return $this->raiseFormulaError("Formula Error: Unexpected '}' encountered");
- } elseif ($openCount > $closeCount) {
- if ($closeCount > 0) {
- return $this->raiseFormulaError("Formula Error: Mismatched matrix braces '{'");
- }
- return $this->raiseFormulaError("Formula Error: Unexpected '{' encountered");
- }
- }
- return $formula;
- }
- // Binary Operators
- // These operators always work on two values
- // Array key is the operator, the value indicates whether this is a left or right associative operator
- private static $operatorAssociativity = [
- '^' => 0, // Exponentiation
- '*' => 0, '/' => 0, // Multiplication and Division
- '+' => 0, '-' => 0, // Addition and Subtraction
- '&' => 0, // Concatenation
- '|' => 0, ':' => 0, // Intersect and Range
- '>' => 0, '<' => 0, '=' => 0, '>=' => 0, '<=' => 0, '<>' => 0, // Comparison
- ];
- // Comparison (Boolean) Operators
- // These operators work on two values, but always return a boolean result
- private static $comparisonOperators = ['>' => true, '<' => true, '=' => true, '>=' => true, '<=' => true, '<>' => true];
- // Operator Precedence
- // This list includes all valid operators, whether binary (including boolean) or unary (such as %)
- // Array key is the operator, the value is its precedence
- private static $operatorPrecedence = [
- ':' => 8, // Range
- '|' => 7, // Intersect
- '~' => 6, // Negation
- '%' => 5, // Percentage
- '^' => 4, // Exponentiation
- '*' => 3, '/' => 3, // Multiplication and Division
- '+' => 2, '-' => 2, // Addition and Subtraction
- '&' => 1, // Concatenation
- '>' => 0, '<' => 0, '=' => 0, '>=' => 0, '<=' => 0, '<>' => 0, // Comparison
- ];
- // Convert infix to postfix notation
- /**
- * @param string $formula
- *
- * @return array<int, mixed>|false
- */
- private function internalParseFormula($formula, ?Cell $pCell = null)
- {
- if (($formula = $this->convertMatrixReferences(trim($formula))) === false) {
- return false;
- }
- // If we're using cell caching, then $pCell may well be flushed back to the cache (which detaches the parent worksheet),
- // so we store the parent worksheet so that we can re-attach it when necessary
- $pCellParent = ($pCell !== null) ? $pCell->getWorksheet() : null;
- $regexpMatchString = '/^(' . self::CALCULATION_REGEXP_FUNCTION .
- '|' . self::CALCULATION_REGEXP_CELLREF .
- '|' . self::CALCULATION_REGEXP_COLUMN_RANGE .
- '|' . self::CALCULATION_REGEXP_ROW_RANGE .
- '|' . self::CALCULATION_REGEXP_NUMBER .
- '|' . self::CALCULATION_REGEXP_STRING .
- '|' . self::CALCULATION_REGEXP_OPENBRACE .
- '|' . self::CALCULATION_REGEXP_DEFINEDNAME .
- '|' . self::CALCULATION_REGEXP_ERROR .
- ')/sui';
- // Start with initialisation
- $index = 0;
- $stack = new Stack();
- $output = [];
- $expectingOperator = false; // We use this test in syntax-checking the expression to determine when a
- // - is a negation or + is a positive operator rather than an operation
- $expectingOperand = false; // We use this test in syntax-checking the expression to determine whether an operand
- // should be null in a function call
- // IF branch pruning
- // currently pending storeKey (last item of the storeKeysStack
- $pendingStoreKey = null;
- // stores a list of storeKeys (string[])
- $pendingStoreKeysStack = [];
- $expectingConditionMap = []; // ['storeKey' => true, ...]
- $expectingThenMap = []; // ['storeKey' => true, ...]
- $expectingElseMap = []; // ['storeKey' => true, ...]
- $parenthesisDepthMap = []; // ['storeKey' => 4, ...]
- // The guts of the lexical parser
- // Loop through the formula extracting each operator and operand in turn
- while (true) {
- // Branch pruning: we adapt the output item to the context (it will
- // be used to limit its computation)
- $currentCondition = null;
- $currentOnlyIf = null;
- $currentOnlyIfNot = null;
- $previousStoreKey = null;
- $pendingStoreKey = end($pendingStoreKeysStack);
- if ($this->branchPruningEnabled) {
- // this is a condition ?
- if (isset($expectingConditionMap[$pendingStoreKey]) && $expectingConditionMap[$pendingStoreKey]) {
- $currentCondition = $pendingStoreKey;
- $stackDepth = count($pendingStoreKeysStack);
- if ($stackDepth > 1) { // nested if
- $previousStoreKey = $pendingStoreKeysStack[$stackDepth - 2];
- }
- }
- if (isset($expectingThenMap[$pendingStoreKey]) && $expectingThenMap[$pendingStoreKey]) {
- $currentOnlyIf = $pendingStoreKey;
- } elseif (isset($previousStoreKey)) {
- if (isset($expectingThenMap[$previousStoreKey]) && $expectingThenMap[$previousStoreKey]) {
- $currentOnlyIf = $previousStoreKey;
- }
- }
- if (isset($expectingElseMap[$pendingStoreKey]) && $expectingElseMap[$pendingStoreKey]) {
- $currentOnlyIfNot = $pendingStoreKey;
- } elseif (isset($previousStoreKey)) {
- if (isset($expectingElseMap[$previousStoreKey]) && $expectingElseMap[$previousStoreKey]) {
- $currentOnlyIfNot = $previousStoreKey;
- }
- }
- }
- $opCharacter = $formula[$index]; // Get the first character of the value at the current index position
- if ((isset(self::$comparisonOperators[$opCharacter])) && (strlen($formula) > $index) && (isset(self::$comparisonOperators[$formula[$index + 1]]))) {
- $opCharacter .= $formula[++$index];
- }
- // Find out if we're currently at the beginning of a number, variable, cell reference, function, parenthesis or operand
- $isOperandOrFunction = (bool) preg_match($regexpMatchString, substr($formula, $index), $match);
- if ($opCharacter == '-' && !$expectingOperator) { // Is it a negation instead of a minus?
- // Put a negation on the stack
- $stack->push('Unary Operator', '~', null, $currentCondition, $currentOnlyIf, $currentOnlyIfNot);
- ++$index; // and drop the negation symbol
- } elseif ($opCharacter == '%' && $expectingOperator) {
- // Put a percentage on the stack
- $stack->push('Unary Operator', '%', null, $currentCondition, $currentOnlyIf, $currentOnlyIfNot);
- ++$index;
- } elseif ($opCharacter == '+' && !$expectingOperator) { // Positive (unary plus rather than binary operator plus) can be discarded?
- ++$index; // Drop the redundant plus symbol
- } elseif ((($opCharacter == '~') || ($opCharacter == '|')) && (!$isOperandOrFunction)) { // We have to explicitly deny a tilde or pipe, because they are legal
- return $this->raiseFormulaError("Formula Error: Illegal character '~'"); // on the stack but not in the input expression
- } elseif ((isset(self::$operators[$opCharacter]) || $isOperandOrFunction) && $expectingOperator) { // Are we putting an operator on the stack?
- while (
- $stack->count() > 0 &&
- ($o2 = $stack->last()) &&
- isset(self::$operators[$o2['value']]) &&
- @(self::$operatorAssociativity[$opCharacter] ? self::$operatorPrecedence[$opCharacter] < self::$operatorPrecedence[$o2['value']] : self::$operatorPrecedence[$opCharacter] <= self::$operatorPrecedence[$o2['value']])
- ) {
- $output[] = $stack->pop(); // Swap operands and higher precedence operators from the stack to the output
- }
- // Finally put our current operator onto the stack
- $stack->push('Binary Operator', $opCharacter, null, $currentCondition, $currentOnlyIf, $currentOnlyIfNot);
- ++$index;
- $expectingOperator = false;
- } elseif ($opCharacter == ')' && $expectingOperator) { // Are we expecting to close a parenthesis?
- $expectingOperand = false;
- while (($o2 = $stack->pop()) && $o2['value'] != '(') { // Pop off the stack back to the last (
- if ($o2 === null) {
- return $this->raiseFormulaError('Formula Error: Unexpected closing brace ")"');
- }
- $output[] = $o2;
- }
- $d = $stack->last(2);
- // Branch pruning we decrease the depth whether is it a function
- // call or a parenthesis
- if (!empty($pendingStoreKey)) {
- --$parenthesisDepthMap[$pendingStoreKey];
- }
- if (is_array($d) && preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', $d['value'], $matches)) { // Did this parenthesis just close a function?
- if (!empty($pendingStoreKey) && $parenthesisDepthMap[$pendingStoreKey] == -1) {
- // we are closing an IF(
- if ($d['value'] != 'IF(') {
- return $this->raiseFormulaError('Parser bug we should be in an "IF("');
- }
- if ($expectingConditionMap[$pendingStoreKey]) {
- return $this->raiseFormulaError('We should not be expecting a condition');
- }
- $expectingThenMap[$pendingStoreKey] = false;
- $expectingElseMap[$pendingStoreKey] = false;
- --$parenthesisDepthMap[$pendingStoreKey];
- array_pop($pendingStoreKeysStack);
- unset($pendingStoreKey);
- }
- $functionName = $matches[1]; // Get the function name
- $d = $stack->pop();
- $argumentCount = $d['value']; // See how many arguments there were (argument count is the next value stored on the stack)
- $output[] = $d; // Dump the argument count on the output
- $output[] = $stack->pop(); // Pop the function and push onto the output
- if (isset(self::$controlFunctions[$functionName])) {
- $expectedArgumentCount = self::$controlFunctions[$functionName]['argumentCount'];
- $functionCall = self::$controlFunctions[$functionName]['functionCall'];
- } elseif (isset(self::$phpSpreadsheetFunctions[$functionName])) {
- $expectedArgumentCount = self::$phpSpreadsheetFunctions[$functionName]['argumentCount'];
- $functionCall = self::$phpSpreadsheetFunctions[$functionName]['functionCall'];
- } else { // did we somehow push a non-function on the stack? this should never happen
- return $this->raiseFormulaError('Formula Error: Internal error, non-function on stack');
- }
- // Check the argument count
- $argumentCountError = false;
- $expectedArgumentCountString = null;
- if (is_numeric($expectedArgumentCount)) {
- if ($expectedArgumentCount < 0) {
- if ($argumentCount > abs($expectedArgumentCount)) {
- $argumentCountError = true;
- $expectedArgumentCountString = 'no more than ' . abs($expectedArgumentCount);
- }
- } else {
- if ($argumentCount != $expectedArgumentCount) {
- $argumentCountError = true;
- $expectedArgumentCountString = $expectedArgumentCount;
- }
- }
- } elseif ($expectedArgumentCount != '*') {
- $isOperandOrFunction = preg_match('/(\d*)([-+,])(\d*)/', $expectedArgumentCount, $argMatch);
- switch ($argMatch[2]) {
- case '+':
- if ($argumentCount < $argMatch[1]) {
- $argumentCountError = true;
- $expectedArgumentCountString = $argMatch[1] . ' or more ';
- }
- break;
- case '-':
- if (($argumentCount < $argMatch[1]) || ($argumentCount > $argMatch[3])) {
- $argumentCountError = true;
- $expectedArgumentCountString = 'between ' . $argMatch[1] . ' and ' . $argMatch[3];
- }
- break;
- case ',':
- if (($argumentCount != $argMatch[1]) && ($argumentCount != $argMatch[3])) {
- $argumentCountError = true;
- $expectedArgumentCountString = 'either ' . $argMatch[1] . ' or ' . $argMatch[3];
- }
- break;
- }
- }
- if ($argumentCountError) {
- return $this->raiseFormulaError("Formula Error: Wrong number of arguments for $functionName() function: $argumentCount given, " . $expectedArgumentCountString . ' expected');
- }
- }
- ++$index;
- } elseif ($opCharacter == ',') { // Is this the separator for function arguments?
- if (
- !empty($pendingStoreKey) &&
- $parenthesisDepthMap[$pendingStoreKey] == 0
- ) {
- // We must go to the IF next argument
- if ($expectingConditionMap[$pendingStoreKey]) {
- $expectingConditionMap[$pendingStoreKey] = false;
- $expectingThenMap[$pendingStoreKey] = true;
- } elseif ($expectingThenMap[$pendingStoreKey]) {
- $expectingThenMap[$pendingStoreKey] = false;
- $expectingElseMap[$pendingStoreKey] = true;
- } elseif ($expectingElseMap[$pendingStoreKey]) {
- return $this->raiseFormulaError('Reaching fourth argument of an IF');
- }
- }
- while (($o2 = $stack->pop()) && $o2['value'] != '(') { // Pop off the stack back to the last (
- if ($o2 === null) {
- return $this->raiseFormulaError('Formula Error: Unexpected ,');
- }
- $output[] = $o2; // pop the argument expression stuff and push onto the output
- }
- // If we've a comma when we're expecting an operand, then what we actually have is a null operand;
- // so push a null onto the stack
- if (($expectingOperand) || (!$expectingOperator)) {
- $output[] = ['type' => 'NULL Value', 'value' => self::$excelConstants['NULL'], 'reference' => null];
- }
- // make sure there was a function
- $d = $stack->last(2);
- if (!preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', $d['value'], $matches)) {
- return $this->raiseFormulaError('Formula Error: Unexpected ,');
- }
- $d = $stack->pop();
- $itemStoreKey = $d['storeKey'] ?? null;
- $itemOnlyIf = $d['onlyIf'] ?? null;
- $itemOnlyIfNot = $d['onlyIfNot'] ?? null;
- $stack->push($d['type'], ++$d['value'], $d['reference'], $itemStoreKey, $itemOnlyIf, $itemOnlyIfNot); // increment the argument count
- $stack->push('Brace', '(', null, $itemStoreKey, $itemOnlyIf, $itemOnlyIfNot); // put the ( back on, we'll need to pop back to it again
- $expectingOperator = false;
- $expectingOperand = true;
- ++$index;
- } elseif ($opCharacter == '(' && !$expectingOperator) {
- if (!empty($pendingStoreKey)) { // Branch pruning: we go deeper
- ++$parenthesisDepthMap[$pendingStoreKey];
- }
- $stack->push('Brace', '(', null, $currentCondition, $currentOnlyIf, $currentOnlyIf);
- ++$index;
- } elseif ($isOperandOrFunction && !$expectingOperator) { // do we now have a function/variable/number?
- $expectingOperator = true;
- $expectingOperand = false;
- $val = $match[1];
- $length = strlen($val);
- if (preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', $val, $matches)) {
- $val = preg_replace('/\s/u', '', $val);
- if (isset(self::$phpSpreadsheetFunctions[strtoupper($matches[1])]) || isset(self::$controlFunctions[strtoupper($matches[1])])) { // it's a function
- $valToUpper = strtoupper($val);
- } else {
- $valToUpper = 'NAME.ERROR(';
- }
- // here $matches[1] will contain values like "IF"
- // and $val "IF("
- if ($this->branchPruningEnabled && ($valToUpper == 'IF(')) { // we handle a new if
- $pendingStoreKey = $this->getUnusedBranchStoreKey();
- $pendingStoreKeysStack[] = $pendingStoreKey;
- $expectingConditionMap[$pendingStoreKey] = true;
- $parenthesisDepthMap[$pendingStoreKey] = 0;
- } else { // this is not an if but we go deeper
- if (!empty($pendingStoreKey) && array_key_exists($pendingStoreKey, $parenthesisDepthMap)) {
- ++$parenthesisDepthMap[$pendingStoreKey];
- }
- }
- $stack->push('Function', $valToUpper, null, $currentCondition, $currentOnlyIf, $currentOnlyIfNot);
- // tests if the function is closed right after opening
- $ax = preg_match('/^\s*\)/u', substr($formula, $index + $length));
- if ($ax) {
- $stack->push('Operand Count for Function ' . $valToUpper . ')', 0, null, $currentCondition, $currentOnlyIf, $currentOnlyIfNot);
- $expectingOperator = true;
- } else {
- $stack->push('Operand Count for Function ' . $valToUpper . ')', 1, null, $currentCondition, $currentOnlyIf, $currentOnlyIfNot);
- $expectingOperator = false;
- }
- $stack->push('Brace', '(');
- } elseif (preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '$/i', $val, $matches)) {
- // Watch for this case-change when modifying to allow cell references in different worksheets...
- // Should only be applied to the actual cell column, not the worksheet name
- // If the last entry on the stack was a : operator, then we have a cell range reference
- $testPrevOp = $stack->last(1);
- if ($testPrevOp !== null && $testPrevOp['value'] === ':') {
- // If we have a worksheet reference, then we're playing with a 3D reference
- if ($matches[2] == '') {
- // Otherwise, we 'inherit' the worksheet reference from the start cell reference
- // The start of the cell range reference should be the last entry in $output
- $rangeStartCellRef = $output[count($output) - 1]['value'];
- preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '$/i', $rangeStartCellRef, $rangeStartMatches);
- if ($rangeStartMatches[2] > '') {
- $val = $rangeStartMatches[2] . '!' . $val;
- }
- } else {
- $rangeStartCellRef = $output[count($output) - 1]['value'];
- preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '$/i', $rangeStartCellRef, $rangeStartMatches);
- if ($rangeStartMatches[2] !== $matches[2]) {
- return $this->raiseFormulaError('3D Range references are not yet supported');
- }
- }
- } elseif (strpos($val, '!') === false && $pCellParent !== null) {
- $worksheet = $pCellParent->getTitle();
- $val = "'{$worksheet}'!{$val}";
- }
- $outputItem = $stack->getStackItem('Cell Reference', $val, $val, $currentCondition, $currentOnlyIf, $currentOnlyIfNot);
- $output[] = $outputItem;
- } else { // it's a variable, constant, string, number or boolean
- $localeConstant = false;
- $stackItemType = 'Value';
- $stackItemReference = null;
- // If the last entry on the stack was a : operator, then we may have a row or column range reference
- $testPrevOp = $stack->last(1);
- if ($testPrevOp !== null && $testPrevOp['value'] === ':') {
- $stackItemType = 'Cell Reference';
- $startRowColRef = $output[count($output) - 1]['value'];
- [$rangeWS1, $startRowColRef] = Worksheet::extractSheetTitle($startRowColRef, true);
- $rangeSheetRef = $rangeWS1;
- if ($rangeWS1 !== '') {
- $rangeWS1 .= '!';
- }
- $rangeSheetRef = trim($rangeSheetRef, "'");
- [$rangeWS2, $val] = Worksheet::extractSheetTitle($val, true);
- if ($rangeWS2 !== '') {
- $rangeWS2 .= '!';
- } else {
- $rangeWS2 = $rangeWS1;
- }
- $refSheet = $pCellParent;
- if ($pCellParent !== null && $rangeSheetRef !== '' && $rangeSheetRef !== $pCellParent->getTitle()) {
- $refSheet = $pCellParent->getParent()->getSheetByName($rangeSheetRef);
- }
- if (ctype_digit($val) && $val <= 1048576) {
- // Row range
- $stackItemType = 'Row Reference';
- $endRowColRef = ($refSheet !== null) ? $refSheet->getHighestDataColumn($val) : 'XFD'; // Max 16,384 columns for Excel2007
- $val = "{$rangeWS2}{$endRowColRef}{$val}";
- } elseif (ctype_alpha($val) && strlen($val) <= 3) {
- // Column range
- $stackItemType = 'Column Reference';
- $endRowColRef = ($refSheet !== null) ? $refSheet->getHighestDataRow($val) : 1048576; // Max 1,048,576 rows for Excel2007
- $val = "{$rangeWS2}{$val}{$endRowColRef}";
- }
- $stackItemReference = $val;
- } elseif ($opCharacter == self::FORMULA_STRING_QUOTE) {
- // UnEscape any quotes within the string
- $val = self::wrapResult(str_replace('""', self::FORMULA_STRING_QUOTE, self::unwrapResult($val)));
- } elseif (isset(self::$excelConstants[trim(strtoupper($val))])) {
- $stackItemType = 'Constant';
- $excelConstant = trim(strtoupper($val));
- $val = self::$excelConstants[$excelConstant];
- } elseif (($localeConstant = array_search(trim(strtoupper($val)), self::$localeBoolean)) !== false) {
- $stackItemType = 'Constant';
- $val = self::$excelConstants[$localeConstant];
- } elseif (
- preg_match('/^' . self::CALCULATION_REGEXP_ROW_RANGE . '/miu', substr($formula, $index), $rowRangeReference)
- ) {
- $val = $rowRangeReference[1];
- $length = strlen($rowRangeReference[1]);
- $stackItemType = 'Row Reference';
- $column = 'A';
- if (($testPrevOp !== null && $testPrevOp['value'] === ':') && $pCellParent !== null) {
- $column = $pCellParent->getHighestDataColumn($val);
- }
- $val = "{$rowRangeReference[2]}{$column}{$rowRangeReference[7]}";
- $stackItemReference = $val;
- } elseif (
- preg_match('/^' . self::CALCULATION_REGEXP_COLUMN_RANGE . '/miu', substr($formula, $index), $columnRangeReference)
- ) {
- $val = $columnRangeReference[1];
- $length = strlen($val);
- $stackItemType = 'Column Reference';
- $row = '1';
- if (($testPrevOp !== null && $testPrevOp['value'] === ':') && $pCellParent !== null) {
- $row = $pCellParent->getHighestDataRow($val);
- }
- $val = "{$val}{$row}";
- $stackItemReference = $val;
- } elseif (preg_match('/^' . self::CALCULATION_REGEXP_DEFINEDNAME . '.*/miu', $val, $match)) {
- $stackItemType = 'Defined Name';
- $stackItemReference = $val;
- } elseif (is_numeric($val)) {
- if ((strpos($val, '.') !== false) || (stripos($val, 'e') !== false) || ($val > PHP_INT_MAX) || ($val < -PHP_INT_MAX)) {
- $val = (float) $val;
- } else {
- $val = (int) $val;
- }
- }
- $details = $stack->getStackItem($stackItemType, $val, $stackItemReference, $currentCondition, $currentOnlyIf, $currentOnlyIfNot);
- if ($localeConstant) {
- $details['localeValue'] = $localeConstant;
- }
- $output[] = $details;
- }
- $index += $length;
- } elseif ($opCharacter == '$') { // absolute row or column range
- ++$index;
- } elseif ($opCharacter == ')') { // miscellaneous error checking
- if ($expectingOperand) {
- $output[] = ['type' => 'NULL Value', 'value' => self::$excelConstants['NULL'], 'reference' => null];
- $expectingOperand = false;
- $expectingOperator = true;
- } else {
- return $this->raiseFormulaError("Formula Error: Unexpected ')'");
- }
- } elseif (isset(self::$operators[$opCharacter]) && !$expectingOperator) {
- return $this->raiseFormulaError("Formula Error: Unexpected operator '$opCharacter'");
- } else { // I don't even want to know what you did to get here
- return $this->raiseFormulaError('Formula Error: An unexpected error occurred');
- }
- // Test for end of formula string
- if ($index == strlen($formula)) {
- // Did we end with an operator?.
- // Only valid for the % unary operator
- if ((isset(self::$operators[$opCharacter])) && ($opCharacter != '%')) {
- return $this->raiseFormulaError("Formula Error: Operator '$opCharacter' has no operands");
- }
- break;
- }
- // Ignore white space
- while (($formula[$index] == "\n") || ($formula[$index] == "\r")) {
- ++$index;
- }
- if ($formula[$index] == ' ') {
- while ($formula[$index] == ' ') {
- ++$index;
- }
- // If we're expecting an operator, but only have a space between the previous and next operands (and both are
- // Cell References) then we have an INTERSECTION operator
- if (
- ($expectingOperator) &&
- ((preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '.*/Ui', substr($formula, $index), $match)) &&
- ($output[count($output) - 1]['type'] == 'Cell Reference') ||
- (preg_match('/^' . self::CALCULATION_REGEXP_DEFINEDNAME . '.*/miu', substr($formula, $index), $match)) &&
- ($output[count($output) - 1]['type'] == 'Defined Name' || $output[count($output) - 1]['type'] == 'Value')
- )
- ) {
- while (
- $stack->count() > 0 &&
- ($o2 = $stack->last()) &&
- isset(self::$operators[$o2['value']]) &&
- @(self::$operatorAssociativity[$opCharacter] ? self::$operatorPrecedence[$opCharacter] < self::$operatorPrecedence[$o2['value']] : self::$operatorPrecedence[$opCharacter] <= self::$operatorPrecedence[$o2['value']])
- ) {
- $output[] = $stack->pop(); // Swap operands and higher precedence operators from the stack to the output
- }
- $stack->push('Binary Operator', '|'); // Put an Intersect Operator on the stack
- $expectingOperator = false;
- }
- }
- }
- while (($op = $stack->pop()) !== null) { // pop everything off the stack and push onto output
- if ((is_array($op) && $op['value'] == '(') || ($op === '(')) {
- return $this->raiseFormulaError("Formula Error: Expecting ')'"); // if there are any opening braces on the stack, then braces were unbalanced
- }
- $output[] = $op;
- }
- return $output;
- }
- private static function dataTestReference(&$operandData)
- {
- $operand = $operandData['value'];
- if (($operandData['reference'] === null) && (is_array($operand))) {
- $rKeys = array_keys($operand);
- $rowKey = array_shift($rKeys);
- $cKeys = array_keys(array_keys($operand[$rowKey]));
- $colKey = array_shift($cKeys);
- if (ctype_upper($colKey)) {
- $operandData['reference'] = $colKey . $rowKey;
- }
- }
- return $operand;
- }
- // evaluate postfix notation
- /**
- * @param mixed $tokens
- * @param null|string $cellID
- *
- * @return array<int, mixed>|false
- */
- private function processTokenStack($tokens, $cellID = null, ?Cell $pCell = null)
- {
- if ($tokens == false) {
- return false;
- }
- // If we're using cell caching, then $pCell may well be flushed back to the cache (which detaches the parent cell collection),
- // so we store the parent cell collection so that we can re-attach it when necessary
- $pCellWorksheet = ($pCell !== null) ? $pCell->getWorksheet() : null;
- $pCellParent = ($pCell !== null) ? $pCell->getParent() : null;
- $stack = new Stack();
- // Stores branches that have been pruned
- $fakedForBranchPruning = [];
- // help us to know when pruning ['branchTestId' => true/false]
- $branchStore = [];
- // Loop through each token in turn
- foreach ($tokens as $tokenData) {
- $token = $tokenData['value'];
- // Branch pruning: skip useless resolutions
- $storeKey = $tokenData['storeKey'] ?? null;
- if ($this->branchPruningEnabled && isset($tokenData['onlyIf'])) {
- $onlyIfStoreKey = $tokenData['onlyIf'];
- $storeValue = $branchStore[$onlyIfStoreKey] ?? null;
- $storeValueAsBool = ($storeValue === null) ?
- true : (bool) Functions::flattenSingleValue($storeValue);
- if (is_array($storeValue)) {
- $wrappedItem = end($storeValue);
- $storeValue = end($wrappedItem);
- }
- if (
- isset($storeValue)
- && (
- !$storeValueAsBool
- || Functions::isError($storeValue)
- || ($storeValue === 'Pruned branch')
- )
- ) {
- // If branching value is not true, we don't need to compute
- if (!isset($fakedForBranchPruning['onlyIf-' . $onlyIfStoreKey])) {
- $stack->push('Value', 'Pruned branch (only if ' . $onlyIfStoreKey . ') ' . $token);
- $fakedForBranchPruning['onlyIf-' . $onlyIfStoreKey] = true;
- }
- if (isset($storeKey)) {
- // We are processing an if condition
- // We cascade the pruning to the depending branches
- $branchStore[$storeKey] = 'Pruned branch';
- $fakedForBranchPruning['onlyIfNot-' . $storeKey] = true;
- $fakedForBranchPruning['onlyIf-' . $storeKey] = true;
- }
- continue;
- }
- }
- if ($this->branchPruningEnabled && isset($tokenData['onlyIfNot'])) {
- $onlyIfNotStoreKey = $tokenData['onlyIfNot'];
- $storeValue = $branchStore[$onlyIfNotStoreKey] ?? null;
- $storeValueAsBool = ($storeValue === null) ?
- true : (bool) Functions::flattenSingleValue($storeValue);
- if (is_array($storeValue)) {
- $wrappedItem = end($storeValue);
- $storeValue = end($wrappedItem);
- }
- if (
- isset($storeValue)
- && (
- $storeValueAsBool
- || Functions::isError($storeValue)
- || ($storeValue === 'Pruned branch'))
- ) {
- // If branching value is true, we don't need to compute
- if (!isset($fakedForBranchPruning['onlyIfNot-' . $onlyIfNotStoreKey])) {
- $stack->push('Value', 'Pruned branch (only if not ' . $onlyIfNotStoreKey . ') ' . $token);
- $fakedForBranchPruning['onlyIfNot-' . $onlyIfNotStoreKey] = true;
- }
- if (isset($storeKey)) {
- // We are processing an if condition
- // We cascade the pruning to the depending branches
- $branchStore[$storeKey] = 'Pruned branch';
- $fakedForBranchPruning['onlyIfNot-' . $storeKey] = true;
- $fakedForBranchPruning['onlyIf-' . $storeKey] = true;
- }
- continue;
- }
- }
- // 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
- if (isset(self::$binaryOperators[$token])) {
- // We must have two operands, error if we don't
- if (($operand2Data = $stack->pop()) === null) {
- return $this->raiseFormulaError('Internal error - Operand value missing from stack');
- }
- if (($operand1Data = $stack->pop()) === null) {
- return $this->raiseFormulaError('Internal error - Operand value missing from stack');
- }
- $operand1 = self::dataTestReference($operand1Data);
- $operand2 = self::dataTestReference($operand2Data);
- // Log what we're doing
- if ($token == ':') {
- $this->debugLog->writeDebugLog('Evaluating Range ', $this->showValue($operand1Data['reference']), ' ', $token, ' ', $this->showValue($operand2Data['reference']));
- } else {
- $this->debugLog->writeDebugLog('Evaluating ', $this->showValue($operand1), ' ', $token, ' ', $this->showValue($operand2));
- }
- // Process the operation in the appropriate manner
- switch ($token) {
- // Comparison (Boolean) Operators
- case '>': // Greater than
- case '<': // Less than
- case '>=': // Greater than or Equal to
- case '<=': // Less than or Equal to
- case '=': // Equality
- case '<>': // Inequality
- $result = $this->executeBinaryComparisonOperation($cellID, $operand1, $operand2, $token, $stack);
- if (isset($storeKey)) {
- $branchStore[$storeKey] = $result;
- }
- break;
- // Binary Operators
- case ':': // Range
- if (strpos($operand1Data['reference'], '!') !== false) {
- [$sheet1, $operand1Data['reference']] = Worksheet::extractSheetTitle($operand1Data['reference'], true);
- } else {
- $sheet1 = ($pCellParent !== null) ? $pCellWorksheet->getTitle() : '';
- }
- [$sheet2, $operand2Data['reference']] = Worksheet::extractSheetTitle($operand2Data['reference'], true);
- if (empty($sheet2)) {
- $sheet2 = $sheet1;
- }
- if ($sheet1 == $sheet2) {
- if ($operand1Data['reference'] === null) {
- if ((trim($operand1Data['value']) != '') && (is_numeric($operand1Data['value']))) {
- $operand1Data['reference'] = $pCell->getColumn() . $operand1Data['value'];
- } elseif (trim($operand1Data['reference']) == '') {
- $operand1Data['reference'] = $pCell->getCoordinate();
- } else {
- $operand1Data['reference'] = $operand1Data['value'] . $pCell->getRow();
- }
- }
- if ($operand2Data['reference'] === null) {
- if ((trim($operand2Data['value']) != '') && (is_numeric($operand2Data['value']))) {
- $operand2Data['reference'] = $pCell->getColumn() . $operand2Data['value'];
- } elseif (trim($operand2Data['reference']) == '') {
- $operand2Data['reference'] = $pCell->getCoordinate();
- } else {
- $operand2Data['reference'] = $operand2Data['value'] . $pCell->getRow();
- }
- }
- $oData = array_merge(explode(':', $operand1Data['reference']), explode(':', $operand2Data['reference']));
- $oCol = $oRow = [];
- foreach ($oData as $oDatum) {
- $oCR = Coordinate::coordinateFromString($oDatum);
- $oCol[] = Coordinate::columnIndexFromString($oCR[0]) - 1;
- $oRow[] = $oCR[1];
- }
- $cellRef = Coordinate::stringFromColumnIndex(min($oCol) + 1) . min($oRow) . ':' . Coordinate::stringFromColumnIndex(max($oCol) + 1) . max($oRow);
- if ($pCellParent !== null) {
- $cellValue = $this->extractCellRange($cellRef, $this->spreadsheet->getSheetByName($sheet1), false);
- } else {
- return $this->raiseFormulaError('Unable to access Cell Reference');
- }
- $stack->push('Cell Reference', $cellValue, $cellRef);
- } else {
- $stack->push('Error', Functions::REF(), null);
- }
- break;
- case '+': // Addition
- $result = $this->executeNumericBinaryOperation($operand1, $operand2, $token, 'plusEquals', $stack);
- if (isset($storeKey)) {
- $branchStore[$storeKey] = $result;
- }
- break;
- case '-': // Subtraction
- $result = $this->executeNumericBinaryOperation($operand1, $operand2, $token, 'minusEquals', $stack);
- if (isset($storeKey)) {
- $branchStore[$storeKey] = $result;
- }
- break;
- case '*': // Multiplication
- $result = $this->executeNumericBinaryOperation($operand1, $operand2, $token, 'arrayTimesEquals', $stack);
- if (isset($storeKey)) {
- $branchStore[$storeKey] = $result;
- }
- break;
- case '/': // Division
- $result = $this->executeNumericBinaryOperation($operand1, $operand2, $token, 'arrayRightDivide', $stack);
- if (isset($storeKey)) {
- $branchStore[$storeKey] = $result;
- }
- break;
- case '^': // Exponential
- $result = $this->executeNumericBinaryOperation($operand1, $operand2, $token, 'power', $stack);
- if (isset($storeKey)) {
- $branchStore[$storeKey] = $result;
- }
- break;
- case '&': // Concatenation
- // If either of the operands is a matrix, we need to treat them both as matrices
- // (converting the other operand to a matrix if need be); then perform the required
- // matrix operation
- if (is_bool($operand1)) {
- $operand1 = ($operand1) ? self::$localeBoolean['TRUE'] : self::$localeBoolean['FALSE'];
- }
- if (is_bool($operand2)) {
- $operand2 = ($operand2) ? self::$localeBoolean['TRUE'] : self::$localeBoolean['FALSE'];
- }
- if ((is_array($operand1)) || (is_array($operand2))) {
- // Ensure that both operands are arrays/matrices
- self::checkMatrixOperands($operand1, $operand2, 2);
- try {
- // Convert operand 1 from a PHP array to a matrix
- $matrix = new Shared\JAMA\Matrix($operand1);
- // Perform the required operation against the operand 1 matrix, passing in operand 2
- $matrixResult = $matrix->concat($operand2);
- $result = $matrixResult->getArray();
- } catch (\Exception $ex) {
- $this->debugLog->writeDebugLog('JAMA Matrix Exception: ', $ex->getMessage());
- $result = '#VALUE!';
- }
- } else {
- $result = self::FORMULA_STRING_QUOTE . str_replace('""', self::FORMULA_STRING_QUOTE, self::unwrapResult($operand1) . self::unwrapResult($operand2)) . self::FORMULA_STRING_QUOTE;
- }
- $this->debugLog->writeDebugLog('Evaluation Result is ', $this->showTypeDetails($result));
- $stack->push('Value', $result);
- if (isset($storeKey)) {
- $branchStore[$storeKey] = $result;
- }
- break;
- case '|': // Intersect
- $rowIntersect = array_intersect_key($operand1, $operand2);
- $cellIntersect = $oCol = $oRow = [];
- foreach (array_keys($rowIntersect) as $row) {
- $oRow[] = $row;
- foreach ($rowIntersect[$row] as $col => $data) {
- $oCol[] = Coordinate::columnIndexFromString($col) - 1;
- $cellIntersect[$row] = array_intersect_key($operand1[$row], $operand2[$row]);
- }
- }
- if (count(Functions::flattenArray($cellIntersect)) === 0) {
- $this->debugLog->writeDebugLog('Evaluation Result is ', $this->showTypeDetails($cellIntersect));
- $stack->push('Error', Functions::null(), null);
- } else {
- $cellRef = Coordinate::stringFromColumnIndex(min($oCol) + 1) . min($oRow) . ':' .
- Coordinate::stringFromColumnIndex(max($oCol) + 1) . max($oRow);
- $this->debugLog->writeDebugLog('Evaluation Result is ', $this->showTypeDetails($cellIntersect));
- $stack->push('Value', $cellIntersect, $cellRef);
- }
- break;
- }
- // if the token is a unary operator, pop one value off the stack, do the operation, and push it back on
- } elseif (($token === '~') || ($token === '%')) {
- if (($arg = $stack->pop()) === null) {
- return $this->raiseFormulaError('Internal error - Operand value missing from stack');
- }
- $arg = $arg['value'];
- if ($token === '~') {
- $this->debugLog->writeDebugLog('Evaluating Negation of ', $this->showValue($arg));
- $multiplier = -1;
- } else {
- $this->debugLog->writeDebugLog('Evaluating Percentile of ', $this->showValue($arg));
- $multiplier = 0.01;
- }
- if (is_array($arg)) {
- self::checkMatrixOperands($arg, $multiplier, 2);
- try {
- $matrix1 = new Shared\JAMA\Matrix($arg);
- $matrixResult = $matrix1->arrayTimesEquals($multiplier);
- $result = $matrixResult->getArray();
- } catch (\Exception $ex) {
- $this->debugLog->writeDebugLog('JAMA Matrix Exception: ', $ex->getMessage());
- $result = '#VALUE!';
- }
- $this->debugLog->writeDebugLog('Evaluation Result is ', $this->showTypeDetails($result));
- $stack->push('Value', $result);
- if (isset($storeKey)) {
- $branchStore[$storeKey] = $result;
- }
- } else {
- $this->executeNumericBinaryOperation($multiplier, $arg, '*', 'arrayTimesEquals', $stack);
- }
- } elseif (preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '$/i', $token ?? '', $matches)) {
- $cellRef = null;
- if (isset($matches[8])) {
- if ($pCell === null) {
- // We can't access the range, so return a REF error
- $cellValue = Functions::REF();
- } else {
- $cellRef = $matches[6] . $matches[7] . ':' . $matches[9] . $matches[10];
- if ($matches[2] > '') {
- $matches[2] = trim($matches[2], "\"'");
- if ((strpos($matches[2], '[') !== false) || (strpos($matches[2], ']') !== false)) {
- // It's a Reference to an external spreadsheet (not currently supported)
- return $this->raiseFormulaError('Unable to access External Workbook');
- }
- $matches[2] = trim($matches[2], "\"'");
- $this->debugLog->writeDebugLog('Evaluating Cell Range ', $cellRef, ' in worksheet ', $matches[2]);
- if ($pCellParent !== null) {
- $cellValue = $this->extractCellRange($cellRef, $this->spreadsheet->getSheetByName($matches[2]), false);
- } else {
- return $this->raiseFormulaError('Unable to access Cell Reference');
- }
- $this->debugLog->writeDebugLog('Evaluation Result for cells ', $cellRef, ' in worksheet ', $matches[2], ' is ', $this->showTypeDetails($cellValue));
- } else {
- $this->debugLog->writeDebugLog('Evaluating Cell Range ', $cellRef, ' in current worksheet');
- if ($pCellParent !== null) {
- $cellValue = $this->extractCellRange($cellRef, $pCellWorksheet, false);
- } else {
- return $this->raiseFormulaError('Unable to access Cell Reference');
- }
- $this->debugLog->writeDebugLog('Evaluation Result for cells ', $cellRef, ' is ', $this->showTypeDetails($cellValue));
- }
- }
- } else {
- if ($pCell === null) {
- // We can't access the cell, so return a REF error
- $cellValue = Functions::REF();
- } else {
- $cellRef = $matches[6] . $matches[7];
- if ($matches[2] > '') {
- $matches[2] = trim($matches[2], "\"'");
- if ((strpos($matches[2], '[') !== false) || (strpos($matches[2], ']') !== false)) {
- // It's a Reference to an external spreadsheet (not currently supported)
- return $this->raiseFormulaError('Unable to access External Workbook');
- }
- $this->debugLog->writeDebugLog('Evaluating Cell ', $cellRef, ' in worksheet ', $matches[2]);
- if ($pCellParent !== null) {
- $cellSheet = $this->spreadsheet->getSheetByName($matches[2]);
- if ($cellSheet && $cellSheet->cellExists($cellRef)) {
- $cellValue = $this->extractCellRange($cellRef, $this->spreadsheet->getSheetByName($matches[2]), false);
- $pCell->attach($pCellParent);
- } else {
- $cellRef = ($cellSheet !== null) ? "{$matches[2]}!{$cellRef}" : $cellRef;
- $cellValue = null;
- }
- } else {
- return $this->raiseFormulaError('Unable to access Cell Reference');
- }
- $this->debugLog->writeDebugLog('Evaluation Result for cell ', $cellRef, ' in worksheet ', $matches[2], ' is ', $this->showTypeDetails($cellValue));
- } else {
- $this->debugLog->writeDebugLog('Evaluating Cell ', $cellRef, ' in current worksheet');
- if ($pCellParent->has($cellRef)) {
- $cellValue = $this->extractCellRange($cellRef, $pCellWorksheet, false);
- $pCell->attach($pCellParent);
- } else {
- $cellValue = null;
- }
- $this->debugLog->writeDebugLog('Evaluation Result for cell ', $cellRef, ' is ', $this->showTypeDetails($cellValue));
- }
- }
- }
- $stack->push('Cell Value', $cellValue, $cellRef);
- if (isset($storeKey)) {
- $branchStore[$storeKey] = $cellValue;
- }
- // if the token is a function, pop arguments off the stack, hand them to the function, and push the result back on
- } elseif (preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', $token ?? '', $matches)) {
- if ($pCellParent) {
- $pCell->attach($pCellParent);
- }
- $functionName = $matches[1];
- $argCount = $stack->pop();
- $argCount = $argCount['value'];
- if ($functionName != 'MKMATRIX') {
- $this->debugLog->writeDebugLog('Evaluating Function ', self::localeFunc($functionName), '() with ', (($argCount == 0) ? 'no' : $argCount), ' argument', (($argCount == 1) ? '' : 's'));
- }
- if ((isset(self::$phpSpreadsheetFunctions[$functionName])) || (isset(self::$controlFunctions[$functionName]))) { // function
- $passByReference = false;
- $passCellReference = false;
- $functionCall = null;
- if (isset(self::$phpSpreadsheetFunctions[$functionName])) {
- $functionCall = self::$phpSpreadsheetFunctions[$functionName]['functionCall'];
- $passByReference = isset(self::$phpSpreadsheetFunctions[$functionName]['passByReference']);
- $passCellReference = isset(self::$phpSpreadsheetFunctions[$functionName]['passCellReference']);
- } elseif (isset(self::$controlFunctions[$functionName])) {
- $functionCall = self::$controlFunctions[$functionName]['functionCall'];
- $passByReference = isset(self::$controlFunctions[$functionName]['passByReference']);
- $passCellReference = isset(self::$controlFunctions[$functionName]['passCellReference']);
- }
- // get the arguments for this function
- $args = $argArrayVals = [];
- for ($i = 0; $i < $argCount; ++$i) {
- $arg = $stack->pop();
- $a = $argCount - $i - 1;
- if (
- ($passByReference) &&
- (isset(self::$phpSpreadsheetFunctions[$functionName]['passByReference'][$a])) &&
- (self::$phpSpreadsheetFunctions[$functionName]['passByReference'][$a])
- ) {
- if ($arg['reference'] === null) {
- $args[] = $cellID;
- if ($functionName != 'MKMATRIX') {
- $argArrayVals[] = $this->showValue($cellID);
- }
- } else {
- $args[] = $arg['reference'];
- if ($functionName != 'MKMATRIX') {
- $argArrayVals[] = $this->showValue($arg['reference']);
- }
- }
- } else {
- $args[] = self::unwrapResult($arg['value']);
- if ($functionName != 'MKMATRIX') {
- $argArrayVals[] = $this->showValue($arg['value']);
- }
- }
- }
- // Reverse the order of the arguments
- krsort($args);
- if (($passByReference) && ($argCount == 0)) {
- $args[] = $cellID;
- $argArrayVals[] = $this->showValue($cellID);
- }
- if ($functionName != 'MKMATRIX') {
- if ($this->debugLog->getWriteDebugLog()) {
- krsort($argArrayVals);
- $this->debugLog->writeDebugLog('Evaluating ', self::localeFunc($functionName), '( ', implode(self::$localeArgumentSeparator . ' ', Functions::flattenArray($argArrayVals)), ' )');
- }
- }
- // Process the argument with the appropriate function call
- $args = $this->addCellReference($args, $passCellReference, $functionCall, $pCell);
- if (!is_array($functionCall)) {
- foreach ($args as &$arg) {
- $arg = Functions::flattenSingleValue($arg);
- }
- unset($arg);
- }
- $result = call_user_func_array($functionCall, $args);
- if ($functionName != 'MKMATRIX') {
- $this->debugLog->writeDebugLog('Evaluation Result for ', self::localeFunc($functionName), '() function call is ', $this->showTypeDetails($result));
- }
- $stack->push('Value', self::wrapResult($result));
- if (isset($storeKey)) {
- $branchStore[$storeKey] = $result;
- }
- }
- } else {
- // if the token is a number, boolean, string or an Excel error, push it onto the stack
- if (isset(self::$excelConstants[strtoupper($token ?? '')])) {
- $excelConstant = strtoupper($token);
- $stack->push('Constant Value', self::$excelConstants[$excelConstant]);
- if (isset($storeKey)) {
- $branchStore[$storeKey] = self::$excelConstants[$excelConstant];
- }
- $this->debugLog->writeDebugLog('Evaluating Constant ', $excelConstant, ' as ', $this->showTypeDetails(self::$excelConstants[$excelConstant]));
- } elseif ((is_numeric($token)) || ($token === null) || (is_bool($token)) || ($token == '') || ($token[0] == self::FORMULA_STRING_QUOTE) || ($token[0] == '#')) {
- $stack->push('Value', $token);
- if (isset($storeKey)) {
- $branchStore[$storeKey] = $token;
- }
- // if the token is a named range or formula, evaluate it and push the result onto the stack
- } elseif (preg_match('/^' . self::CALCULATION_REGEXP_DEFINEDNAME . '$/miu', $token, $matches)) {
- $definedName = $matches[6];
- if ($pCell === null || $pCellWorksheet === null) {
- return $this->raiseFormulaError("undefined name '$token'");
- }
- $this->debugLog->writeDebugLog('Evaluating Defined Name ', $definedName);
- $namedRange = DefinedName::resolveName($definedName, $pCellWorksheet);
- if ($namedRange === null) {
- return $this->raiseFormulaError("undefined name '$definedName'");
- }
- $result = $this->evaluateDefinedName($pCell, $namedRange, $pCellWorksheet, $stack);
- if (isset($storeKey)) {
- $branchStore[$storeKey] = $result;
- }
- } else {
- return $this->raiseFormulaError("undefined name '$token'");
- }
- }
- }
- // when we're out of tokens, the stack should have a single element, the final result
- if ($stack->count() != 1) {
- return $this->raiseFormulaError('internal error');
- }
- $output = $stack->pop();
- $output = $output['value'];
- return $output;
- }
- private function validateBinaryOperand(&$operand, &$stack)
- {
- if (is_array($operand)) {
- if ((count($operand, COUNT_RECURSIVE) - count($operand)) == 1) {
- do {
- $operand = array_pop($operand);
- } while (is_array($operand));
- }
- }
- // Numbers, matrices and booleans can pass straight through, as they're already valid
- if (is_string($operand)) {
- // We only need special validations for the operand if it is a string
- // Start by stripping off the quotation marks we use to identify true excel string values internally
- if ($operand > '' && $operand[0] == self::FORMULA_STRING_QUOTE) {
- $operand = self::unwrapResult($operand);
- }
- // If the string is a numeric value, we treat it as a numeric, so no further testing
- if (!is_numeric($operand)) {
- // If not a numeric, test to see if the value is an Excel error, and so can't be used in normal binary operations
- if ($operand > '' && $operand[0] == '#') {
- $stack->push('Value', $operand);
- $this->debugLog->writeDebugLog('Evaluation Result is ', $this->showTypeDetails($operand));
- return false;
- } elseif (!Shared\StringHelper::convertToNumberIfFraction($operand)) {
- // If not a numeric or a fraction, then it's a text string, and so can't be used in mathematical binary operations
- $stack->push('Error', '#VALUE!');
- $this->debugLog->writeDebugLog('Evaluation Result is a ', $this->showTypeDetails('#VALUE!'));
- return false;
- }
- }
- }
- // return a true if the value of the operand is one that we can use in normal binary operations
- return true;
- }
- /**
- * @param null|string $cellID
- * @param mixed $operand1
- * @param mixed $operand2
- * @param string $operation
- *
- * @return array
- */
- private function executeArrayComparison($cellID, $operand1, $operand2, $operation, Stack &$stack, bool $recursingArrays)
- {
- $result = [];
- if (!is_array($operand2)) {
- // Operand 1 is an array, Operand 2 is a scalar
- foreach ($operand1 as $x => $operandData) {
- $this->debugLog->writeDebugLog('Evaluating Comparison ', $this->showValue($operandData), ' ', $operation, ' ', $this->showValue($operand2));
- $this->executeBinaryComparisonOperation($cellID, $operandData, $operand2, $operation, $stack);
- $r = $stack->pop();
- $result[$x] = $r['value'];
- }
- } elseif (!is_array($operand1)) {
- // Operand 1 is a scalar, Operand 2 is an array
- foreach ($operand2 as $x => $operandData) {
- $this->debugLog->writeDebugLog('Evaluating Comparison ', $this->showValue($operand1), ' ', $operation, ' ', $this->showValue($operandData));
- $this->executeBinaryComparisonOperation($cellID, $operand1, $operandData, $operation, $stack);
- $r = $stack->pop();
- $result[$x] = $r['value'];
- }
- } else {
- // Operand 1 and Operand 2 are both arrays
- if (!$recursingArrays) {
- self::checkMatrixOperands($operand1, $operand2, 2);
- }
- foreach ($operand1 as $x => $operandData) {
- $this->debugLog->writeDebugLog('Evaluating Comparison ', $this->showValue($operandData), ' ', $operation, ' ', $this->showValue($operand2[$x]));
- $this->executeBinaryComparisonOperation($cellID, $operandData, $operand2[$x], $operation, $stack, true);
- $r = $stack->pop();
- $result[$x] = $r['value'];
- }
- }
- // Log the result details
- $this->debugLog->writeDebugLog('Comparison Evaluation Result is ', $this->showTypeDetails($result));
- // And push the result onto the stack
- $stack->push('Array', $result);
- return $result;
- }
- /**
- * @param null|string $cellID
- * @param mixed $operand1
- * @param mixed $operand2
- * @param string $operation
- * @param bool $recursingArrays
- *
- * @return mixed
- */
- private function executeBinaryComparisonOperation($cellID, $operand1, $operand2, $operation, Stack &$stack, $recursingArrays = false)
- {
- // If we're dealing with matrix operations, we want a matrix result
- if ((is_array($operand1)) || (is_array($operand2))) {
- return $this->executeArrayComparison($cellID, $operand1, $operand2, $operation, $stack, $recursingArrays);
- }
- // Simple validate the two operands if they are string values
- if (is_string($operand1) && $operand1 > '' && $operand1[0] == self::FORMULA_STRING_QUOTE) {
- $operand1 = self::unwrapResult($operand1);
- }
- if (is_string($operand2) && $operand2 > '' && $operand2[0] == self::FORMULA_STRING_QUOTE) {
- $operand2 = self::unwrapResult($operand2);
- }
- // Use case insensitive comparaison if not OpenOffice mode
- if (Functions::getCompatibilityMode() != Functions::COMPATIBILITY_OPENOFFICE) {
- if (is_string($operand1)) {
- $operand1 = Shared\StringHelper::strToUpper($operand1);
- }
- if (is_string($operand2)) {
- $operand2 = Shared\StringHelper::strToUpper($operand2);
- }
- }
- $useLowercaseFirstComparison = is_string($operand1) && is_string($operand2) && Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE;
- // execute the necessary operation
- switch ($operation) {
- // Greater than
- case '>':
- if ($useLowercaseFirstComparison) {
- $result = $this->strcmpLowercaseFirst($operand1, $operand2) > 0;
- } else {
- $result = ($operand1 > $operand2);
- }
- break;
- // Less than
- case '<':
- if ($useLowercaseFirstComparison) {
- $result = $this->strcmpLowercaseFirst($operand1, $operand2) < 0;
- } else {
- $result = ($operand1 < $operand2);
- }
- break;
- // Equality
- case '=':
- if (is_numeric($operand1) && is_numeric($operand2)) {
- $result = (abs($operand1 - $operand2) < $this->delta);
- } else {
- $result = $this->strcmpAllowNull($operand1, $operand2) == 0;
- }
- break;
- // Greater than or equal
- case '>=':
- if (is_numeric($operand1) && is_numeric($operand2)) {
- $result = ((abs($operand1 - $operand2) < $this->delta) || ($operand1 > $operand2));
- } elseif ($useLowercaseFirstComparison) {
- $result = $this->strcmpLowercaseFirst($operand1, $operand2) >= 0;
- } else {
- $result = $this->strcmpAllowNull($operand1, $operand2) >= 0;
- }
- break;
- // Less than or equal
- case '<=':
- if (is_numeric($operand1) && is_numeric($operand2)) {
- $result = ((abs($operand1 - $operand2) < $this->delta) || ($operand1 < $operand2));
- } elseif ($useLowercaseFirstComparison) {
- $result = $this->strcmpLowercaseFirst($operand1, $operand2) <= 0;
- } else {
- $result = $this->strcmpAllowNull($operand1, $operand2) <= 0;
- }
- break;
- // Inequality
- case '<>':
- if (is_numeric($operand1) && is_numeric($operand2)) {
- $result = (abs($operand1 - $operand2) > 1E-14);
- } else {
- $result = $this->strcmpAllowNull($operand1, $operand2) != 0;
- }
- break;
- default:
- throw new Exception('Unsupported binary comparison operation');
- }
- // Log the result details
- $this->debugLog->writeDebugLog('Evaluation Result is ', $this->showTypeDetails($result));
- // And push the result onto the stack
- $stack->push('Value', $result);
- return $result;
- }
- /**
- * Compare two strings in the same way as strcmp() except that lowercase come before uppercase letters.
- *
- * @param null|string $str1 First string value for the comparison
- * @param null|string $str2 Second string value for the comparison
- *
- * @return int
- */
- private function strcmpLowercaseFirst($str1, $str2)
- {
- $inversedStr1 = Shared\StringHelper::strCaseReverse($str1);
- $inversedStr2 = Shared\StringHelper::strCaseReverse($str2);
- return strcmp($inversedStr1 ?? '', $inversedStr2 ?? '');
- }
- /**
- * PHP8.1 deprecates passing null to strcmp.
- *
- * @param null|string $str1 First string value for the comparison
- * @param null|string $str2 Second string value for the comparison
- *
- * @return int
- */
- private function strcmpAllowNull($str1, $str2)
- {
- return strcmp($str1 ?? '', $str2 ?? '');
- }
- /**
- * @param mixed $operand1
- * @param mixed $operand2
- * @param mixed $operation
- * @param string $matrixFunction
- * @param mixed $stack
- *
- * @return bool|mixed
- */
- private function executeNumericBinaryOperation($operand1, $operand2, $operation, $matrixFunction, &$stack)
- {
- // Validate the two operands
- if (!$this->validateBinaryOperand($operand1, $stack)) {
- return false;
- }
- if (!$this->validateBinaryOperand($operand2, $stack)) {
- return false;
- }
- // If either of the operands is a matrix, we need to treat them both as matrices
- // (converting the other operand to a matrix if need be); then perform the required
- // matrix operation
- if ((is_array($operand1)) || (is_array($operand2))) {
- // Ensure that both operands are arrays/matrices of the same size
- self::checkMatrixOperands($operand1, $operand2, 2);
- try {
- // Convert operand 1 from a PHP array to a matrix
- $matrix = new Shared\JAMA\Matrix($operand1);
- // Perform the required operation against the operand 1 matrix, passing in operand 2
- $matrixResult = $matrix->$matrixFunction($operand2);
- $result = $matrixResult->getArray();
- } catch (\Exception $ex) {
- $this->debugLog->writeDebugLog('JAMA Matrix Exception: ', $ex->getMessage());
- $result = '#VALUE!';
- }
- } else {
- if (
- (Functions::getCompatibilityMode() != Functions::COMPATIBILITY_OPENOFFICE) &&
- ((is_string($operand1) && !is_numeric($operand1) && strlen($operand1) > 0) ||
- (is_string($operand2) && !is_numeric($operand2) && strlen($operand2) > 0))
- ) {
- $result = Functions::VALUE();
- } else {
- // If we're dealing with non-matrix operations, execute the necessary operation
- switch ($operation) {
- // Addition
- case '+':
- $result = $operand1 + $operand2;
- break;
- // Subtraction
- case '-':
- $result = $operand1 - $operand2;
- break;
- // Multiplication
- case '*':
- $result = $operand1 * $operand2;
- break;
- // Division
- case '/':
- if ($operand2 == 0) {
- // Trap for Divide by Zero error
- $stack->push('Error', '#DIV/0!');
- $this->debugLog->writeDebugLog('Evaluation Result is ', $this->showTypeDetails('#DIV/0!'));
- return false;
- }
- $result = $operand1 / $operand2;
- break;
- // Power
- case '^':
- $result = $operand1 ** $operand2;
- break;
- default:
- throw new Exception('Unsupported numeric binary operation');
- }
- }
- }
- // Log the result details
- $this->debugLog->writeDebugLog('Evaluation Result is ', $this->showTypeDetails($result));
- // And push the result onto the stack
- $stack->push('Value', $result);
- return $result;
- }
- // trigger an error, but nicely, if need be
- protected function raiseFormulaError($errorMessage)
- {
- $this->formulaError = $errorMessage;
- $this->cyclicReferenceStack->clear();
- if (!$this->suppressFormulaErrors) {
- throw new Exception($errorMessage);
- }
- trigger_error($errorMessage, E_USER_ERROR);
- return false;
- }
- /**
- * Extract range values.
- *
- * @param string $pRange String based range representation
- * @param Worksheet $pSheet Worksheet
- * @param bool $resetLog Flag indicating whether calculation log should be reset or not
- *
- * @return mixed Array of values in range if range contains more than one element. Otherwise, a single value is returned.
- */
- public function extractCellRange(&$pRange = 'A1', ?Worksheet $pSheet = null, $resetLog = true)
- {
- // Return value
- $returnValue = [];
- if ($pSheet !== null) {
- $pSheetName = $pSheet->getTitle();
- if (strpos($pRange, '!') !== false) {
- [$pSheetName, $pRange] = Worksheet::extractSheetTitle($pRange, true);
- $pSheet = $this->spreadsheet->getSheetByName($pSheetName);
- }
- // Extract range
- $aReferences = Coordinate::extractAllCellReferencesInRange($pRange);
- $pRange = $pSheetName . '!' . $pRange;
- if (!isset($aReferences[1])) {
- $currentCol = '';
- $currentRow = 0;
- // Single cell in range
- sscanf($aReferences[0], '%[A-Z]%d', $currentCol, $currentRow);
- if ($pSheet->cellExists($aReferences[0])) {
- $returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog);
- } else {
- $returnValue[$currentRow][$currentCol] = null;
- }
- } else {
- // Extract cell data for all cells in the range
- foreach ($aReferences as $reference) {
- $currentCol = '';
- $currentRow = 0;
- // Extract range
- sscanf($reference, '%[A-Z]%d', $currentCol, $currentRow);
- if ($pSheet->cellExists($reference)) {
- $returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog);
- } else {
- $returnValue[$currentRow][$currentCol] = null;
- }
- }
- }
- }
- return $returnValue;
- }
- /**
- * Extract range values.
- *
- * @param string $pRange String based range representation
- * @param Worksheet $pSheet Worksheet
- * @param bool $resetLog Flag indicating whether calculation log should be reset or not
- *
- * @return mixed Array of values in range if range contains more than one element. Otherwise, a single value is returned.
- */
- public function extractNamedRange(&$pRange = 'A1', ?Worksheet $pSheet = null, $resetLog = true)
- {
- // Return value
- $returnValue = [];
- if ($pSheet !== null) {
- $pSheetName = $pSheet->getTitle();
- if (strpos($pRange, '!') !== false) {
- [$pSheetName, $pRange] = Worksheet::extractSheetTitle($pRange, true);
- $pSheet = $this->spreadsheet->getSheetByName($pSheetName);
- }
- // Named range?
- $namedRange = DefinedName::resolveName($pRange, $pSheet);
- if ($namedRange === null) {
- return Functions::REF();
- }
- $pSheet = $namedRange->getWorksheet();
- $pRange = $namedRange->getValue();
- $splitRange = Coordinate::splitRange($pRange);
- // Convert row and column references
- if (ctype_alpha($splitRange[0][0])) {
- $pRange = $splitRange[0][0] . '1:' . $splitRange[0][1] . $namedRange->getWorksheet()->getHighestRow();
- } elseif (ctype_digit($splitRange[0][0])) {
- $pRange = 'A' . $splitRange[0][0] . ':' . $namedRange->getWorksheet()->getHighestColumn() . $splitRange[0][1];
- }
- // Extract range
- $aReferences = Coordinate::extractAllCellReferencesInRange($pRange);
- if (!isset($aReferences[1])) {
- // Single cell (or single column or row) in range
- [$currentCol, $currentRow] = Coordinate::coordinateFromString($aReferences[0]);
- if ($pSheet->cellExists($aReferences[0])) {
- $returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog);
- } else {
- $returnValue[$currentRow][$currentCol] = null;
- }
- } else {
- // Extract cell data for all cells in the range
- foreach ($aReferences as $reference) {
- // Extract range
- [$currentCol, $currentRow] = Coordinate::coordinateFromString($reference);
- if ($pSheet->cellExists($reference)) {
- $returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog);
- } else {
- $returnValue[$currentRow][$currentCol] = null;
- }
- }
- }
- }
- return $returnValue;
- }
- /**
- * Is a specific function implemented?
- *
- * @param string $pFunction Function Name
- *
- * @return bool
- */
- public function isImplemented($pFunction)
- {
- $pFunction = strtoupper($pFunction);
- $notImplemented = !isset(self::$phpSpreadsheetFunctions[$pFunction]) || (is_array(self::$phpSpreadsheetFunctions[$pFunction]['functionCall']) && self::$phpSpreadsheetFunctions[$pFunction]['functionCall'][1] === 'DUMMY');
- return !$notImplemented;
- }
- /**
- * Get a list of all implemented functions as an array of function objects.
- */
- public function getFunctions(): array
- {
- return self::$phpSpreadsheetFunctions;
- }
- /**
- * Get a list of implemented Excel function names.
- *
- * @return array
- */
- public function getImplementedFunctionNames()
- {
- $returnValue = [];
- foreach (self::$phpSpreadsheetFunctions as $functionName => $function) {
- if ($this->isImplemented($functionName)) {
- $returnValue[] = $functionName;
- }
- }
- return $returnValue;
- }
- /**
- * Add cell reference if needed while making sure that it is the last argument.
- *
- * @param bool $passCellReference
- * @param array|string $functionCall
- *
- * @return array
- */
- private function addCellReference(array $args, $passCellReference, $functionCall, ?Cell $pCell = null)
- {
- if ($passCellReference) {
- if (is_array($functionCall)) {
- $className = $functionCall[0];
- $methodName = $functionCall[1];
- $reflectionMethod = new ReflectionMethod($className, $methodName);
- $argumentCount = count($reflectionMethod->getParameters());
- while (count($args) < $argumentCount - 1) {
- $args[] = null;
- }
- }
- $args[] = $pCell;
- }
- return $args;
- }
- private function getUnusedBranchStoreKey()
- {
- $storeKeyValue = 'storeKey-' . $this->branchStoreKeyCounter;
- ++$this->branchStoreKeyCounter;
- return $storeKeyValue;
- }
- private function getTokensAsString($tokens)
- {
- $tokensStr = array_map(function ($token) {
- $value = $token['value'] ?? 'no value';
- while (is_array($value)) {
- $value = array_pop($value);
- }
- return $value;
- }, $tokens);
- return '[ ' . implode(' | ', $tokensStr) . ' ]';
- }
- /**
- * @return mixed|string
- */
- private function evaluateDefinedName(Cell $pCell, DefinedName $namedRange, Worksheet $pCellWorksheet, Stack $stack)
- {
- $definedNameScope = $namedRange->getScope();
- if ($definedNameScope !== null && $definedNameScope !== $pCellWorksheet) {
- // The defined name isn't in our current scope, so #REF
- $result = Functions::REF();
- $stack->push('Error', $result, $namedRange->getName());
- return $result;
- }
- $definedNameValue = $namedRange->getValue();
- $definedNameType = $namedRange->isFormula() ? 'Formula' : 'Range';
- $definedNameWorksheet = $namedRange->getWorksheet();
- if ($definedNameValue[0] !== '=') {
- $definedNameValue = '=' . $definedNameValue;
- }
- $this->debugLog->writeDebugLog("Defined Name is a {$definedNameType} with a value of {$definedNameValue}");
- $recursiveCalculationCell = ($definedNameWorksheet !== null && $definedNameWorksheet !== $pCellWorksheet)
- ? $definedNameWorksheet->getCell('A1')
- : $pCell;
- $recursiveCalculationCellAddress = $recursiveCalculationCell->getCoordinate();
- // Adjust relative references in ranges and formulae so that we execute the calculation for the correct rows and columns
- $definedNameValue = self::$referenceHelper->updateFormulaReferencesAnyWorksheet(
- $definedNameValue,
- Coordinate::columnIndexFromString($pCell->getColumn()) - 1,
- $pCell->getRow() - 1
- );
- $this->debugLog->writeDebugLog("Value adjusted for relative references is {$definedNameValue}");
- $recursiveCalculator = new self($this->spreadsheet);
- $recursiveCalculator->getDebugLog()->setWriteDebugLog($this->getDebugLog()->getWriteDebugLog());
- $recursiveCalculator->getDebugLog()->setEchoDebugLog($this->getDebugLog()->getEchoDebugLog());
- $result = $recursiveCalculator->_calculateFormulaValue($definedNameValue, $recursiveCalculationCellAddress, $recursiveCalculationCell);
- if ($this->getDebugLog()->getWriteDebugLog()) {
- $this->debugLog->mergeDebugLog(array_slice($recursiveCalculator->getDebugLog()->getLog(), 3));
- $this->debugLog->writeDebugLog("Evaluation Result for Named {$definedNameType} {$namedRange->getName()} is {$this->showTypeDetails($result)}");
- }
- $stack->push('Defined Name', $result, $namedRange->getName());
- return $result;
- }
- }
|