Calculation.Class.php 190 KB

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