Calculation.php 202 KB

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