!function(){"undefined"==typeof window&&(window=root);var t=(window.excelFormulaUtilities=window.excelFormulaUtilities||{},window.excelFormulaUtilities.core={});window.excelFormulaUtilities.string=window.excelFormulaUtilities.string||{};var e=(window.excelFormulaUtilities.string.formatStr=function(t){for(var e=t,n=1;n<arguments.length;n++){var r=n-1,o=new RegExp("\\{{1}"+r.toString()+"{1}\\}{1}","g");e=e.replace(o,arguments[n])}return e},window.excelFormulaUtilities.string.trim=function(t){return t.replace(/^\s|\s$/,"")},window.excelFormulaUtilities.string.trim=function(t){return t.replace(/^(?:\s| |<\s*br\s*\/*\s*>)*|(?:\s| |<\s*br\s*\/*\s*>)*$/,"")},t.isFunction=function(t){return"function"==typeof t}),n=t.isArray=function(t){return"object"==typeof t&&t.length},r=t.isWindow=function(){return obj&&"object"==typeof obj&&"setInterval"in obj},o=t.isPlainObject=function(t){if(!t||"object"!=typeof t||t.nodeType||r(t))return!1;if(t.constructor&&!hasOwnProperty.call(t,"constructor")&&!hasOwnProperty.call(t.constructor.prototype,"isPrototypeOf"))return!1;var e;for(e in t);return void 0===e||hasOwnProperty.call(t,e)};t.extend=function(){var r,i,a,s,p,u,l=arguments[0]||{},c=1,d=arguments.length,g=!1;for("boolean"==typeof l&&(g=l,l=arguments[1]||{},c=2),"object"==typeof l||e(l)||(l={}),d===c&&(l=this,--c);c<d;c++)if(null!=(r=arguments[c]))for(i in r)a=l[i],s=r[i],l!==s&&(g&&s&&(o(s)||(p=n(s)))?(p?(p=!1,u=a&&n(a)?a:[]):u=a&&o(a)?a:{},l[i]=t.extend(g,u,s)):void 0!==s&&(l[i]=s));return l}}(),function(t){function e(t,e,n){this.value=t,this.type=e,this.subtype=n}function n(){this.items=[],this.add=function(t,n,r){r||(r="");var o=new e(t,n,r);return this.addRef(o),o},this.addRef=function(t){this.items.push(t)},this.index=-1,this.reset=function(){this.index=-1},this.BOF=function(){return this.index<=0},this.EOF=function(){return this.index>=this.items.length-1},this.moveNext=function(){return!this.EOF()&&(this.index+=1,!0)},this.current=function(){return this.index===-1?null:this.items[this.index]},this.next=function(){return this.EOF()?null:this.items[this.index+1]},this.previous=function(){return this.index<1?null:this.items[this.index-1]}}function r(){this.items=[],this.push=function(t){this.items.push(t)},this.pop=function(t){var n=this.items.pop();return new e(t||"",n.type,k)},this.token=function(){return this.items.length>0?this.items[this.items.length-1]:null},this.value=function(){return this.token()?this.token().value.toString():""},this.type=function(){return this.token()?this.token().type.toString():""},this.subtype=function(){return this.token()?this.token().subtype.toString():""}}function o(e){for(var o=new n,i=new r,a=0,s=function(){return e.substr(a,1)},p=function(){return e.substr(a,2)},u=function(){return e.substr(a+1,1)},l=function(){return a>=e.length},c="",C=!1,N=!1,Y=!1,K=!1,B=/^[1-9]{1}(\.[0-9]+)?E{1}$/;e.length>0;){if(" "!==e.substr(0,1)){"="===e.substr(0,1)&&(e=e.substr(1));break}e=e.substr(1)}for(;!l();)if(C)'"'===s()?'"'===u()?(c+='"',a+=1):(C=!1,o.add(c,g,v),c=""):c+=s(),a+=1;else if(N)"'"===s()?"'"===u()?(c+="'",a+=1):(N=!1,c+="'"):c+=s(),a+=1;else if(Y)"]"===s()&&(Y=!1),c+=s(),a+=1;else if(K)c+=s(),a+=1,",#NULL!,#DIV/0!,#VALUE!,#REF!,#NAME?,#NUM!,#N/A,".indexOf(","+c+",")!==-1&&(K=!1,o.add(c,g,R),c="");else if("+-".indexOf(s())!==-1&&c.length>1&&c.match(B))c+=s(),a+=1;else if('"'!==s())if("'"!==s())if("["!==s())if("#"!==s())if("{"!==s())if(";"!==s())if("}"!==s())if(" "!==s())",>=,<=,<>,".indexOf(","+p()+",")===-1?"+-*/^&=><".indexOf(s())===-1?"%".indexOf(s())===-1?"("!==s()?","!==s()||t.excelFormulaUtilities.isEu?")"!==s()?(c+=s(),a+=1):(c.length>0&&(o.add(c,g),c=""),o.addRef(i.pop()),a+=1):(c.length>0&&(o.add(c,g),c=""),i.type()!==f?o.add(s(),h,P):o.add(s(),S),a+=1):(c.length>0?(i.push(o.add(c,f,O)),c=""):i.push(o.add("",m,O)),a+=1):(c.length>0&&(o.add(c,g),c=""),o.add(s(),y),a+=1):(c.length>0&&(o.add(c,g),c=""),o.add(s(),h),a+=1):(c.length>0&&(o.add(c,g),c=""),o.add(p(),h,E),a+=2);else for(c.length>0&&(o.add(c,g),c=""),o.add("",T),a+=1;" "===s()&&!l();)a+=1;else c.length>0&&(o.add(c,g),c=""),o.addRef(i.pop("ARRAYROWSTOP")),o.addRef(i.pop("ARRAYSTOP")),a+=1;else{if(t.excelFormulaUtilities.isEu){c.length>0&&(o.add(c,g),c=""),i.type()!==f?o.add(s(),h,P):o.add(s(),S),a+=1;continue}c.length>0&&(o.add(c,g),c=""),o.addRef(i.pop()),o.add(",",S),i.push(o.add("ARRAYROW",f,O)),a+=1}else c.length>0&&(o.add(c,x),c=""),i.push(o.add("ARRAY",f,O)),i.push(o.add("ARRAYROW",f,O)),a+=1;else c.length>0&&(o.add(c,x),c=""),K=!0,c+=s(),a+=1;else Y=!0,c+=s(),a+=1;else c.length>0&&(o.add(c,x),c=""),c="'",N=!0,a+=1;else c.length>0&&(o.add(c,x),c=""),C=!0,a+=1;c.length>0&&o.add(c,g);for(var I=new n;o.moveNext();)if(c=o.current(),c.type.toString()!==T)I.addRef(c);else{var L=o.BOF()||o.EOF();L=L&&(o.previous().type.toString()===f&&o.previous().subtype.toString()===k||o.previous().type.toString()===m&&o.previous().subtype.toString()===k||o.previous().type.toString()===g),L=L&&(o.next().type.toString()===f&&o.next().subtype.toString()===O||o.next().type.toString()===m&&o.next().subtype.toString()===O||o.next().type.toString()===g),L&&I.add(c.value.toString(),h,F)}for(;I.moveNext();)c=I.current(),c.type.toString()!==h||"-"!==c.value.toString()?c.type.toString()!==h||"+"!==c.value.toString()?c.type.toString()!==h||0!==c.subtype.length?c.type.toString()!==g||0!==c.subtype.length?c.type.toString()!==f||"@"===c.value.substr(0,1)&&(c.value=c.value.substr(1).toString()):isNaN(parseFloat(c.value))?"TRUE"===c.value.toString()||"FALSE"===c.value.toString()?c.subtype=E.toString():c.subtype=_.toString():c.subtype=w.toString():"<>=".indexOf(c.value.substr(0,1))!==-1?c.subtype=E.toString():"&"===c.value.toString()?c.subtype=U.toString():c.subtype=A.toString():I.BOF()?c.type=d.toString():I.previous().type.toString()===f&&I.previous().subtype.toString()===k||I.previous().type.toString()===m&&I.previous().subtype.toString()===k||I.previous().type.toString()===y||I.previous().type.toString()===g?c.subtype=A.toString():c.type=d.toString():I.BOF()?c.type=b.toString():I.previous().type.toString()===f&&I.previous().subtype.toString()===k||I.previous().type.toString()===m&&I.previous().subtype.toString()===k||I.previous().type.toString()===y||I.previous().type.toString()===g?c.subtype=A.toString():c.type=b.toString();for(I.reset(),o=new n;I.moveNext();)I.current().type.toString()!==d&&o.addRef(I.current());return o.reset(),o}function i(t,e){if(!RegExp("[a-z]+[0-9]+:[a-z]+[0-9]+","gi").test(t))throw"This is not a valid range: "+t;var n=t.split(":"),r=parseInt(n[0].match(/[0-9]+/gi)[0]),o=n[0].match(/[A-Z]+/gi)[0],i=N(o);for(endRow=parseInt(n[1].match(/[0-9]+/gi)[0]),endCol=n[1].match(/[A-Z]+/gi)[0],endColDec=N(endCol),totalRows=endRow-r+1,totalCols=N(endCol)-N(o)+1,curCol=0,curRow=1,curCell="",retStr="";curRow<=totalRows;curRow+=1){for(;curCol<totalCols;curCol+=1)curCell=C(i+curCol)+""+(r+curRow-1),retStr+=curCell+(curRow===totalRows&&curCol===totalCols-1?"":e);curCol=0}return retStr}function a(t,e,n,r,o){var i=n,a=void 0===typeof arguments[5]||null===arguments[5]?null:arguments[5],s=function(t){return t.replace(/\{\{token\}\}/gi,"{0}").replace(/\{\{autoindent\}\}/gi,"{1}").replace(/\{\{autolinebreak\}\}/gi,"{2}")},p="";if(p="text"===t.subtype||"text"===t.type?t.value.toString():"operand"===t.type&&"range"===t.subtype?t.value.toString():(0===t.value.length?" ":t.value.toString()).split(" ").join("").toString(),"function"==typeof o){var l=o(p,t,n,r);if(p=l.tokenString,!l.useTemplate)return p}switch(t.type){case"function":switch(t.value){case"ARRAY":p=u(s(e.tmplFunctionStartArray),p,i,r);break;case"ARRAYROW":p=u(s(e.tmplFunctionStartArrayRow),p,i,r);break;default:p="start"===t.subtype.toString()?u(s(e.tmplFunctionStart),p,i,r):u(s(e.tmplFunctionStop),p,i,r)}break;case"operand":switch(t.subtype.toString()){case"error":p=u(s(e.tmplOperandError),p,i,r);break;case"range":p=u(s(e.tmplOperandRange),p,i,r);break;case"logical":p=u(s(e.tmplOperandLogical),p,i,r);break;case"number":p=u(s(e.tmplOperandNumber),p,i,r);break;case"text":p=u(s(e.tmplOperandText),p,i,r);break;case"argument":p=u(s(e.tmplArgument),p,i,r)}break;case"operator-infix":p=u(s(e.tmplOperandOperatorInfix),p,i,r);break;case"logical":p=u(s(e.tmplLogical),p,i,r);break;case"argument":p="argument"!==a.type?u(s(e.tmplArgument),p,i,r):u(s("{{autoindent}}"+e.tmplArgument),p,i,r);break;case"subexpression":p="start"===t.subtype.toString()?u(s(e.tmplSubexpressionStart),p,i,r):u(s(e.tmplSubexpressionStop),p,i,r)}return p}var s=t.excelFormulaUtilities=t.excelFormulaUtilities||{},p=t.excelFormulaUtilities.core,u=t.excelFormulaUtilities.string.formatStr,l=t.excelFormulaUtilities.string.trim,c={},d=c.TOK_TYPE_NOOP="noop",g=c.TOK_TYPE_OPERAND="operand",f=c.TOK_TYPE_FUNCTION="function",m=c.TOK_TYPE_SUBEXPR="subexpression",S=c.TOK_TYPE_ARGUMENT="argument",b=c.TOK_TYPE_OP_PRE="operator-prefix",h=c.TOK_TYPE_OP_IN="operator-infix",y=c.TOK_TYPE_OP_POST="operator-postfix",T=c.TOK_TYPE_WSPACE="white-space",x=c.TOK_TYPE_UNKNOWN="unknown",O=c.TOK_SUBTYPE_START="start",k=c.TOK_SUBTYPE_STOP="stop",v=c.TOK_SUBTYPE_TEXT="text",w=c.TOK_SUBTYPE_NUMBER="number",E=c.TOK_SUBTYPE_LOGICAL="logical",R=c.TOK_SUBTYPE_ERROR="error",_=c.TOK_SUBTYPE_RANGE="range",A=c.TOK_SUBTYPE_MATH="math",U=c.TOK_SUBTYPE_CONCAT="concatenate",F=c.TOK_SUBTYPE_INTERSECT="intersect",P=c.TOK_SUBTYPE_UNION="union";t.excelFormulaUtilities.isEu="boolean"==typeof t.excelFormulaUtilities.isEu&&t.excelFormulaUtilities.isEu;var C=(s.parseFormula=function(t,e){var n=0,r=function(){for(var t="|",e=0;e<n;e+=1)t+=" |";return t},i=document.getElementById(t),a=i.value,s=o(a),p="";for(p+="<table cellspacing='0' style='border-top: 1px #cecece solid; margin-top: 5px; margin-bottom: 5px'>",p+="<tr>",p+="<td class='token' style='font-weight: bold; width: 50px'>index</td>",p+="<td class='token' style='font-weight: bold; width: 125px'>type</td>",p+="<td class='token' style='font-weight: bold; width: 125px'>subtype</td>",p+="<td class='token' style='font-weight: bold; width: 150px'>token</td>",p+="<td class='token' style='font-weight: bold; width: 300px'>token tree</td></tr>";s.moveNext();){var u=s.current();u.subtype===k&&(n-=n>0?1:0),p+="<tr>",p+="<td class='token'>"+(s.index+1)+"</td>",p+="<td class='token'>"+u.type+"</td>",p+="<td class='token'>"+(0===u.subtype.length?" ":u.subtype.toString())+"</td>",p+="<td class='token'>"+(0===u.value.length?" ":u.value).split(" ").join(" ")+"</td>",p+="<td class='token'>"+r()+(0===u.value.length?" ":u.value).split(" ").join(" ")+"</td>",p+="</tr>",u.subtype===O&&(n+=1)}p+="</table>",document.getElementById(e).innerHTML=p,i.select(),i.focus()},s.toBase26=function(t){t=Math.abs(t);var e,n="",r=!1;do e=t%26,r&&t<25&&e--,n=String.fromCharCode(e+"A".charCodeAt(0))+n,t=Math.floor((t-e)/26),r=!0;while(t>0);return n}),N=s.fromBase26=function(t){t=t.toUpperCase();var e=0,n=0,r=0;if(null!==t&&"undefined"!=typeof t&&t.length>0)for(;n<t.length;n++)e=t.charCodeAt(t.length-n-1)-"A".charCodeAt(0),r+=Math.pow(26,n)*(e+1);return r-1},Y=s.formatFormula=function(t,e){t=t.replace(/^\s*=\s+/,"=");var n=!0,r={tmplFunctionStart:"{{autoindent}}{{token}}(\n",tmplFunctionStop:"\n{{autoindent}}{{token}})",tmplOperandError:" {{token}}",tmplOperandRange:"{{autoindent}}{{token}}",tmplLogical:"{{token}}{{autolinebreak}}",tmplOperandLogical:"{{autoindent}}{{token}}",tmplOperandNumber:"{{autoindent}}{{token}}",tmplOperandText:'{{autoindent}}"{{token}}"',tmplArgument:"{{token}}\n",tmplOperandOperatorInfix:" {{token}}{{autolinebreak}}",tmplFunctionStartArray:"",tmplFunctionStartArrayRow:"{",tmplFunctionStopArrayRow:"}",tmplFunctionStopArray:"",tmplSubexpressionStart:"{{autoindent}}(\n",tmplSubexpressionStop:"\n)",tmplIndentTab:"\t",tmplIndentSpace:" ",autoLineBreak:"TOK_TYPE_FUNCTION | TOK_TYPE_ARGUMENT | TOK_SUBTYPE_LOGICAL | TOK_TYPE_OP_IN ",newLine:"\n",customTokenRender:null,prefix:"",postfix:""};e=e?p.extend(!0,r,e):r;for(var i=0,s=function(){for(var t="",n=0;n<i;n+=1)t+=e.tmplIndentTab;return t},u=o(t),d="",g=e.autoLineBreak.replace(/\s/gi,"").split("|"),f=!0,m=function(t){for(var e=0;e<g.length;e+=1)if(null!==t&&"undefined"!=typeof t&&(c[g[e]]===t.type.toString()||c[g[e]]===t.subtype.toString()))return!0;return!1},S=null;u.moveNext();){var b=u.current(),h=u.next();b.subtype.toString()===k&&(i-=i>0?1:0);var y=(new RegExp("^"+e.newLine,""),new RegExp(e.newLine+"$","")),T=m(h),x=f,v=x?s():e.tmplIndentSpace,w=T?e.newLine:"";d+=a(b,e,v,w,e.customTokenRender,S),b.subtype.toString()===O&&(i+=1),f=T||y.test(d),n=!1,S=b}return d=e.prefix+l(d)+e.postfix},K=(s.formatFormulaHTML=function(t){var e={tmplFunctionStart:'{{autoindent}}<span class="function">{{token}}</span><span class="function_start">(</span><br />',tmplFunctionStop:'<br />{{autoindent}}{{token}}<span class="function_stop">)</span>',tmplOperandText:'{{autoindent}}<span class="quote_mark">"</span><span class="text">{{token}}</span><span class="quote_mark">"</span>',tmplArgument:"{{token}}<br />",tmplSubexpressionStart:"{{autoindent}}(",tmplSubexpressionStop:" )",tmplIndentTab:'<span class="tabbed"> </span>',tmplIndentSpace:" ",newLine:"<br />",autoLineBreak:"TOK_TYPE_FUNCTION | TOK_TYPE_ARGUMENT | TOK_SUBTYPE_LOGICAL | TOK_TYPE_OP_IN ",trim:!0,prefix:"=",customTokenRender:null};return Y(t,e)},s.formula2CSharp=function(t){var e=[],n=function(t,n,r,o){var a="",s=t,p={"=":"==","<>":"!=",MIN:"Math.min",MAX:"Math.max",ABS:"Math.abs",SUM:"",IF:"","&":"+",AND:"",OR:""},u=e[e.length-1],l=!1;switch(n.type.toString()){case f:switch(n.subtype){case O:e.push({name:s,argumentNumber:0}),a="string"==typeof p[s.toUpperCase()]?p[s.toUpperCase()]:s,l=!0;break;case k:switch(l=!0,u.name.toLowerCase()){case"if":a=")",l=!1;break;default:a="string"==typeof p[s.toUpperCase()]?p[s.toUpperCase()]:s}e.pop()}break;case S:switch(u.name.toLowerCase()){case"if":switch(u.argumentNumber){case 0:a="?";break;case 1:a=":"}break;case"sum":a="+";break;case"and":a="&&";break;case"or":a="||";break;default:a="string"==typeof p[s.toUpperCase()]?p[s.toUpperCase()]:s,l=!0}u.argumentNumber+=1;break;case g:switch(n.subtype){case _:if(!u)break;switch(u.name.toLowerCase()){case"sum":RegExp(":","gi").test(s)?a=i(s,"+"):outStr=s;break;case"and":RegExp(":","gi").test(s)?a=i(s,"&&"):outStr=s;break;case"or":RegExp(":","gi").test(s)?a=i(s,"||"):outStr=s;break;default:a=RegExp(":","gi").test(s)?"["+i(s,",")+"]":s}}default:""===a&&(a="string"==typeof p[s.toUpperCase()]?p[s.toUpperCase()]:s),l=!0}return{tokenString:a,useTemplate:l}},r=Y(t,{tmplFunctionStart:"{{token}}(",tmplFunctionStop:"{{token}})",tmplOperandError:"{{token}}",tmplOperandRange:"{{token}}",tmplOperandLogical:"{{token}}",tmplOperandNumber:"{{token}}",tmplOperandText:'"{{token}}"',tmplArgument:"{{token}}",tmplOperandOperatorInfix:"{{token}}",tmplFunctionStartArray:"",tmplFunctionStartArrayRow:"{",tmplFunctionStopArrayRow:"}",tmplFunctionStopArray:"",tmplSubexpressionStart:"(",tmplSubexpressionStop:")",tmplIndentTab:"\t",tmplIndentSpace:" ",autoLineBreak:"TOK_SUBTYPE_STOP | TOK_SUBTYPE_START | TOK_TYPE_ARGUMENT",trim:!0,customTokenRender:n});return r});s.formula2JavaScript=function(t){return K(t).replace("==","===")};s.getTokens=o}(window||module.exports||{});
|