/*
    *
    * Wijmo Library 5.20182.500
    * http://wijmo.com/
    *
    * Copyright(c) GrapeCity, Inc.  All rights reserved.
    *
    * Licensed under the GrapeCity Commercial License.
    * sales@wijmo.com
    * wijmo.com/products/wijmo-5/license/
    *
    */
var __extends=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)t.hasOwnProperty(o)&&(e[o]=t[o])};return function(t,o){function n(){this.constructor=t}e(t,o),t.prototype=null===o?Object.create(o):(n.prototype=o.prototype,new n)}}();define(["require","exports","wijmo/wijmo","wijmo/wijmo.xlsx","wijmo/wijmo.grid","wijmo/wijmo.input","wijmo/wijmo.grid.xlsx","wijmo/wijmo.grid.filter","wijmo/wijmo.grid.sheet"],function(e,t,o,n,i,l,s,r,a){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var h=a||t;window.wijmo=window.wijmo||{},window.wijmo.grid=window.wijmo.grid||{},window.wijmo.grid.sheet=h;var d=function(){function e(e){this._expressionCache={},this._idChars="$:!",this._functionTable={},this._cacheSize=0,this._tableRefStart=!1,this.unknownFunction=new o.Event,this._owner=e,this._buildSymbolTable(),this._registerAggregateFunction(),this._registerMathFunction(),this._registerLogicalFunction(),this._registerTextFunction(),this._registerDateFunction(),this._registLookUpReferenceFunction(),this._registFinacialFunction()}return e.prototype.onUnknownFunction=function(e,t){var o,n;if(t&&t.length>0){o=[];for(var i=0;i<t.length;i++)o[i]=t[i].evaluate(this._rowIndex,this._columnIndex)}if(n=new j(e,o),this.unknownFunction.raise(this,n),null!=n.value)return new w(n.value);throw'The function "'+e+'" has not supported in FlexSheet yet.'},e.prototype.evaluate=function(e,t,n,i,l){var s;try{if(e&&e.length>1&&"="===e[0]){for(this._containsCellRef=!1,this._rowIndex=i,this._columnIndex=l,this._sheet=n||this._owner.selectedSheet,s=this._checkCache(e).evaluate(i,l,n);s instanceof w;)s=s.evaluate(i,l,n);return t&&o.isPrimitive(s)?o.Globalize.format(s,t):s}return e||""}catch(e){return"Error: "+e}},e.prototype.addCustomFunction=function(e,t,o,n){var i=this;e=e.toLowerCase(),this._functionTable[e]=new u(function(e){var o,n=[];if(e&&e.length>0)for(var l=0;l<e.length;l++)o=e[l],n[l]=o instanceof b?o.cells:o.evaluate(i._rowIndex,i._columnIndex);return t.apply(i,n)},n,o)},e.prototype.addFunction=function(e,t,o,n){var i=this;e=e.toLowerCase(),this._functionTable[e]=new u(function(e){var o,n=[];if(e&&e.length>0)for(var l=0;l<e.length;l++)o=e[l],n[l]=o instanceof b?o.getValuseWithTwoDimensions():[[o.evaluate(i._rowIndex,i._columnIndex)]];return t.apply(i,n)},n,o)},e.prototype._clearExpressionCache=function(){this._expressionCache=null,this._expressionCache={},this._cacheSize=0},e.prototype._parse=function(e){return this._expression=e,this._expressLength=e?e.length:0,this._pointer=0,this._expressLength>0&&"="===this._expression[0]&&this._pointer++,this._parseExpression()},e.prototype._buildSymbolTable=function(){this._tokenTable||(this._tokenTable={},this._addToken("+",g.ADD,_.ADDSUB),this._addToken("-",g.SUB,_.ADDSUB),this._addToken("(",g.OPEN,_.GROUP),this._addToken(")",g.CLOSE,_.GROUP),this._addToken("*",g.MUL,_.MULDIV),this._addToken(",",g.COMMA,_.GROUP),this._addToken(".",g.PERIOD,_.GROUP),this._addToken("/",g.DIV,_.MULDIV),this._addToken("\\",g.DIVINT,_.MULDIV),this._addToken("=",g.EQ,_.COMPARE),this._addToken(">",g.GT,_.COMPARE),this._addToken("<",g.LT,_.COMPARE),this._addToken("^",g.POWER,_.POWER),this._addToken("<>",g.NE,_.COMPARE),this._addToken(">=",g.GE,_.COMPARE),this._addToken("<=",g.LE,_.COMPARE),this._addToken("&",g.CONCAT,_.CONCAT),this._addToken("[",g.OPEN,_.SQUAREBRACKETS),this._addToken("]",g.CLOSE,_.SQUAREBRACKETS))},e.prototype._registerAggregateFunction=function(){var e=this;e._functionTable.sum=new u(function(t,n){return e._getAggregateResult(o.Aggregate.Sum,t,n)}),e._functionTable.average=new u(function(t,n){return e._getAggregateResult(o.Aggregate.Avg,t,n)}),e._functionTable.max=new u(function(t,n){return e._getAggregateResult(o.Aggregate.Max,t,n)}),e._functionTable.min=new u(function(t,n){return e._getAggregateResult(o.Aggregate.Min,t,n)}),e._functionTable.var=new u(function(t,n){return e._getAggregateResult(o.Aggregate.Var,t,n)}),e._functionTable.varp=new u(function(t,n){return e._getAggregateResult(o.Aggregate.VarPop,t,n)}),e._functionTable.stdev=new u(function(t,n){return e._getAggregateResult(o.Aggregate.Std,t,n)}),e._functionTable.stdevp=new u(function(t,n){return e._getAggregateResult(o.Aggregate.StdPop,t,n)}),e._functionTable.count=new u(function(t,o){return e._getFlexSheetAggregateResult(f.Count,t,o)}),e._functionTable.counta=new u(function(t,o){return e._getFlexSheetAggregateResult(f.CountA,t,o)}),e._functionTable.countblank=new u(function(t,o){return e._getFlexSheetAggregateResult(f.ConutBlank,t,o)}),e._functionTable.countif=new u(function(t,o){return e._getFlexSheetAggregateResult(f.CountIf,t,o)},2,2),e._functionTable.countifs=new u(function(t,o){return e._getFlexSheetAggregateResult(f.CountIfs,t,o)},254,2),e._functionTable.sumif=new u(function(t,o){return e._getFlexSheetAggregateResult(f.SumIf,t,o)},3,2),e._functionTable.sumifs=new u(function(t,o){return e._getFlexSheetAggregateResult(f.SumIfs,t,o)},255,2),e._functionTable.rank=new u(function(t,o){return e._getFlexSheetAggregateResult(f.Rank,t,o)},3,2),e._functionTable.product=new u(function(t,o){return e._getFlexSheetAggregateResult(f.Product,t,o)},255,1),e._functionTable.subtotal=new u(function(t,o){return e._handleSubtotal(t,o)},255,2),e._functionTable.dcount=new u(function(t,o){return e._handleDCount(t,o)},3,3),e._functionTable.sumproduct=new u(function(t,o){return e._getSumProduct(t,o)},255,1)},e.prototype._registerMathFunction=function(){var e=this,t=["abs","acos","asin","atan","cos","exp","ln","sin","sqrt","tan"],n=["ceiling","floor"],i=["round","rounddown","roundup"];e._functionTable.pi=new u(function(){return Math.PI},0,0),e._functionTable.rand=new u(function(){return Math.random()},0,0),e._functionTable.power=new u(function(t,o){return Math.pow(w.toNumber(t[0],e._rowIndex,e._columnIndex,o),w.toNumber(t[1],e._rowIndex,e._columnIndex,o))},2,2),e._functionTable.atan2=new u(function(t,o){var n=w.toNumber(t[0],e._rowIndex,e._columnIndex,o),i=w.toNumber(t[1],e._rowIndex,e._columnIndex,o);if(0===n&&0===i)throw"The x number and y number can't both be zero for the atan2 function";return Math.atan2(i,n)},2,2),e._functionTable.mod=new u(function(t,o){return w.toNumber(t[0],e._rowIndex,e._columnIndex,o)%w.toNumber(t[1],e._rowIndex,e._columnIndex,o)},2,2),e._functionTable.trunc=new u(function(t,o){var n,i=w.toNumber(t[0],e._rowIndex,e._columnIndex,o),l=2===t.length?w.toNumber(t[1],e._rowIndex,e._columnIndex,o):0;return 0===l?i>=0?Math.floor(i):Math.ceil(i):(n=Math.pow(10,l),i>=0?Math.floor(i*n)/n:Math.ceil(i*n)/n)},2,1),n.forEach(function(t){e._functionTable[t]=new u(function(o,n){var i,l,s,r=w.toNumber(o[0],e._rowIndex,e._columnIndex,n),a=2===o.length?w.toNumber(o[1],e._rowIndex,e._columnIndex,n):1;if(isNaN(r))throw"Invalid Number!";if(isNaN(a))throw"Invalid Significance!";if(r>0&&a<0)throw"The significance has to be positive, if the number is positive.";if(0===r||0===a)return 0;if(i=a-Math.floor(a),l=1,0!==i)for(;i<1;)l*=10,i*=10;return s="ceiling"===t?Math.ceil(r/a):Math.floor(r/a),a*l*s/l},2,1)}),i.forEach(function(t){e._functionTable[t]=new u(function(n,i){var l,s,r,a=w.toNumber(n[0],e._rowIndex,e._columnIndex,i),h=w.toNumber(n[1],e._rowIndex,e._columnIndex,i);if(0===h){switch(t){case"rounddown":l=a>=0?Math.floor(a):Math.ceil(a);break;case"roundup":l=a>=0?Math.ceil(a):Math.floor(a);break;case"round":l=Math.round(a);break;default:l=Math.floor(a)}s="n0"}else if(h>0&&o.isInt(h)){switch(r=Math.pow(10,h),t){case"rounddown":l=a>=0?Math.floor(a*r)/r:Math.ceil(a*r)/r;break;case"roundup":l=a>=0?Math.ceil(a*r)/r:Math.floor(a*r)/r;break;case"round":l=Math.round(a*r)/r}s="n"+h}if(null!=l)return{value:l,format:s};throw"Invalid precision!"},2,2)}),t.forEach(function(t){e._functionTable[t]=new u(function(o,n){return"ln"===t?Math.log(w.toNumber(o[0],e._rowIndex,e._columnIndex,n)):Math[t](w.toNumber(o[0],e._rowIndex,e._columnIndex,n))},1,1)})},e.prototype._registerLogicalFunction=function(){var e=this;e._functionTable.and=new u(function(t,o){var n,i=!0;for(n=0;n<t.length&&(i=i&&w.toBoolean(t[n],e._rowIndex,e._columnIndex,o));n++);return i},Number.MAX_VALUE,1),e._functionTable.or=new u(function(t,o){var n,i=!1;for(n=0;n<t.length&&!(i=i||w.toBoolean(t[n],e._rowIndex,e._columnIndex,o));n++);return i},Number.MAX_VALUE,1),e._functionTable.not=new u(function(t,o){return!w.toBoolean(t[0],e._rowIndex,e._columnIndex,o)},1,1),e._functionTable.if=new u(function(t,o){return 3===t.length?w.toBoolean(t[0],e._rowIndex,e._columnIndex,o)?t[1].evaluate(e._rowIndex,e._columnIndex,o):t[2].evaluate(e._rowIndex,e._columnIndex,o):!!w.toBoolean(t[0],e._rowIndex,e._columnIndex,o)&&t[1].evaluate(e._rowIndex,e._columnIndex,o)},3,2),e._functionTable.true=new u(function(){return!0},0,0),e._functionTable.false=new u(function(){return!1},0,0)},e.prototype._registerTextFunction=function(){var e=this;e._functionTable.char=new u(function(t,o){var n,i="";for(n=0;n<t.length;n++)i+=String.fromCharCode(w.toNumber(t[n],e._rowIndex,e._columnIndex,o));return i},Number.MAX_VALUE,1),e._functionTable.code=new u(function(t,o){var n=w.toString(t[0],e._rowIndex,e._columnIndex,o);return n&&n.length>0?n.charCodeAt(0):-1},1,1),e._functionTable.concatenate=new u(function(t,o){var n,i="";for(n=0;n<t.length;n++)i=i.concat(w.toString(t[n],e._rowIndex,e._columnIndex,o));return i},Number.MAX_VALUE,1),e._functionTable.left=new u(function(t,o){var n=w.toString(t[0],e._rowIndex,e._columnIndex,o),i=Math.floor(w.toNumber(t[1],e._rowIndex,e._columnIndex,o));return n&&n.length>0?n.slice(0,i):null},2,2),e._functionTable.right=new u(function(t,o){var n=w.toString(t[0],e._rowIndex,e._columnIndex,o),i=Math.floor(w.toNumber(t[1],e._rowIndex,e._columnIndex,o));return n&&n.length>0?n.slice(-i):null},2,2),e._functionTable.find=new u(function(t,n){var i,l=w.toString(t[0],e._rowIndex,e._columnIndex,n),s=w.toString(t[1],e._rowIndex,e._columnIndex,n),r=null!=t[2]?o.asInt(w.toNumber(t[2],e._rowIndex,e._columnIndex,n)):0;return null!=s&&null!=l&&(i=!isNaN(r)&&r>0&&r<s.length?s.indexOf(l,r):s.indexOf(l))>-1?i+1:-1},3,2),e._functionTable.search=new u(function(t,n){var i,l,s,r=w.toString(t[0],e._rowIndex,e._columnIndex,n),a=w.toString(t[1],e._rowIndex,e._columnIndex,n),h=null!=t[2]?o.asInt(w.toNumber(t[2],e._rowIndex,e._columnIndex,n)):0;return null!=a&&null!=r&&(l=new RegExp(r,"i"),!isNaN(h)&&h>0&&h<a.length?(a=a.substring(h),i=h+1):i=1,(s=a.search(l))>-1)?s+i:-1},3,2),e._functionTable.len=new u(function(t,o){var n=w.toString(t[0],e._rowIndex,e._columnIndex,o);return n?n.length:-1},1,1),e._functionTable.mid=new u(function(t,o){var n=w.toString(t[0],e._rowIndex,e._columnIndex,o),i=Math.floor(w.toNumber(t[1],e._rowIndex,e._columnIndex,o)),l=Math.floor(w.toNumber(t[2],e._rowIndex,e._columnIndex,o));return n&&n.length>0&&i>0?n.substr(i-1,l):null},3,3),e._functionTable.lower=new u(function(t,o){var n=w.toString(t[0],e._rowIndex,e._columnIndex,o);return n&&n.length>0?n.toLowerCase():null},1,1),e._functionTable.upper=new u(function(t,o){var n=w.toString(t[0],e._rowIndex,e._columnIndex,o);return n&&n.length>0?n.toUpperCase():null},1,1),e._functionTable.proper=new u(function(t,o){var n=w.toString(t[0],e._rowIndex,e._columnIndex,o);return n&&n.length>0?n[0].toUpperCase()+n.substring(1).toLowerCase():null},1,1),e._functionTable.trim=new u(function(t,o){var n=w.toString(t[0],e._rowIndex,e._columnIndex,o);return n&&n.length>0?n.trim():null},1,1),e._functionTable.replace=new u(function(t,o){var n=w.toString(t[0],e._rowIndex,e._columnIndex,o),i=Math.floor(w.toNumber(t[1],e._rowIndex,e._columnIndex,o)),l=Math.floor(w.toNumber(t[2],e._rowIndex,e._columnIndex,o)),s=w.toString(t[3],e._rowIndex,e._columnIndex,o);return n&&n.length>0&&i>0?n.substring(0,i-1)+s+n.slice(i-1+l):null},4,4),e._functionTable.substitute=new u(function(t,o){var n,i=w.toString(t[0],e._rowIndex,e._columnIndex,o),l=w.toString(t[1],e._rowIndex,e._columnIndex,o),s=w.toString(t[2],e._rowIndex,e._columnIndex,o),r=4===t.length?w.toNumber(t[3],e._rowIndex,e._columnIndex,o):null,a=0;if(null!=r&&r<1||isNaN(r))throw"Invalid instance number.";return i&&i.length>0&&l&&l.length>0?(n=new RegExp(l,"g"),i.replace(n,function(e){return a++,null!=r?(r=Math.floor(r),a===r?s:e):s})):null},4,3),e._functionTable.rept=new u(function(t,o){var n,i=w.toString(t[0],e._rowIndex,e._columnIndex,o),l=Math.floor(w.toNumber(t[1],e._rowIndex,e._columnIndex,o)),s="";if(i&&i.length>0&&l>0)for(n=0;n<l;n++)s=s.concat(i);return s},2,2),e._functionTable.text=new u(function(t,i){var l,s=t[0].evaluate(e._rowIndex,e._columnIndex,i),r=w.toString(t[1],e._rowIndex,e._columnIndex,i);if(!o.isPrimitive(s)&&s&&(s=s.value),o.isDate(s))r=r.replace(/\[\$\-.+\]/g,"").replace(/(\\)(.)/g,"$2").replace(/H+/g,function(e){return e.toLowerCase()}).replace(/m+/g,function(e){return e.toUpperCase()}).replace(/S+/g,function(e){return e.toLowerCase()}).replace(/AM\/PM/gi,"tt").replace(/A\/P/gi,"t").replace(/\.000/g,".fff").replace(/\.00/g,".ff").replace(/\.0/g,".f").replace(/\\[\-\s,]/g,function(e){return e.substring(1)}).replace(/Y+/g,function(e){return e.toLowerCase()}).replace(/D+/g,function(e){return e.toLowerCase()}).replace(/M+:?|:?M+/gi,function(e){return e.indexOf(":")>-1?e.toLowerCase():e}).replace(/g+e/gi,function(e){return e.substring(0,e.length-1)+"yy"});else{if(!o.isNumber(s))return s;if((l=r.match(/^(\d+)(\.\d+)?\E\+(\d+)(\.\d+)?$/))&&5===l.length)return e._parseToScientificValue(s,l[1],l[2],l[3],l[4]);/M{1,4}|d{1,4}|y{1,4}/.test(r)?s=new Date(1900,0,s-1):r&&r.indexOf("#")>-1&&(r=n.Workbook.fromXlsxFormat(r)[0])}if(o.isDate(s))switch(r){case"d":return s.getDate();case"M":return s.getMonth()+1;case"y":r="yy";break;case"yyy":r="yyyy"}return o.Globalize.format(s,r)},2,2),e._functionTable.value=new u(function(t,n){var i,l=w.toString(t[0],e._rowIndex,e._columnIndex,n);if((l=l.replace(/(\,\d{3})/g,function(e){return e.substring(1)})).length>0){if(l[0]===o.culture.Globalize.numberFormat.currency.symbol)return+(l=l.substring(1));if("%"===l[l.length-1])return+(l=l.substring(0,l.length-1))/100}return i=+l,isNaN(i)?w.toNumber(t[0],e._rowIndex,e._columnIndex,n):i},1,1)},e.prototype._registerDateFunction=function(){var e=this;e._functionTable.now=new u(function(){return{value:new Date,format:"M/d/yyyy h:mm"}},0,0),e._functionTable.today=new u(function(){var e=new Date;return{value:new Date(e.getFullYear(),e.getMonth(),e.getDate()),format:"M/d/yyyy"}},0,0),e._functionTable.year=new u(function(t,n){var i=w.toDate(t[0],e._rowIndex,e._columnIndex,n);return!o.isPrimitive(i)&&i?i.value:o.isDate(i)?i.getFullYear():1900},1,1),e._functionTable.month=new u(function(t,n){var i=w.toDate(t[0],e._rowIndex,e._columnIndex,n);return!o.isPrimitive(i)&&i?i.value:o.isDate(i)?i.getMonth()+1:1},1,1),e._functionTable.day=new u(function(t,n){var i=w.toDate(t[0],e._rowIndex,e._columnIndex,n);return!o.isPrimitive(i)&&i?i.value:o.isDate(i)?i.getDate():0},1,1),e._functionTable.hour=new u(function(t,n){var i=t[0].evaluate(e._rowIndex,e._columnIndex,n);if(o.isNumber(i)&&!isNaN(i))return Math.floor(24*(i-Math.floor(i)));if(o.isDate(i))return i.getHours();if(i=w.toDate(t[0],e._rowIndex,e._columnIndex,n),!o.isPrimitive(i)&&i&&(i=i.value),o.isDate(i))return i.getHours();throw"Invalid parameter."},1,1),e._functionTable.time=new u(function(t,n){var i=t[0].evaluate(e._rowIndex,e._columnIndex,n),l=t[1].evaluate(e._rowIndex,e._columnIndex,n),s=t[2].evaluate(e._rowIndex,e._columnIndex,n);if(o.isNumber(i)&&o.isNumber(l)&&o.isNumber(s))return i%=24,l%=60,s%=60,{value:new Date(0,0,0,i,l,s),format:"h:mm tt"};throw"Invalid parameters."},3,3),e._functionTable.date=new u(function(t,n){var i=t[0].evaluate(e._rowIndex,e._columnIndex,n),l=t[1].evaluate(e._rowIndex,e._columnIndex,n),s=t[2].evaluate(e._rowIndex,e._columnIndex,n);if(o.isNumber(i)&&o.isNumber(l)&&o.isNumber(s))return{value:new Date(i,l-1,s),format:"M/d/yyyy"};throw"Invalid parameters."},3,3),e._functionTable.datedif=new u(function(t,n){var i,l,s,r,a,h=w.toDate(t[0],e._rowIndex,e._columnIndex,n),d=w.toDate(t[1],e._rowIndex,e._columnIndex,n),c=t[2].evaluate(e._rowIndex,e._columnIndex,n);if(!o.isPrimitive(h)&&h&&(h=h.value),!o.isPrimitive(d)&&d&&(d=d.value),o.isDate(h)&&o.isDate(d)&&o.isString(c)){if(i=h.getTime(),l=d.getTime(),i>l)throw"Start date is later than end date.";switch(s=d.getDate()-h.getDate(),r=d.getMonth()-h.getMonth(),a=d.getFullYear()-h.getFullYear(),c.toUpperCase()){case"Y":return r>0?a:r<0?a-1:s>=0?a:a-1;case"M":return s>=0?12*a+r:12*a+r-1;case"D":return(l-i)/864e5;case"YM":return(r=s>=0?12*a+r:12*a+r-1)%12;case"YD":return r>0?(new Date(h.getFullYear(),d.getMonth(),d.getDate()).getTime()-h.getTime())/864e5:r<0?(new Date(h.getFullYear()+1,d.getMonth(),d.getDate()).getTime()-h.getTime())/864e5:s>=0?s:(new Date(h.getFullYear()+1,d.getMonth(),d.getDate()).getTime()-h.getTime())/864e5;case"MD":return s>=0?s:s=new Date(d.getFullYear(),d.getMonth(),0).getDate()-new Date(d.getFullYear(),d.getMonth()-1,1).getDate()+1+s;default:throw"Invalid unit."}}throw"Invalid parameters."},3,3)},e.prototype._registLookUpReferenceFunction=function(){var e=this;e._functionTable.column=new u(function(t,o,n,i){var l;if(null==t)return i+1;if(l=t[0],(l=e._ensureNonFunctionExpression(l))instanceof b)return l.cells.col+1;throw"Invalid Cell Reference."},1,0),e._functionTable.columns=new u(function(t,o){var n=t[0];if((n=e._ensureNonFunctionExpression(n))instanceof b)return n.cells.columnSpan;throw"Invalid Cell Reference."},1,1),e._functionTable.row=new u(function(t,o,n,i){var l;if(null==t)return n+1;if(l=t[0],(l=e._ensureNonFunctionExpression(l))instanceof b)return l.cells.row+1;throw"Invalid Cell Reference."},1,0),e._functionTable.rows=new u(function(t,o){var n=t[0];if((n=e._ensureNonFunctionExpression(n))instanceof b)return n.cells.rowSpan;throw"Invalid Cell Reference."},1,1),e._functionTable.choose=new u(function(t,o){var n=w.toNumber(t[0],e._rowIndex,e._columnIndex,o);if(isNaN(n))throw"Invalid index number.";if(n<1||n>=t.length)throw"The index number is out of the list range.";return t[n].evaluate(e._rowIndex,e._columnIndex,o)},255,2),e._functionTable.index=new u(function(t,o){var n,l=t[0],s=w.toNumber(t[1],e._rowIndex,e._columnIndex,o),r=null!=t[2]?w.toNumber(t[2],e._rowIndex,e._columnIndex,o):0;if(isNaN(s)||s<0)throw"Invalid Row Number.";if(isNaN(r)||r<0)throw"Invalid Column Number.";if((l=e._ensureNonFunctionExpression(l))instanceof b){if(n=l.cells,s>n.rowSpan||r>n.columnSpan)throw"Index is out of the cell range.";if(s>0&&r>0)return e._owner.getCellValue(n.topRow+s-1,n.leftCol+r-1,!0,o);if(0===s&&0===r)return l;if(0===s)return new b(new i.CellRange(n.topRow,n.leftCol+r-1,n.bottomRow,n.leftCol+r-1),l.sheetRef,e._owner);if(0===r)return new b(new i.CellRange(n.topRow+s-1,n.leftCol,n.topRow+s-1,n.rightCol),l.sheetRef,e._owner)}throw"Invalid Cell Reference."},4,2),e._functionTable.hlookup=new u(function(t,o){return e._handleHLookup(t,o)},4,3)},e.prototype._registFinacialFunction=function(){var e=this;e._functionTable.rate=new u(function(t,o){return{value:e._calculateRate(t,o),format:"p2"}},6,3)},e.prototype._addToken=function(e,t,o){var n=new c(e,t,o);this._tokenTable[e]=n},e.prototype._parseExpression=function(){return this._getToken(),this._parseCompareOrConcat()},e.prototype._parseCompareOrConcat=function(){for(var e,t,o=this._parseAddSub();this._token.tokenType===_.COMPARE||this._token.tokenType===_.CONCAT;)e=this._token,this._getToken(),t=this._parseAddSub(),o=new C(e,o,t);return o},e.prototype._parseAddSub=function(){for(var e,t,o=this._parseMulDiv();this._token.tokenType===_.ADDSUB;)e=this._token,this._getToken(),t=this._parseMulDiv(),o=new C(e,o,t);return o},e.prototype._parseMulDiv=function(){for(var e,t,o=this._parsePower();this._token.tokenType===_.MULDIV;)e=this._token,this._getToken(),t=this._parsePower(),o=new C(e,o,t);return o},e.prototype._parsePower=function(){for(var e,t,o=this._parseUnary();this._token.tokenType===_.POWER;)e=this._token,this._getToken(),t=this._parseUnary(),o=new C(e,o,t);return o},e.prototype._parseUnary=function(){var e,t;return this._token.tokenID===g.ADD||this._token.tokenID===g.SUB?(e=this._token,this._getToken(),t=this._parseAtom(),new m(e,t)):this._parseAtom()},e.prototype._parseAtom=function(){var e,t,o,n,i,l,s,r,a,h,d,c,u,f=null;switch(this._token.tokenType){case _.LITERAL:f=new w(this._token);break;case _.IDENTIFIER:if(e=this._token.value.toString().toLowerCase(),t=this._functionTable[e]){if(o=this._getParameters(),this._token.tokenType===_.GROUP&&this._token.tokenID===g.CLOSE){if(n=o?o.length:0,-1!==t.paramMin&&n<t.paramMin)throw"Too few parameters.";if(-1!==t.paramMax&&n>t.paramMax)throw"Too many parameters.";"rand"===e&&(this._containsCellRef=!0),f=new y(e,t,o);break}if("true"===e||"false"===e){f=new y(e,t,o,!1);break}}if(2===(h=e.split("!")).length?(c=h[0],d=h[1]):d=h[0],l=this._getDefinedName(d,c||this._sheet.name.toLowerCase())){if(l.sheetName&&l.sheetName!==this._sheet.name&&l.sheetName.toLowerCase()!==c)throw"The defined name item works in "+l.sheetName+".  It does not work in current sheet.";a=this._pointer,r=this._expressLength,s=this._expression,this._pointer=0,f=this._checkCache(l.value),this._pointer=a,this._expressLength=r,this._expression=s;break}if(c="",null!=(u=this._owner._getTable(e))){if(""===(c=u.sheet.name))throw"The Table("+e+") is not located in any sheet.";if(this._getToken(),this._token.tokenType!==_.SQUAREBRACKETS||this._token.tokenID!==g.OPEN)throw"Invalid Table Reference.";this._tableRefStart=!0,f=this._getTableReference(u,c);break}if(i=this._getCellRange(e)){this._containsCellRef=!0,f=new b(i.cellRef.cellRange,i.sheetRef,this._owner,e.indexOf(":")>-1,i.cellRef.absRow,i.cellRef.absCol,i.cellRef.absRow2,i.cellRef.absCol2);break}o=this._getParameters(),f=this.onUnknownFunction(e,o);break;case _.GROUP:if(this._token.tokenID!==g.OPEN)throw"Expression expected.";if(this._getToken(),f=this._parseCompareOrConcat(),this._token.tokenID!==g.CLOSE)throw"Unbalanced parenthesis.";break;case _.SQUAREBRACKETS:if(this._token.tokenID!==g.OPEN)throw"Table References expected.";null!=(u=this._sheet.findTable(this._rowIndex,this._columnIndex))&&(c=u.sheet.name,this._tableRefStart=!0,f=this._getTableReference(u,c,!1))}if(null===f)throw"";return this._getToken(),f},e.prototype._getToken=function(){for(var e,t,o,n,i,l="",s="",r=new RegExp("[　-〿぀-ゟ゠-ヿ＀-ﾟ一-龯㐀-䶿]");this._pointer<this._expressLength&&" "===this._expression[this._pointer];)this._pointer++;if(this._pointer>=this._expressLength)this._token=new c(null,g.END,_.GROUP);else{if(t=this._expression[this._pointer],n=t>="a"&&t<="z"||t>="A"&&t<="Z"||r.test(t),i=t>="0"&&t<="9"||"."==t,!n&&!i){var a=this._tokenTable[t];if(a)return this._token=a,this._pointer++,void(this._pointer<this._expressLength&&(">"===t||"<"===t)&&(a=this._tokenTable[this._expression.substring(this._pointer-1,this._pointer+1)])&&(this._token=a,this._pointer++))}if(i)this._parseDigit();else if('"'!==t){if("'"!==t||(s=this._parseSheetRef()))if("#"!==t){if(!n&&"_"!==t&&this._idChars.indexOf(t)<0&&!s)throw"Identifier expected.";for(e=1;e+this._pointer<this._expressLength;e++)if(t=this._expression[this._pointer+e],n=t>="a"&&t<="z"||t>="A"&&t<="Z"||r.test(t),i=t>="0"&&t<="9","'"!==t||":"!==o){if(o=t,!n&&!i&&"_"!==t&&this._idChars.indexOf(t)<0)break}else l=s+this._expression.substring(this._pointer,this._pointer+e),this._pointer+=e,s=this._parseSheetRef(),e=0;l+=s+this._expression.substring(this._pointer,this._pointer+e),this._pointer+=e,this._token=new c(l,g.ATOM,_.IDENTIFIER)}else this._parseDate()}else this._parseString()}},e.prototype._getTableToken=function(){for(var e,t,o,n="",i=!1;this._pointer<this._expressLength&&" "===this._expression[this._pointer];)this._pointer++;for("@"===(t=this._expression[this._pointer])&&(n=t,this._pointer++),"["===(t=this._expression[this._pointer])&&(i=!0),e=1;e+this._pointer<this._expressLength;e++){if(t=this._expression[this._pointer+e],i&&","===t)throw"Invalid table reference.";if("]"===t)break}o=n+this._expression.substring(this._pointer+(i?1:0),this._pointer+e),this._pointer+=e+(i?1:0),this._token=new c(o,g.ATOM,_.IDENTIFIER)},e.prototype._parseDigit=function(){var e,t,o=-1,n=!1,i=!1,l=0;for(e=0;e+this._pointer<this._expressLength;e++)if((t=this._expression[this._pointer+e])>="0"&&t<="9")l=10*l+(+t-0),o>-1&&(o*=10);else if("."===t&&o<0)o=1;else{if("E"!==t&&"e"!==t||n){if("%"===t){i=!0,e++;break}break}n=!0,"+"!==(t=this._expression[this._pointer+e+1])&&"-"!==t||e++}n?l=+this._expression.substring(this._pointer,this._pointer+e):(o>1&&(l/=o),i&&(l/=100)),this._token=new c(l,g.ATOM,_.LITERAL),this._pointer+=e},e.prototype._parseString=function(){var e,t,o;for(e=1;e+this._pointer<this._expressLength;e++)if('"'===(t=this._expression[this._pointer+e])){if('"'!==(e+this._pointer<this._expressLength-1?this._expression[this._pointer+e+1]:" "))break;e++}if('"'!==t)throw"Can't find final quote.";if(o=this._expression.substring(this._pointer+1,this._pointer+e),this._pointer+=e+1,"!"===this._expression[this._pointer])throw"Illegal cross sheet reference.";this._token=new c(o.replace('""','"'),g.ATOM,_.LITERAL)},e.prototype._parseDate=function(){var e,t,o;for(e=1;e+this._pointer<this._expressLength&&"#"!==(t=this._expression[this._pointer+e]);e++);if("#"!==t)throw'Can\'t find final date delimiter ("#").';o=this._expression.substring(this._pointer+1,this._pointer+e),this._pointer+=e+1,this._token=new c(Date.parse(o),g.ATOM,_.LITERAL)},e.prototype._parseSheetRef=function(){var e,t,o;for(e=1;e+this._pointer<this._expressLength;e++)if("'"===(t=this._expression[this._pointer+e])){if("'"!==(e+this._pointer<this._expressLength-1?this._expression[this._pointer+e+1]:" "))break;e++}if("'"!==t)throw"Can't find final quote.";return o=this._expression.substring(this._pointer+1,this._pointer+e),this._pointer+=e+1,"!"===this._expression[this._pointer]?o.replace(/\'\'/g,"'"):""},e.prototype._getCellRange=function(e){var t,o,n,i,l;if(e&&(t=e.split(":")).length>0&&t.length<3&&(o=this._parseCell(t[0]),(i=o.cellRef?o.cellRef.cellRange:null)&&2===t.length)){if(n=this._parseCell(t[1]),l=n.cellRef.cellRange,o.sheetRef&&!n.sheetRef&&(n.sheetRef=o.sheetRef),o.sheetRef!==n.sheetRef)throw"The cell reference must be in the same sheet!";l?(i.col2=l.col,i.row2=l.row):i=null}return null==i?null:{cellRef:{cellRange:i,absRow:o.cellRef.absRow,absCol:o.cellRef.absCol,absRow2:n?n.cellRef.absRow:null,absCol2:n?n.cellRef.absCol:null},sheetRef:o.sheetRef}},e.prototype._parseCellRange=function(e){var t,o,n=-1,l=-1,s=!1,r=!1;for(t=0;t<e.length;t++)if("$"!==(o=e[t])||s){if(!(o>="a"&&o<="z"||o>="A"&&o<="Z"))break;n<0&&(n=0),n=26*n+(o.toUpperCase().charCodeAt(0)-"A".charCodeAt(0)+1)}else s=!0;for(;t<e.length;t++)if("$"!==(o=e[t])||r){if(!(o>="0"&&o<="9"))break;l<0&&(l=0),l=10*l+(+o-0)}else r=!0;return t<e.length&&(l=n=-1),-1===l||-1===n?null:{cellRange:new i.CellRange(l-1,n-1),absRow:r,absCol:s}},e.prototype._parseCell=function(e){var t,o,n,i;if((o=e.lastIndexOf("!"))>0&&o<e.length-1)i=e.substring(0,o),n=e.substring(o+1);else{if(!(o<=0))return null;n=e}return t=this._parseCellRange(n),{cellRef:t,sheetRef:i}},e.prototype._getParameters=function(){var e,t,o=this._pointer,n=this._token;if(this._getToken(),this._token.tokenType!==_.SQUAREBRACKETS||this._token.tokenID!==g.OPEN){if(this._token.tokenID!==g.OPEN)return this._pointer=o,this._token=n,null;if(o=this._pointer,this._getToken(),this._token.tokenID===g.CLOSE)return null;for(this._pointer=o,e=new Array,t=this._parseExpression(),e.push(t);this._token.tokenID===g.COMMA;)t=this._parseExpression(),e.push(t);if(this._token.tokenID!==g.CLOSE)throw"Syntax error.";return e}},e.prototype._getTableReference=function(e,t,o){void 0===o&&(o=!0);var n,i,l=[],s=this._getTableParameter(),r=!1;if(null==s)throw"Invalid table reference.";for(l.push(s);this._tableRefStart&&(this._token.tokenID===g.COMMA||":"===this._token.value);){if(":"===this._token.value&&(r=!0),null==(s=this._getTableParameter()))throw"Invalid table reference.";r?(l[l.length-1]+=":"+s,r=!1):l.push(s)}if(this._token.tokenType!==_.SQUAREBRACKETS||this._token.tokenID!==g.CLOSE)throw"Unbalanced square brackets.";return this._tableRefStart=!1,n=this._getTableRange(e,l),this._containsCellRef=!0,i=new b(n,t.toLowerCase(),this._owner),i._tableParams=l,o&&(i._tableName=e.name),i},e.prototype._getTableParameter=function(){var e;for(this._pointer;this._pointer<this._expressLength&&" "===this._expression[this._pointer];)this._pointer++;return"]"===this._expression[this._pointer]?(this._tableRefStart=!1,null):(this._getTableToken(),e=this._token.value,this._getToken(),e)},e.prototype._getTableRange=function(e,t){for(var o,n,l,s,r,a,h=0;h<t.length;h++){if(n)throw"Invalid Table Refernce.";if(o=t[h].toLowerCase(),r=null,"#"===o[0]){switch(o){case"#all":r=e.getRange();break;case"#data":r=e.getRange(ne.Data);break;case"#headers":r=e.getRange(ne.Header);break;case"#totals":r=e.getRange(ne.Footer);break;case"#this row":if(s=e.getRange(),!(this._rowIndex>=s.topRow&&this._rowIndex<=s.bottomRow))throw"The row is out of the table ("+e.name+") range.";r=new i.CellRange(this._rowIndex,s.leftCol,this._rowIndex,s.rightCol);break;default:throw"Invalid Table Refernce."}if(null==r)throw"Invalid Table Refernce.";null==l?l=r:(l.row=l.topRow<r.topRow?l.topRow:r.topRow,l.row2=l.bottomRow>r.bottomRow?l.bottomRow:r.bottomRow)}else{n=!0,a=o.split(":");for(var d=0;d<a.length;d++){if(a.length>2)throw"Invalid Table Column Refernce.";if("@"===(o=a[d])[0]){if(null==(r=e.getRange(ne.Data,o.substring(1))))throw"Invalid Table Refernce.";if(!(this._rowIndex>=r.topRow&&this._rowIndex<=r.bottomRow))throw"The row is out of the table ("+e.name+") range.";r.row=this._rowIndex,r.row2=this._rowIndex}else if(null==(r=e.getRange(ne.Data,o)))throw"Invalid Table Refernce.";0===d&&(null==l?l=r:l.col=r.col),l.col2=r.col,r=null}}}return l},e.prototype._getAggregateResult=function(e,t,n){var i,l=this._getItemList(t,n);return i=o.getAggregate(e,l.items),l.isDate&&(i={value:i=new Date(i),format:l.format||"M/d/yyyy"}),i},e.prototype._getFlexSheetAggregateResult=function(e,t,o){var n,i,l,s;switch(e){case f.Count:return n=this._getItemList(t,o,!0,!1),this._countNumberCells(n.items);case f.CountA:return(n=this._getItemList(t,o,!1,!1)).items.length;case f.ConutBlank:return n=this._getItemList(t,o,!1,!0),this._countBlankCells(n.items);case f.Rank:if(l=w.toNumber(t[0],this._rowIndex,this._columnIndex,o),s=t[2]?w.toNumber(t[2],this._rowIndex,this._columnIndex,o):0,isNaN(l))throw"Invalid number.";if(isNaN(s))throw"Invalid order.";if(t[1]=this._ensureNonFunctionExpression(t[1]),t[1]instanceof b)return n=this._getItemList([t[1]],o),this._getRankOfCellRange(l,n.items,s);throw"Invalid Cell Reference.";case f.CountIf:if(t[0]=this._ensureNonFunctionExpression(t[0]),t[0]instanceof b)return n=this._getItemList([t[0]],o,!1),this._countCellsByCriterias([n.items],[t[1]],o);throw"Invalid Cell Reference.";case f.CountIfs:return this._handleCountIfs(t,o);case f.SumIf:if(t[0]=this._ensureNonFunctionExpression(t[0]),t[0]instanceof b)return n=this._getItemList([t[0]],o,!1),t[2]=this._ensureNonFunctionExpression(t[2]),null!=t[2]&&t[2]instanceof b&&(i=this._getItemList([t[2]],o)),this._sumCellsByCriterias([n.items],[t[1]],i?i.items:null,o);throw"Invalid Cell Reference.";case f.SumIfs:return this._handleSumIfs(t,o);case f.Product:return n=this._getItemList(t,o),this._getProductOfNumbers(n.items)}throw"Invalid aggregate type."},e.prototype._getItemList=function(e,t,n,i,l,s){void 0===n&&(n=!0),void 0===i&&(i=!1),void 0===l&&(l=!0);var r,a,h,d,c,u,_,g,f,p,m=new Array;for(a=0;a<e.length;a++)if(c=e[a],(c=this._ensureNonFunctionExpression(c))instanceof b){for(d=c.getValues(l,s,t),0===a&&((f=(g=c._getSheet()||t||this._sheet).getCellStyle(c.cells.topRow,c.cells.leftCol))&&(_=f.format),_||(p=g.grid.columns[c.cells.leftCol])&&(_=p.format)),h=0;h<d.length;h++)if(r=d[h],i||null!=r&&""!==r){if(o.isString(r)&&0===r.indexOf("Error: ")){m=[0];break}null==u&&(u=r instanceof Date),r=n&&!o.isBoolean(r)?+r:r,m.push(r)}}else{if(r=c instanceof w?c.evaluate(this._rowIndex,this._columnIndex,t):c,o.isPrimitive(r)||(r=r.value),!i&&(null==r||""===r))continue;if(o.isString(r)&&0===r.indexOf("Error: ")){m=[0];break}null==u&&(u=r instanceof Date),r=n?+r:r,m.push(r)}return 0===m.length&&(u=!1),{isDate:u,items:m,format:_}},e.prototype._countBlankCells=function(e){for(var t,n=0,i=0;n<e.length;n++)(null==(t=e[n])||o.isString(t)&&""===t||o.isNumber(t)&&isNaN(t))&&i++;return i},e.prototype._countNumberCells=function(e){for(var t,n=0,i=0;n<e.length;n++)null!=(t=e[n])&&o.isNumber(t)&&!isNaN(t)&&i++;return i},e.prototype._getRankOfCellRange=function(e,t,o){void 0===o&&(o=0);var n,i=0,l=0;for(o?t.sort(function(e,t){return isNaN(e)||isNaN(t)?-1:e-t}):t.sort(function(e,t){return isNaN(e)||isNaN(t)?1:t-e});i<t.length;i++)if(n=t[i],!isNaN(n)&&(l++,e===n))return l;throw e+" is not in the cell range."},e.prototype._handleCountIfs=function(e,t){var o,n,i,l,s=0,r=[],a=[];if(e.length%2!=0)throw"Invalid params.";for(;s<e.length/2;s++){if(n=e[2*s],!((n=this._ensureNonFunctionExpression(n))instanceof b))throw"Invalid Cell Reference.";if(0===s){if(!n.cells)throw"Invalid Cell Reference.";i=n.cells.rowSpan,l=n.cells.columnSpan}else{if(!n.cells)throw"Invalid Cell Reference.";if(n.cells.rowSpan!==i||n.cells.columnSpan!==l)throw"The row span and column span of each cell range has to be same with each other."}o=this._getItemList([n],t,!1),r[s]=o.items,a[s]=e[2*s+1]}return this._countCellsByCriterias(r,a,t)},e.prototype._countCellsByCriterias=function(e,t,n,i){for(var l,s,r,a,h,d=0,c=0,u=0,_=e[0].length,g=[];c<t.length;c++)"*"===(h=w.toString(t[c],this._rowIndex,this._columnIndex,n))?g.push(h):g.push(this._parseRightExpr(h));for(;d<_;d++){l=!1;e:for(c=0;c<e.length;c++)if(r=e[c],a=r[d],"string"==typeof(h=g[c])){if("*"!==h&&(null==a||""===a)){l=!1;break e}if(!(l="*"===h||this.evaluate(this._combineExpr(a,h),null,n,this._rowIndex,this._columnIndex)))break e}else if(!(l=l=h.reg.test(a.toString())===h.checkMathces))break e;l&&(i?null!=(s=i[d])&&o.isNumber(s)&&!isNaN(s)&&u++:u++)}return u},e.prototype._handleSumIfs=function(e,t){var o,n,i,l,s,r,a=1,h=[],d=[];if(e.length%2!=1)throw"Invalid params.";if(i=e[0],!((i=this._ensureNonFunctionExpression(i))instanceof b))throw"Invalid Sum Cell Reference.";if(!i.cells)throw"Invalid Sum Cell Reference.";for(s=i.cells.rowSpan,r=i.cells.columnSpan,n=this._getItemList([i],t);a<(e.length+1)/2;a++){if(l=e[2*a-1],!((l=this._ensureNonFunctionExpression(l))instanceof b))throw"Invalid Criteria Cell Reference.";if(!l.cells)throw"Invalid Criteria Cell Reference.";if(l.cells.rowSpan!==s||l.cells.columnSpan!==r)throw"The row span and column span of each cell range has to be same with each other.";o=this._getItemList([l],t,!1),h[a-1]=o.items,d[a-1]=e[2*a]}return this._sumCellsByCriterias(h,d,n.items,t)},e.prototype._sumCellsByCriterias=function(e,t,n,i){var l,s,r,a,h,d=0,c=0,u=0,_=e[0].length,g=[];for(null==n&&(n=e[0]);c<t.length;c++)"*"===(h=w.toString(t[c],this._rowIndex,this._columnIndex,i))?g.push(h):g.push(this._parseRightExpr(h));for(;d<_;d++){s=!1,l=n[d];e:for(c=0;c<e.length;c++)if(r=e[c],a=r[d],"string"==typeof(h=g[c])){if("*"!==h&&(null==a||""===a)){s=!1;break e}if(!(s="*"===h||this.evaluate(this._combineExpr(a,h),null,i,this._rowIndex,this._columnIndex)))break e}else if(!(s=h.reg.test(a.toString())===h.checkMathces))break e;s&&o.isNumber(l)&&!isNaN(l)&&(u+=l)}return u},e.prototype._getProductOfNumbers=function(e){var t,n=0,i=1,l=!1;if(e)for(;n<e.length;n++)t=e[n],o.isNumber(t)&&!isNaN(t)&&(i*=t,l=!0);return l?i:0},e.prototype._handleSubtotal=function(e,t){var n,i,l,s,r=!0;if((n=w.toNumber(e[0],this._rowIndex,this._columnIndex,t))>=1&&n<=11||n>=101&&n<=111){switch(n>=101&&n<=111&&(r=!1),n=o.asEnum(n,p),i=this._getItemList(e.slice(1),t,!0,!1,r),n){case p.Count:case p.CountWithoutHidden:return this._countNumberCells(i.items);case p.CountA:case p.CountAWithoutHidden:return i.items.length;case p.Product:case p.ProductWithoutHidden:return this._getProductOfNumbers(i.items);case p.Average:case p.AverageWithoutHidden:l=o.Aggregate.Avg;break;case p.Max:case p.MaxWithoutHidden:l=o.Aggregate.Max;break;case p.Min:case p.MinWithoutHidden:l=o.Aggregate.Min;break;case p.Std:case p.StdWithoutHidden:l=o.Aggregate.Std;break;case p.StdPop:case p.StdPopWithoutHidden:l=o.Aggregate.StdPop;break;case p.Sum:case p.SumWithoutHidden:l=o.Aggregate.Sum;break;case p.Var:case p.VarWithoutHidden:l=o.Aggregate.Var;break;case p.VarPop:case p.VarPopWithoutHidden:l=o.Aggregate.VarPop}return s=o.getAggregate(l,i.items),i.isDate&&(s=new Date(s)),s}throw"Invalid Subtotal function."},e.prototype._handleDCount=function(e,t){var o,n,i,l=e[0],s=e[2];if(l=this._ensureNonFunctionExpression(l),s=this._ensureNonFunctionExpression(s),l instanceof b&&s instanceof b&&(o=e[1].evaluate(this._rowIndex,this._columnIndex,t),n=this._getColumnIndexByField(l,o),(i=this._getItemList([l],t,!0,!1,!0,n)).items&&i.items.length>1))return this._DCountWithCriterias(i.items.slice(1),l,s);throw"Invalid Count Cell Reference."},e.prototype._DCountWithCriterias=function(e,t,o){var n,i,l,s,r,a,h,d,c,u,_,g=o.cells,f=0;if(n=this._getSheet(t.sheetRef),i=this._getSheet(o.sheetRef),g.rowSpan>1){for(l=g.topRow,s=g.bottomRow;s>g.topRow;s--){for(u=[],_=[],r=g.leftCol;r<=g.rightCol;r++)if(null!=(h=this._owner.getCellValue(s,r,!1,i))&&""!==h){if(_.push(new w(h)),d=this._owner.getCellValue(l,r,!1,i),a=this._getColumnIndexByField(t,d),!(null!=(c=this._getItemList([t],n,!1,!1,!0,a)).items&&c.items.length>1))throw"Invalid Count Cell Reference.";u.push(c.items.slice(1))}f+=this._countCellsByCriterias(u,_,n,e)}return f}throw"Invalid Criteria Cell Reference."},e.prototype._getColumnIndexByField=function(e,t){var n,i,l,s,r;if(n=e.cells,-1===(r=n.topRow))throw"Invalid Count Cell Reference.";if(o.isInt(t)&&!isNaN(t)){if(t>=1&&t<=n.columnSpan)return l=n.leftCol+t-1}else for(i=this._getSheet(e.sheetRef),l=n.leftCol;l<=n.rightCol;l++)if(s=this._owner.getCellValue(r,l,!1,i),t=o.isString(t)?t.toLowerCase():t,s=o.isString(s)?s.toLowerCase():s,t===s)return l;throw"Invalid field."},e.prototype._getSumProduct=function(e,t){var o,n,i,l=0,s=this._getItemListForSumProduct(e,t);if(s.length>0){n=s[0].length,i=s.length;for(var r=0;r<n;r++){o=1;for(var a=0;a<i;a++)o*=s[a][r];l+=o}}return l},e.prototype._getItemListForSumProduct=function(e,t){var o,n,i,l,s,r,a=[new Array];for(i=0;i<e.length;i++){if(r=e[i],o=new Array,(r=this._ensureNonFunctionExpression(r))instanceof b)for(s=r.getValues(!0,null,t),l=0;l<s.length;l++)n=s[l],o.push(+n);else n=r instanceof w?r.evaluate(this._rowIndex,this._columnIndex,t):r,o.push(+n);if(i>0&&o.length!==a[0].length)throw"The cell ranges of the sumProduct formula must have the same dimensions.";a[i]=o}return a},e.prototype._getSheet=function(e){var t,o=0;if(e)for(;o<this._owner.sheets.length&&(t=this._owner.sheets[o]).name!==e;o++);return t},e.prototype._parseRightExpr=function(e){var t,o,n=!1;if(e.indexOf("?")>-1||e.indexOf("*")>-1){if(null==(t=e.match(/([\?\*]*)(\w+)([\?\*]*)(\w+)([\?\*]*)/))||6!==t.length)throw"Invalid Criteria.";return o=new RegExp("^"+(t[1].length>0?this._parseRegCriteria(t[1]):"")+t[2]+(t[3].length>0?this._parseRegCriteria(t[3]):"")+t[4]+(t[5].length>0?this._parseRegCriteria(t[5]):"")+"$","i"),/^[<>=]/.test(e)?"="===e.trim()[0]&&(n=!0):n=!0,{reg:o,checkMathces:n}}if(isNaN(+e))if(/^\w/.test(e))e='="'+e+'"';else{if(!/^[<>=]{1,2}\s*-?.+$/.test(e))throw"Invalid Criteria.";e=e.replace(/([<>=]{1,2})\s*(-?.+)/,'$1"$2"')}else e="="+ +e;return e},e.prototype._combineExpr=function(e,t){return(o.isString(e)||o.isDate(e))&&(e='"'+e+'"'),(e="="+e)+t},e.prototype._parseRegCriteria=function(e){for(var t=0,o=0,n="";t<e.length;t++)"*"===e[t]?(o>0&&(n+="\\w{"+o+"}",o=0),n+="\\w*"):"?"===e[t]&&o++;return o>0&&(n+="\\w{"+o+"}"),n},e.prototype._calculateRate=function(e,t){var o,n,i,l,s,r,a,h,d,c,u=0,_=0;for(i=w.toNumber(e[0],this._rowIndex,this._columnIndex,t),l=w.toNumber(e[1],this._rowIndex,this._columnIndex,t),s=w.toNumber(e[2],this._rowIndex,this._columnIndex,t),r=null!=e[3]?w.toNumber(e[3],this._rowIndex,this._columnIndex,t):0,a=null!=e[4]?w.toNumber(e[4],this._rowIndex,this._columnIndex,t):0,n=null!=e[5]?w.toNumber(e[5],this._rowIndex,this._columnIndex,t):.1,Math.abs(n)<1e-7?s*(1+i*n)+l*(1+n*a)*i+r:s*(h=Math.exp(i*Math.log(1+n)))+l*(1/n+a)*(h-1)+r,d=s+l*i+r,c=s*h+l*(1/n+a)*(h-1)+r,o=n;Math.abs(d-c)>1e-7&&u<20;)n=(c*_-d*o)/(c-d),_=o,o=n,d=c,c=Math.abs(n)<1e-7?s*(1+i*n)+l*(1+n*a)*i+r:s*(h=Math.exp(i*Math.log(1+n)))+l*(1/n+a)*(h-1)+r,++u;if(Math.abs(d-c)>1e-7&&20===u)throw"It is not able to calculate the rate with current parameters.";return n},e.prototype._handleHLookup=function(e,t){var o,n,i=e[0].evaluate(this._rowIndex,this._columnIndex,t),l=e[1],s=w.toNumber(e[2],this._rowIndex,this._columnIndex,t),r=null==e[3]||w.toBoolean(e[3],this._rowIndex,this._columnIndex,t);if(null==i||""==i)throw"Invalid lookup value.";if(isNaN(s)||s<0)throw"Invalid row index.";if((l=this._ensureNonFunctionExpression(l))instanceof b){if(o=l.cells,s>o.rowSpan)throw"Row index is out of the cell range.";if(r?-1===(n=this._exactMatch(i,o,t,!1))&&(n=this._approximateMatch(i,o,t)):n=this._exactMatch(i,o,t),-1===n)throw"Lookup Value is not found.";return this._owner.getCellValue(o.topRow+s-1,n,!1,t)}throw"Invalid Cell Reference."},e.prototype._exactMatch=function(e,t,n,i){void 0===i&&(i=!0);var l,s,r,a,h=t.topRow;if(o.isString(e)&&(e=e.toLowerCase()),i&&o.isString(e)&&(e.indexOf("?")>-1||e.indexOf("*")>-1)){if(null==(r=e.match(/([\?\*]*)(\w+)([\?\*]*)(\w+)([\?\*]*)/))||6!==r.length)throw"Invalid lookup value.";a=new RegExp("^"+(r[1].length>0?this._parseRegCriteria(r[1]):"")+r[2]+(r[3].length>0?this._parseRegCriteria(r[3]):"")+r[4]+(r[5].length>0?this._parseRegCriteria(r[5]):"")+"$","i")}for(l=t.leftCol;l<=t.rightCol;l++)if(s=this._owner.getCellValue(h,l,!1,n),null!=a){if(a.test(s))return l}else if(o.isString(s)&&(s=s.toLowerCase()),e===s)return l;return-1},e.prototype._approximateMatch=function(e,t,n){var i,l,s=t.topRow,r=[],a=0;for(o.isString(e)&&(e=e.toLowerCase()),l=t.leftCol;l<=t.rightCol;l++)i=this._owner.getCellValue(s,l,!1,n),i=isNaN(+i)?i:+i,r.push({value:i,index:l});for(r.sort(function(e,t){return o.isString(e.value)&&(e.value=e.value.toLowerCase()),o.isString(t.value)&&(t.value=t.value.toLowerCase()),e.value>t.value?-1:e.value===t.value?t.index-e.index:1});a<r.length;a++)if(i=r[a],o.isString(i.value)&&(i.value=i.value.toLowerCase()),e>i.value)return i.index;throw"Lookup Value is not found."},e.prototype._parseToScientificValue=function(e,t,n,i,l){var s,r,a,h,d=0;if(Math.abs(e)>=1)for(r="+",s=Math.pow(10,t.length);e>s;)e/=s,d+=t.length;else for(r="-",s=Math.pow(10,t.length);e*s<s;)e*=s,d+=t.length;if(a=o.Globalize.format(e,"D"+t.length),n)for((a+=o.Globalize.format(e-Math.floor(e),t+n).substring(1)).indexOf(".")>-1?h=a.length-1-a.indexOf("."):(a+=".",h=0);h<n.length-1;)a+="0",h++;if(a+="E"+r+o.Globalize.format(d,"D"+i.length),l){a+=".";for(var c=1;c<l.length;c++)a+="0"}return a},e.prototype._checkCache=function(e,t,o,n){null!=t&&(this._sheet=this._owner.sheets[t]),null!=o&&(this._rowIndex=o),null!=n&&(this._columnIndex=n);var i=this._expressionCache[e]||this._expressionCache[this._rowIndex+"_"+this._columnIndex+":"+e];if(i)return i;if(i=this._parse(e),this._token.tokenID!==g.END||this._token.tokenType!==_.GROUP)throw"Invalid Expression: "+e;return this._cacheSize>1e4&&this._clearExpressionCache(),this._expressionCache[(this._containsCellRef?this._rowIndex+"_"+this._columnIndex+":":"")+e]=i,this._cacheSize++,i},e.prototype._ensureNonFunctionExpression=function(e,t){for(;e instanceof y;)e=e.evaluate(this._rowIndex,this._columnIndex,t);return e},e.prototype._getDefinedName=function(e,t){for(var o,n,i=0;i<this._owner.definedNames.length;i++)if((o=this._owner.definedNames[i]).name.toLowerCase()===e)if(o.sheetName){if(o.sheetName.toLowerCase()===t)return o}else n=o;return n},e}();t._CalcEngine=d;var c=function(){function e(e,t,o){this._value=e,this._tokenID=t,this._tokenType=o}return Object.defineProperty(e.prototype,"value",{get:function(){return this._value},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"tokenID",{get:function(){return this._tokenID},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"tokenType",{get:function(){return this._tokenType},enumerable:!0,configurable:!0}),e}();t._Token=c;var u=function(){function e(e,t,n){this._paramMax=Number.MAX_VALUE,this._paramMin=Number.MIN_VALUE,this._func=e,o.isNumber(t)&&!isNaN(t)&&(this._paramMax=t),o.isNumber(n)&&!isNaN(n)&&(this._paramMin=n)}return Object.defineProperty(e.prototype,"paramMax",{get:function(){return this._paramMax},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"paramMin",{get:function(){return this._paramMin},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"func",{get:function(){return this._func},enumerable:!0,configurable:!0}),e}();t._FunctionDefinition=u;var _;!function(e){e[e.COMPARE=0]="COMPARE",e[e.ADDSUB=1]="ADDSUB",e[e.MULDIV=2]="MULDIV",e[e.POWER=3]="POWER",e[e.CONCAT=4]="CONCAT",e[e.GROUP=5]="GROUP",e[e.LITERAL=6]="LITERAL",e[e.IDENTIFIER=7]="IDENTIFIER",e[e.SQUAREBRACKETS=8]="SQUAREBRACKETS"}(_=t._TokenType||(t._TokenType={}));var g;!function(e){e[e.GT=0]="GT",e[e.LT=1]="LT",e[e.GE=2]="GE",e[e.LE=3]="LE",e[e.EQ=4]="EQ",e[e.NE=5]="NE",e[e.ADD=6]="ADD",e[e.SUB=7]="SUB",e[e.MUL=8]="MUL",e[e.DIV=9]="DIV",e[e.DIVINT=10]="DIVINT",e[e.MOD=11]="MOD",e[e.POWER=12]="POWER",e[e.CONCAT=13]="CONCAT",e[e.OPEN=14]="OPEN",e[e.CLOSE=15]="CLOSE",e[e.END=16]="END",e[e.COMMA=17]="COMMA",e[e.PERIOD=18]="PERIOD",e[e.ATOM=19]="ATOM"}(g=t._TokenID||(t._TokenID={}));var f;!function(e){e[e.Count=0]="Count",e[e.CountA=1]="CountA",e[e.ConutBlank=2]="ConutBlank",e[e.CountIf=3]="CountIf",e[e.CountIfs=4]="CountIfs",e[e.Rank=5]="Rank",e[e.SumIf=6]="SumIf",e[e.SumIfs=7]="SumIfs",e[e.Product=8]="Product"}(f||(f={}));var p;!function(e){e[e.Average=1]="Average",e[e.Count=2]="Count",e[e.CountA=3]="CountA",e[e.Max=4]="Max",e[e.Min=5]="Min",e[e.Product=6]="Product",e[e.Std=7]="Std",e[e.StdPop=8]="StdPop",e[e.Sum=9]="Sum",e[e.Var=10]="Var",e[e.VarPop=11]="VarPop",e[e.AverageWithoutHidden=101]="AverageWithoutHidden",e[e.CountWithoutHidden=102]="CountWithoutHidden",e[e.CountAWithoutHidden=103]="CountAWithoutHidden",e[e.MaxWithoutHidden=104]="MaxWithoutHidden",e[e.MinWithoutHidden=105]="MinWithoutHidden",e[e.ProductWithoutHidden=106]="ProductWithoutHidden",e[e.StdWithoutHidden=107]="StdWithoutHidden",e[e.StdPopWithoutHidden=108]="StdPopWithoutHidden",e[e.SumWithoutHidden=109]="SumWithoutHidden",e[e.VarWithoutHidden=110]="VarWithoutHidden",e[e.VarPopWithoutHidden=111]="VarPopWithoutHidden"}(p||(p={}));var w=function(){function e(e){this._token=e?e instanceof c?e:new c(e,g.ATOM,_.LITERAL):new c(null,g.ATOM,_.IDENTIFIER)}return Object.defineProperty(e.prototype,"token",{get:function(){return this._token},enumerable:!0,configurable:!0}),e.prototype.evaluate=function(e,t,o){if(this._token.tokenType!==_.LITERAL)throw"Bad expression.";return this._token.value},e.toString=function(e,t,n,i){var l=e.evaluate(t,n,i);return o.isPrimitive(l)||(l=l.value),null!=l?l.toString():""},e.toNumber=function(e,t,n,i){var l=e.evaluate(t,n,i),s=["January","February","March","April","May","June","July","August","September","October","November","December","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];if(o.isPrimitive(l)||(l=l.value),o.isNumber(l))return l;if(o.isBoolean(l))return l?1:0;if(o.isDate(l))return this._toOADate(l);if(o.isString(l)){if(l){if(isNaN(+l)){for(var r in s)if(l.indexOf(s[r])>-1)return this._toOADate(new Date(l));return+l}return+l}return 0}return o.changeType(l,o.DataType.Number,"")},e.toBoolean=function(e,t,n,i){var l=e.evaluate(t,n,i);return o.isPrimitive(l)||(l=l.value),o.isBoolean(l)?l:o.isNumber(l)?0!==l:o.changeType(l,o.DataType.Boolean,"")},e.toDate=function(e,t,n,i){var l=e.evaluate(t,n,i);return o.isPrimitive(l)||(l=l.value),o.isDate(l)?l:o.isNumber(l)?this._fromOADate(l):o.changeType(l,o.DataType.Date,"")},e._toOADate=function(e){var t=Date.UTC(1899,11,30);return(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())-t)/864e5},e._fromOADate=function(e){var t=Date.UTC(1899,11,30),o=new Date,n=e>=60?0:864e5;return new Date(864e5*e+t+6e4*o.getTimezoneOffset()+n)},e.prototype._updateCellRangeExp=function(e,t,o,n,i){return!1},e.prototype._moveCellRangeExp=function(e,t,o,n,i){return void 0===n&&(n=!1),void 0===i&&(i=!1),!1},e.prototype._updateCellRangeExpForReorderingRows=function(e){return!1},e.prototype._getStringExpression=function(){return null==this._token.value?"":o.isString(this._token.value)?'"'+this._token.value+'"':this._token.value.toString()},e}();t._Expression=w;var m=function(e){function t(t,o){var n=e.call(this,t)||this;return n._expr=o,n}return __extends(t,e),t.prototype.evaluate=function(e,t,o){if(this.token.tokenID===g.SUB)return null==this._evaluatedValue&&(this._evaluatedValue=-w.toNumber(this._expr,e,t,o)),this._evaluatedValue;if(this.token.tokenID===g.ADD)return null==this._evaluatedValue&&(this._evaluatedValue=+w.toNumber(this._expr,e,t,o)),this._evaluatedValue;throw"Bad expression."},t.prototype._updateCellRangeExp=function(e,t,o,n,i){return this._expr._updateCellRangeExp(e,t,o,n,i)},t.prototype._moveCellRangeExp=function(e,t,o,n,i){return void 0===n&&(n=!1),void 0===i&&(i=!1),this._expr._moveCellRangeExp(e,t,o,n,i)},t.prototype._updateCellRangeExpForReorderingRows=function(e){return this._expr._updateCellRangeExpForReorderingRows(e)},t.prototype._getStringExpression=function(){return this.token.tokenID===g.SUB?"-"+this._expr._getStringExpression():this.token.tokenID===g.ADD?"+"+this._expr._getStringExpression():""},t}(w);t._UnaryExpression=m;var C=function(e){function t(t,o,n){var i=e.call(this,t)||this;return i._leftExpr=o,i._rightExpr=n,i}return __extends(t,e),t.prototype.evaluate=function(e,t,o){var n,i,l,s,r,a,h,d=!1;if(null!=this._evaluatedValue)return this._evaluatedValue;if(n=w.toString(this._leftExpr,e,t,o),i=w.toString(this._rightExpr,e,t,o),this.token.tokenType===_.CONCAT)return this._evaluatedValue=n+i,this._evaluatedValue;if(l=this._leftExpr.evaluate(e,t,o),s=this._rightExpr.evaluate(e,t,o),d=this._isDateValue(l)||this._isDateValue(s),r=w.toNumber(this._leftExpr,e,t,o),a=w.toNumber(this._rightExpr,e,t,o),h=r-a,this.token.tokenType===_.COMPARE)switch(this.token.tokenID){case g.GT:return h>0;case g.LT:return h<0;case g.GE:return h>=0;case g.LE:return h<=0;case g.EQ:return isNaN(h)?(this._evaluatedValue=n.toLowerCase()===i.toLowerCase(),this._evaluatedValue):(this._evaluatedValue=0===h,this._evaluatedValue);case g.NE:return isNaN(h)?(this._evaluatedValue=n.toLowerCase()!==i.toLowerCase(),this._evaluatedValue):(this._evaluatedValue=0!==h,this._evaluatedValue)}switch(this.token.tokenID){case g.ADD:this._evaluatedValue=r+a;break;case g.SUB:this._evaluatedValue=r-a;break;case g.MUL:this._evaluatedValue=r*a;break;case g.DIV:this._evaluatedValue=r/a;break;case g.DIVINT:this._evaluatedValue=Math.floor(r/a);break;case g.MOD:this._evaluatedValue=Math.floor(r%a);break;case g.POWER:0===a&&(this._evaluatedValue=1),.5===a&&(this._evaluatedValue=Math.sqrt(r)),1===a&&(this._evaluatedValue=r),2===a&&(this._evaluatedValue=r*r),3===a&&(this._evaluatedValue=r*r*r),4===a&&(this._evaluatedValue=r*r*r*r),this._evaluatedValue=Math.pow(r,a);break;default:this._evaluatedValue=NaN}if(!isNaN(this._evaluatedValue))return d&&(this._evaluatedValue={value:w._fromOADate(this._evaluatedValue),format:l.format||s.format}),this._evaluatedValue;throw"Bad expression."},t.prototype._updateCellRangeExp=function(e,t,o,n,i){var l,s=!1;return l=this._leftExpr._updateCellRangeExp(e,t,o,n,i),s=s||l,l=this._rightExpr._updateCellRangeExp(e,t,o,n,i),s||l},t.prototype._moveCellRangeExp=function(e,t,o,n,i){void 0===n&&(n=!1),void 0===i&&(i=!1);var l,s=!1;return l=this._leftExpr._moveCellRangeExp(e,t,o,n,i),s=s||l,l=this._rightExpr._moveCellRangeExp(e,t,o,n,i),s||l},t.prototype._updateCellRangeExpForReorderingRows=function(e){var t,o=!1;return t=this._leftExpr._updateCellRangeExpForReorderingRows(e),o=o||t,t=this._rightExpr._updateCellRangeExpForReorderingRows(e),o||t},t.prototype._getStringExpression=function(){var e;switch(this.token.tokenID){case g.GT:e=">";break;case g.LT:e="<";break;case g.GE:e=">=";break;case g.LE:e="<=";break;case g.EQ:e="=";break;case g.NE:e="<>";break;case g.ADD:e="+";break;case g.SUB:e="-";break;case g.MUL:e="*";break;case g.DIV:e="/";break;case g.DIVINT:e="\\";break;case g.POWER:e="^";break;default:return""}return this._leftExpr._getStringExpression()+e+this._rightExpr._getStringExpression()},t.prototype._isDateValue=function(e){return o.isPrimitive(e)?o.isDate(e):o.isDate(e.value)},t}(w);t._BinaryExpression=C;var b=function(e){function t(t,o,n,l,s,r,a,h){void 0===l&&(l=!0),void 0===s&&(s=!1),void 0===r&&(r=!1),void 0===a&&(a=!1),void 0===h&&(h=!1);var d=e.call(this)||this;return d._cells=new i.CellRange(t.topRow,t.leftCol,t.bottomRow,t.rightCol),d._sheetRef=o,d._flex=n,d._evalutingRange={},d._isCellRange=l,d._absRow=s,d._absCol=r,d._absRow2=a,d._absCol2=h,d}return __extends(t,e),t.prototype.evaluate=function(e,t,o){return null==this._evaluatedValue&&(this._evaluatedValue=this._getCellValue(this._cells,o,e,t)),this._evaluatedValue},t.prototype.getValues=function(e,t,n){void 0===e&&(e=!0);var l,s,t,r,a,h=[],d=0;if(r=null==t||isNaN(+t)?this._cells.leftCol:t,a=null==t||isNaN(+t)?this._cells.rightCol:t,!(n=this._getSheet()||n||this._flex.selectedSheet))return null;for(s=this._cells.topRow;s<=this._cells.bottomRow;s++){if(s>=n.grid.rows.length)throw"The cell reference is out of the cell range of the flexsheet.";if(e||!1!==n.grid.rows[s].isVisible)for(t=r;t<=a;t++){if(t>=n.grid.columns.length)throw"The cell reference is out of the cell range of the flexsheet.";(e||!1!==n.grid.columns[t].isVisible)&&(l=this._getCellValue(new i.CellRange(s,t),n),o.isPrimitive(l)||(l=l.value),h[d]=l,d++)}}return h},t.prototype.getValuseWithTwoDimensions=function(e,t){void 0===e&&(e=!0);var n,l,s,r,a=[],h=0,d=0;if(!(t=this._getSheet()||t||this._flex.selectedSheet))return null;for(s=this._cells.topRow;s<=this._cells.bottomRow;s++){if(s>=t.grid.rows.length)throw"The cell reference is out of the cell range of the flexsheet.";if(e||!1!==t.grid.rows[s].isVisible){for(l=[],d=0,r=this._cells.leftCol;r<=this._cells.rightCol;r++){if(r>=t.grid.columns.length)throw"The cell reference is out of the cell range of the flexsheet.";e||!1!==t.grid.columns[r].isVisible?(n=this._getCellValue(new i.CellRange(s,r),t),o.isPrimitive(n)||(n=n.value),l[d]=n,d++):d++}a[h]=l,h++}else h++}return a},Object.defineProperty(t.prototype,"cells",{get:function(){return this._cells},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"sheetRef",{get:function(){return this._sheetRef},enumerable:!0,configurable:!0}),t.prototype._getCellValue=function(e,t,o,n){var t,i,l,s;if(!(t=this._getSheet()||t||this._flex.selectedSheet))return null;if(e.isSingleCell?(l=e.row,s=e.col):(null!=o&&o>=e.topRow&&o<=e.bottomRow&&e.col===e.col2&&(l=o,s=e.col),null!=n&&n>=e.leftCol&&n<=e.rightCol&&e.row===e.row2&&(l=e.row,s=n)),null==l||null==s)throw"Invalid Cell Reference.";if(i=t.name+":"+l+","+s+"-"+l+","+s,this._evalutingRange[i])throw"Circular Reference";try{if(this._flex)return this._evalutingRange[i]=!0,l<t.rowCount&&s<t.columnCount?this._flex.getCellValue(l,s,!1,t):0}finally{delete this._evalutingRange[i]}},t.prototype._getSheet=function(){var e,t=0;if(!this._sheetRef)return null;for(;t<this._flex.sheets.length;t++)if((e=this._flex.sheets[t]).name.toLowerCase()===this._sheetRef)return e;throw"Invalid sheet reference"},t.prototype._updateCellRangeExp=function(e,t,o,n,i){var l=this._cells,s=!1;if(this._tableParams&&this._tableParams.length>0)return!1;if(e===this._flex.selectedSheetIndex){if(this._sheetRef&&this._sheetRef.toLowerCase()!==this._flex.selectedSheet.name.toLowerCase())return!1}else if(!this._sheetRef||this._sheetRef.toLowerCase()!==this._flex.selectedSheet.name.toLowerCase())return!1;return i?n?l.topRow>=t?(l.row+=o,l.row2+=o,s=!0):l.topRow<t&&l.bottomRow>=t&&(l.row2+=o,s=!0):l.topRow>t?(l.row-=o,l.row2-=o,s=!0):l.isSingleCell?l.row>=t-o+1&&(l.row=t-o+1,l.row2=t-o+1,s=!0):l.topRow>=t-o+1?(l.row=t-o+1,l.row2-=o,s=!0):l.topRow<t-o+1&&l.bottomRow>=t-o+1&&(l.bottomRow>t?l.row2-=o:l.row2=t-o,s=!0):n?l.leftCol>=t?(l.col+=o,l.col2+=o,s=!0):l.leftCol<t&&l.rightCol>=t&&(l.col2+=o,s=!0):l.leftCol>t?(l.col-=o,l.col2-=o,s=!0):l.isSingleCell?l.col>=t-o+1&&(l.col=t-o+1,l.col2=t-o+1,s=!0):l.leftCol>=t-o+1?(l.col=t-o+1,l.col2-=o,s=!0):l.leftCol<t-o+1&&l.rightCol>=t-o+1&&(l.rightCol>t?l.col2-=o:l.col2=t-o,s=!0),s},t.prototype._moveCellRangeExp=function(e,t,o,n,i){void 0===n&&(n=!1),void 0===i&&(i=!1);var l,s,r=this._cells,a=!1;return!(this._tableParams&&this._tableParams.length>0)&&(l=o.topRow-t.topRow,s=o.leftCol-t.leftCol,i?(0!==l&&(r.row+=i&&this._absRow?0:l,r.row2+=this._isCellRange?i&&this._absRow2?0:l:i&&this._absRow?0:l,a=!0),0!==s&&(r.col+=i&&this._absCol?0:s,r.col2+=this._isCellRange?i&&this._absCol2?0:s:i&&this._absCol?0:s,a=!0),a):(t.contains(r)?(0!==l&&(r.row+=l,r.row2+=l,a=!0),0!==s&&(r.col+=s,r.col2+=s,a=!0)):t.intersects(r)?(t.intersectsRow(r)&&0!==l&&(t.topRow<=r.topRow?l<0?(r.row+=l,a=!0):l>0&&n&&(t.topRow<r.topRow&&(r.row-=r.topRow-t.topRow),r.row2-=t.rowSpan,a=!0):t.bottomRow>=r.bottomRow?l>0?(r.row2+=l,a=!0):l<0&&n&&(t.bottomRow>r.bottomRow&&(r.row2+=t.bottomRow-r.bottomRow),r.row+=t.rowSpan,a=!0):n&&(l<0?r.row+=t.rowSpan:r.row2-=t.rowSpan,a=!0)),t.intersectsColumn(r)&&0!==s&&(t.leftCol<=r.leftCol?s<0?(r.col+=s,a=!0):s>0&&n&&(t.leftCol<r.leftCol&&(r.col-=r.leftCol-t.leftCol),r.col2-=t.columnSpan,a=!0):t.rightCol>=r.rightCol?s>0?(r.col2+=s,a=!0):s<0&&n&&(t.rightCol>r.rightCol&&(r.col2+=t.rightCol-r.rightCol),r.col+=t.columnSpan,a=!0):n&&(s<0?r.col+=t.columnSpan:r.col2-=t.columnSpan,a=!0))):n&&(r.topRow>t.bottomRow&&l>0&&(r.row-=t.rowSpan,r.row2-=t.rowSpan,a=!0),r.bottomRow<t.topRow&&l<0&&(r.row+=t.rowSpan,r.row2+=t.rowSpan,a=!0),r.leftCol>t.rightCol&&s>0&&(r.col-=t.columnSpan,r.col2-=t.columnSpan,a=!0),r.rightCol<t.leftCol&&s<0&&(r.col+=t.columnSpan,r.col2+=t.columnSpan,a=!0)),a))},t.prototype._updateCellRangeExpForReorderingRows=function(e){var t,o=this._cells;return(t=this._cells.row+e)<0?t=0:t>=this._flex.rows.length&&(t=this._flex.rows.length-1),o.row=t,this._isCellRange&&((t=this._cells.row2+e)<0?t=0:t>=this._flex.rows.length&&(t=this._flex.rows.length-1)),o.row2=t,!0},t.prototype._getStringExpression=function(){return this._tableParams&&this._tableParams.length>0?this._getTableParamsStringExpression():(this._sheetRef?this._sheetRef+"!":"")+n.Workbook.xlsxAddress(this._cells.row,this._cells.col,this._absRow,this._absCol)+(this._isCellRange?":"+n.Workbook.xlsxAddress(this._cells.row2,this._cells.col2,this._absRow2,this._absCol2):"")},t.prototype._getTableParamsStringExpression=function(){for(var e,t=0,o="",n=this._tableParams.length,i=!1;t<n;t++)"#"===(e=this._tableParams[t])[0]?(o+="["+e+"]",t<n-1&&(o+=", ")):i?o+=": ["+e+"]":(o+="["+e+"]",i=!0);return n>1&&(o="["+o+"]"),this._tableName&&(o=this._tableName+o),o},t}(w);t._CellRangeExpression=b;var y=function(e){function t(t,o,n,i){void 0===i&&(i=!0);var l=e.call(this)||this;return l._funcId=t,l._funcDefinition=o,l._params=n,l._needCacheEvaluatedVal=i,l}return __extends(t,e),t.prototype.evaluate=function(e,t,o){return this._needCacheEvaluatedVal?(null==this._evaluatedValue&&(this._evaluatedValue=this._funcDefinition.func(this._params,o,e,t)),this._evaluatedValue):this._funcDefinition.func(this._params,o,e,t)},t.prototype._updateCellRangeExp=function(e,t,o,n,i){var l,s,r=!1;if(this._params&&this._params.length>0)for(l=0;l<this._params.length;l++)s=this._params[l]._updateCellRangeExp(e,t,o,n,i),r||(r=r||s);return r},t.prototype._moveCellRangeExp=function(e,t,o,n,i){void 0===n&&(n=!1),void 0===i&&(i=!1);var l,s,r=!1;if(this._params&&this._params.length>0)for(l=0;l<this._params.length;l++)s=this._params[l]._moveCellRangeExp(e,t,o,n,i),r||(r=r||s);return r},t.prototype._updateCellRangeExpForReorderingRows=function(e){var t,o,n=!1;if(this._params&&this._params.length>0)for(t=0;t<this._params.length;t++)o=this._params[t]._updateCellRangeExpForReorderingRows(e),n||(n=n||o);return n},t.prototype._getStringExpression=function(){return this._funcId+this._parseParamsExpToString()},t.prototype._parseParamsExpToString=function(){var e,t,o;if(this._params&&this._params.length>0){for(o="",e=0;e<this._params.length;e++)t=this._params[e],0===e&&(o+="("),o+=t._getStringExpression(),e<this._params.length-1?o+=", ":o+=")";return o}return"()"},t}(w);t._FunctionExpression=y;var S=function(){function e(e){this._owner=e,this._sheetIndex=e.selectedSheetIndex}return Object.defineProperty(e.prototype,"sheetIndex",{get:function(){return this._sheetIndex},enumerable:!0,configurable:!0}),e.prototype.undo=function(){throw"This abstract method must be overridden."},e.prototype.redo=function(){throw"This abstract method must be overridden."},e.prototype.saveNewState=function(){throw"This abstract method must be overridden."},e}();t._UndoAction=S;var R=function(e){function t(t,o){var n=e.call(this,t)||this;return n._isPaste=!1,n._selections=o?[o]:t.selectedSheet.selectionRanges.length>0?t.selectedSheet.selectionRanges.slice():[t.selection.clone()],n._mergeAction=new E(t),n._cellStyleAction=new I(t),n._saveValues(!0),n}return __extends(t,e),Object.defineProperty(t.prototype,"isPaste",{get:function(){return this._isPaste},enumerable:!0,configurable:!0}),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return!!this._saveValues(!1)&&(this._mergeAction.saveNewState(),this._cellStyleAction.saveNewState(),this._checkActionState())},t.prototype.markIsPaste=function(){this._isPaste=!0},t.prototype.updateForPasting=function(e){var t=this._selections[this._selections.length-1],o=this._owner.getCellData(e.row,e.col,!!this._owner.columns[e.col].dataMap);t||(t=this._owner.selection,this._selections=[t]),o=null==o?"":o,this._oldValues["r"+e.row+"_c"+e.col]={row:e.row,col:e.col,value:o},t.row=Math.min(t.topRow,e.topRow),t.row2=Math.max(t.bottomRow,e.bottomRow),t.col=Math.min(t.leftCol,e.leftCol),t.col2=Math.max(t.rightCol,e.rightCol)},t.prototype._storeDeletedTables=function(e){null==this._deletedTables&&(this._deletedTables=[]),this._deletedTables.push(e)},t.prototype._checkActionState=function(){var e=this,t=!1;return Object.keys(e._oldValues).forEach(function(o){var n,i;t||(n=e._oldValues[o],i=e._newValues[o],n&&i&&n.value!==i.value&&(t=!0))}),t||e._mergeAction._checkActionState()||e._cellStyleAction._checkActionState()},t.prototype._saveValues=function(e){var t,o,n,i,l,s,r={};for(t=0;t<this._selections.length;t++)for(i=(o=this._selections[t]).topRow;i<=o.bottomRow;i++)for(l=o.leftCol;l<=o.rightCol;l++){if(!(n=this._owner.columns[l]))return!1;s=null==(s=this._owner.getCellData(i,l,!!n.dataMap))?"":s,r["r"+i+"_c"+l]={row:i,col:l,value:s}}return e?this._oldValues=r:this._newValues=r,!0},t.prototype._handleUndoRedo=function(e){var t=this;t._owner._clearCalcEngine(),t._owner.selectedSheet.selectionRanges.clear(),t._owner.deferUpdate(function(){var o,n,i,l,s=e?t._oldValues:t._newValues;if(t._deletedTables&&t._deletedTables.length>0)for(o=0;o<t._deletedTables.length;o++)n=t._deletedTables[o],e?t._owner.selectedSheet.tables.push(n):t._owner.selectedSheet.tables.remove(n);for(i=0;i<t._selections.length;i++)l=t._selections[i],t._owner.selectedSheet.selectionRanges.push(l);Object.keys(s).forEach(function(e){var o=s[e];t._owner.setCellData(o.row,o.col,o.value)}),e?(t._mergeAction.undo(),t._cellStyleAction.undo()):(t._mergeAction.redo(),t._cellStyleAction.redo()),t._owner.refresh(!1)})},t}(S);t._EditAction=R;var v=function(e){function t(t,o,n){var i=e.call(this,t)||this;return i._panel=o,i._colIndex=n,i._oldColWidth=o.columns[n].width,i}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return this._newColWidth=this._panel.columns[this._colIndex].width,this._oldColWidth!==this._newColWidth},t.prototype._handleUndoRedo=function(e){var t=this._panel.columns[this._colIndex];t&&(t.width=e?this._oldColWidth:this._newColWidth)},t}(S);t._ColumnResizeAction=v;var T=function(e){function t(t,o,n){var i=e.call(this,t)||this;return i._panel=o,i._rowIndex=n,i._oldRowHeight=o.rows[n].height,i}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return this._newRowHeight=this._panel.rows[this._rowIndex].height,this._oldRowHeight!==this._newRowHeight},t.prototype._handleUndoRedo=function(e){var t=this._panel.rows[this._rowIndex];t&&(t.height=e?this._oldRowHeight:this._newRowHeight)},t}(S);t._RowResizeAction=T;var x=function(e){function t(t,o,n,i){var l=e.call(this,t)||this;return l._columnIndex=o,l._count=n,l._isAdding=i,l._saveValues(!0),l}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return this._saveValues(!1),!0},t.prototype._saveValues=function(e){var t,o,n,i,l=[],s=[];if(null==this._isAdding)for(t=0;t<this._owner.columns.length;t++)l.push(this._owner.columns[t]);else if(e&&!this._isAdding||!e&&this._isAdding)for(t=this._columnIndex;t<this._columnIndex+this._count&&t<this._owner.columns.length;t++)l.push(this._owner.columns[t]);if(this._owner.selectedSheet.tables&&this._owner.selectedSheet.tables.length>0)for(o=0;o<this._owner.selectedSheet.tables.length;o++)(n=this._owner.selectedSheet.tables[o])&&n.sheet.name===this._owner.selectedSheet.name&&s.push({name:n.name,range:n.getRange(),columns:n.getColumns()});i={columns:l,sortList:this._owner.sortManager._cloneSortList(this._owner.sortManager._committedList),styledCells:this._owner.selectedSheet?this._owner._cloneObject(this._owner.selectedSheet._styledCells):null,mergedCells:this._owner.selectedSheet?this._owner.selectedSheet._cloneMergedCells():null,tableRanges:s,selection:this._owner.selection},e?this._oldValue=i:this._newValue=i},t.prototype._handleUndoRedo=function(e){var t,o,n,i,l,s,r,a,h,d,c,u,_=this,g=e?_._oldValue:_._newValue;_._owner.selectedSheet&&(_._owner.deferUpdate(function(){var f;if(_._owner._isUndoing=!0,_._owner._clearCalcEngine(),_._owner.finishEditing(),null==_._isAdding&&(_._owner.columns.clear(),_._columnIndex=0),_._owner.selectedSheet._styledCells=null,_._owner.selectedSheet._mergedRanges.length=0,_._owner.columns.beginUpdate(),g.columns&&g.columns.length>0)for(t=0;t<g.columns.length;t++)(o=g.columns[t])&&o.isVisible&&(_._owner.columns.insert(_._columnIndex+t,o),_._owner.itemsSource&&(f=_._owner.allowAddNew&&_._owner.newRowAtTop?_._owner.rows[1]:_._owner.rows[0])&&(f._ubv||(f._ubv={}),f._ubv[o._hash]=o.header));else for(t=_._columnIndex+_._count-1;t>=_._columnIndex;t--)(o=_._owner.columns[t])&&o.isVisible&&_._owner.columns.removeAt(t);for(_._owner.columns.endUpdate(),_._owner.selectedSheet._styledCells=_._owner._cloneObject(g.styledCells),u=0;u<g.mergedCells.length;u++)_._owner.selectedSheet._mergedRanges[u]=g.mergedCells[u];for(i=0;i<g.tableRanges.length;i++)l=g.tableRanges[i],(s=_._owner._getTable(l.name))&&s._setTableRange(l.range,l.columns);if(_._affectedFormulas&&(a=e?_._affectedFormulas.oldFormulas:_._affectedFormulas.newFormulas),a&&a.length>0)for(n=0;n<a.length;n++)null!=(r=a[n]).point?r.sheet.name===_._owner.selectedSheet.name?_._owner.setCellData(r.point.x,r.point.y,r.formula):r.sheet.grid.setCellData(r.point.x,r.point.y,r.formula):r.row._ubv[r.column._hash]=r.formula;if(_._deletedTables&&_._deletedTables.length>0)for(i=0;i<_._deletedTables.length;i++)s=_._deletedTables[i],e?_._owner.selectedSheet.tables.push(s):_._owner.selectedSheet.tables.remove(s);if(_._affectedDefinedNameVals&&(h=e?_._affectedDefinedNameVals.oldDefinedNameVals:_._affectedDefinedNameVals.newDefinedNameVals),h&&h.length>0)for(n=0;n<h.length;n++)d=h[n],(c=_._owner._getDefinedNameIndexByName(d.name))>-1&&(_._owner.definedNames[c].value=d.value);_._owner.selectedSheet.grid.wj_sheetInfo.styledCells=_._owner.selectedSheet._styledCells,_._owner.selectedSheet.grid.wj_sheetInfo.mergedRanges=_._owner.selectedSheet._mergedRanges,_._owner._isUndoing=!1}),_._owner._copyColumnsToSelectedSheet(),_._owner.sortManager.sortDescriptions.sourceCollection=g.sortList.slice(),_._owner.sortManager.commitSort(!1),_._owner.selection=g.selection)},t}(S);t._ColumnsChangedAction=x;var k=function(e){function t(t,o,n,i){var l=e.call(this,t)||this;return l._rowIndex=o,l._count=n,l._isAdding=i,l._saveValues(!0),l}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return this._saveValues(!1),!0},t.prototype._saveValues=function(e){var t,n,i,l,s,r,a=[],h=[],d=[];if(null==this._isAdding)if(this._owner.itemsSource)for(s=this._owner.itemsSource instanceof o.CollectionView?this._owner.itemsSource.sourceCollection.slice():this._owner.itemsSource.slice(),n=0;n<this._owner.columns.length;n++)h.push(this._owner.columns[n]);else for(t=0;t<this._owner.rows.length;t++)a.push(this._owner.rows[t]);else if(e&&!this._isAdding||!e&&this._isAdding)for(t=this._rowIndex;t<this._rowIndex+this._count&&t<this._owner.rows.length;t++)a.push(this._owner.rows[t]);if(this._owner.selectedSheet.tables&&this._owner.selectedSheet.tables.length>0)for(i=0;i<this._owner.selectedSheet.tables.length;i++)(l=this._owner.selectedSheet.tables[i])&&l.sheet.name===this._owner.selectedSheet.name&&d.push({name:l.name,range:l.getRange(),setting:{showHeaderRow:l.showHeaderRow,showTotalRow:l.showTotalRow}});r={rows:a,columns:h,itemsSource:s,styledCells:this._owner.selectedSheet?this._owner._cloneObject(this._owner.selectedSheet._styledCells):null,mergedCells:this._owner.selectedSheet?this._owner.selectedSheet._cloneMergedCells():null,tableSettings:d,selection:this._owner.selection},e?this._oldValue=r:this._newValue=r},t.prototype._handleUndoRedo=function(e){var t,n,i,l,s,r,a,h,d,c,u,_,g,f,p=this,w=this,m=!!w._owner.itemsSource,C=e?w._oldValue:w._newValue;w._owner.selectedSheet&&(w._owner.deferUpdate(function(){if(w._owner._isUndoing=!0,w._owner._clearCalcEngine(),w._owner.finishEditing(),null==w._isAdding&&(w._owner.itemsSource&&w._owner.columns.clear(),w._owner.rows.clear(),w._rowIndex=0),w._owner.selectedSheet._styledCells=null,w._owner.selectedSheet._mergedRanges.length=0,null==p._isAdding&&m){for(w._owner.collectionView.beginUpdate(),w._owner.autoGenerateColumns=!1,w._owner.itemsSource instanceof o.CollectionView?(f=[0,w._owner.itemsSource.sourceCollection.length].concat(C.itemsSource),Array.prototype.splice.apply(w._owner.itemsSource.sourceCollection,f)):w._owner.itemsSource=C.itemsSource.slice(),w._owner.columns.beginUpdate(),i=0;i<C.columns.length;i++)w._owner.columns.push(C.columns[i]);w._owner.columns.endUpdate(),w._owner.collectionView.endUpdate()}else{if(m?w._owner.collectionView.beginUpdate():w._owner.rows.beginUpdate(),C.rows&&C.rows.length>0)for(t=0;t<C.rows.length;t++)n=C.rows[t],m&&n.dataItem?(w._owner.itemsSource instanceof o.CollectionView?w._owner.itemsSource.sourceCollection.splice(w._rowIndex+t-(w._owner.allowAddNew&&w._owner.newRowAtTop?2:1),0,n.dataItem):w._owner.itemsSource.splice(w._rowIndex+t-(w._owner.allowAddNew&&w._owner.newRowAtTop?2:1),0,n.dataItem),w._owner.selectedSheet._orgItemsSource&&w._owner.selectedSheet._orgItemsSource.splice(w._rowIndex+t-(w._owner.allowAddNew&&w._owner.newRowAtTop?2:1),0,n.dataItem)):w._owner.rows.insert(w._rowIndex+t,n);else for(t=w._rowIndex+w._count-1;t>=w._rowIndex;t--)(n=w._owner.rows[t])&&n.isVisible&&(m&&n.dataItem?(w._owner.itemsSource instanceof o.CollectionView?w._owner.itemsSource.sourceCollection.splice(t-(w._owner.allowAddNew&&w._owner.newRowAtTop?2:1),1):w._owner.itemsSource.splice(t-(w._owner.allowAddNew&&w._owner.newRowAtTop?2:1),1),w._owner.selectedSheet._orgItemsSource&&w._owner.selectedSheet._orgItemsSource.splice(t-(w._owner.allowAddNew&&w._owner.newRowAtTop?2:1),1)):w._owner.rows.removeAt(t));m?w._owner.collectionView.endUpdate():w._owner.rows.endUpdate()}for(w._owner.selectedSheet._styledCells=w._owner._cloneObject(C.styledCells),g=0;g<C.mergedCells.length;g++)w._owner.selectedSheet._mergedRanges[g]=C.mergedCells[g];for(s=0;s<C.tableSettings.length;s++)r=C.tableSettings[s],(a=w._owner._getTable(r.name))&&(a._showHeaderRow=r.setting.showHeaderRow,a._showTotalRow=r.setting.showTotalRow,a._setTableRange(r.range));if(w._affectedFormulas&&(d=e?w._affectedFormulas.oldFormulas:w._affectedFormulas.newFormulas),d&&d.length>0)for(l=0;l<d.length;l++)null!=(h=d[l]).point?h.sheet.name===w._owner.selectedSheet.name?w._owner.setCellData(h.point.x,h.point.y,h.formula):h.sheet.grid.setCellData(h.point.x,h.point.y,h.formula):h.row._ubv[h.column._hash]=h.formula;if(w._deletedTables&&w._deletedTables.length>0)for(s=0;s<w._deletedTables.length;s++)a=w._deletedTables[s],e?w._owner.selectedSheet.tables.push(a):w._owner.selectedSheet.tables.remove(a);if(w._affectedDefinedNameVals&&(c=e?w._affectedDefinedNameVals.oldDefinedNameVals:w._affectedDefinedNameVals.newDefinedNameVals),c&&c.length>0)for(l=0;l<c.length;l++)u=c[l],(_=w._owner._getDefinedNameIndexByName(u.name))>-1&&(w._owner.definedNames[_].value=u.value);w._owner.selectedSheet.grid.wj_sheetInfo.styledCells=w._owner.selectedSheet._styledCells,w._owner.selectedSheet.grid.wj_sheetInfo.mergedRanges=w._owner.selectedSheet._mergedRanges,w._owner.selection=C.selection,w._owner._isUndoing=!1}),w._owner._copyRowsToSelectedSheet())},t}(S);t._RowsChangedAction=k;var I=function(e){function t(t,o){var n=e.call(this,t)||this;return n._oldStyledCells=o?t._cloneObject(o):t.selectedSheet?t._cloneObject(t.selectedSheet._styledCells):null,n}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return this._newStyledCells=this._owner.selectedSheet?this._owner._cloneObject(this._owner.selectedSheet._styledCells):null,!0},t.prototype._checkActionState=function(){return null!=this._oldStyledCells&&null==this._newStyledCells||null==this._oldStyledCells&&null!=this._newStyledCells||null!=this._oldStyledCells&&null!=this._newStyledCells&&this._oldStyledCells.length!==this._newStyledCells.length},t.prototype._handleUndoRedo=function(e){var t;this._owner.selectedSheet&&(t=e?this._oldStyledCells:this._newStyledCells,this._owner.selectedSheet._styledCells=this._owner._cloneObject(t),this._owner.selectedSheet.grid.wj_sheetInfo.styledCells=this._owner.selectedSheet._styledCells,this._owner.refresh(!1))},t}(S);t._CellStyleAction=I;var E=function(e){function t(t){var o=e.call(this,t)||this;return o._oldMergedCells=t.selectedSheet?t.selectedSheet._cloneMergedCells():null,o}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return this._newMergedCells=this._owner.selectedSheet?this._owner.selectedSheet._cloneMergedCells():null,!0},t.prototype._handleUndoRedo=function(e){var t,o;if(this._owner.selectedSheet){if(t=e?this._oldMergedCells:this._newMergedCells,this._owner._clearCalcEngine(),t)for(this._owner.selectedSheet._mergedRanges.length=0,o=0;o<t.length;o++)this._owner.selectedSheet._mergedRanges[o]=t[o];this._owner.selectedSheet.grid.wj_sheetInfo.mergedRanges=this._owner.selectedSheet._mergedRanges,this._owner.refresh(!0)}},t.prototype._checkActionState=function(){var e,t,o;if(null!=this._oldMergedCells&&null==this._newMergedCells||null==this._oldMergedCells&&null!=this._newMergedCells)return!0;if(null!=this._oldMergedCells&&null!=this._newMergedCells&&this._oldMergedCells.length!==this._newMergedCells.length)return!0;if(null!=this._oldMergedCells&&null!=this._newMergedCells&&this._oldMergedCells.length===this._newMergedCells.length)for(e=0;e<this._oldMergedCells.length;e++)if(o=this._oldMergedCells[e],t=this._oldMergedCells[e],!o.equals(t))return!0;return!1},t}(S);t._CellMergeAction=E;var D=function(e){function t(t){var o=e.call(this,t)||this;return o._saveValues(!0),o}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return this._saveValues(!1),!0},t.prototype._saveValues=function(e){var t,o,n,i,l,s=[];for(o=0;o<this._owner.columns.length;o++)s.push(this._owner.columns[o]);if(this._owner.itemsSource)i=this._owner.collectionView._view.slice();else for(n=[],t=0;t<this._owner.rows.length;t++)n.push(this._owner.rows[t]);l={sortList:this._owner.sortManager._committedList.slice(),rows:n,columns:s,selection:this._owner.selection.clone(),items:i,formulas:this._owner._scanFormulas(),styledCells:this._owner.selectedSheet?this._owner._cloneObject(this._owner.selectedSheet._styledCells):null},e?this._oldValue=l:this._newValue=l},t.prototype._handleUndoRedo=function(e){var t,n,l,s,r,a,h=this,d=this,c=e?d._oldValue:d._newValue,u=!!d._owner.itemsSource,_=this._owner.itemsSource instanceof o.CollectionView;d._owner.selectedSheet&&(d._owner._isUndoing=!0,d._owner.deferUpdate(function(){if(d._owner._clearCalcEngine(),d._owner.sortManager.sortDescriptions.sourceCollection=c.sortList.slice(),d._owner.sortManager._committedList=c.sortList.slice(),d._owner.selectedSheet._styledCells=d._owner._cloneObject(c.styledCells),u)d._owner.autoGenerateColumns=!1,_?d._owner.itemsSource.sourceCollection=c.items:(a=d._owner.selectedSheet._filterDefinition,d._owner.itemsSource=c.items);else for(d._owner.rows.clear(),d._owner.selectedSheet.grid.rows.clear(),t=0;t<c.rows.length;t++)l=c.rows[t],d._owner.selectedSheet.grid.rows.push(l),d._owner.rows.push(l);for(d._owner.columns.clear(),u&&!_&&(r=h._owner.rows[0]instanceof i._NewRowTemplate?h._owner.rows[1]:h._owner.rows[0]),n=0;n<c.columns.length;n++)s=c.columns[n],d._owner.columns.push(s),r&&(r._ubv||(r._ubv={}),r._ubv[s._hash]=s.header);u&&(_||(d._owner.filter.filterDefinition=a),d._owner.selection=c.selection),d._owner._resetFormulas(c.formulas),d._owner._isUndoing=!1}))},t}(S);t._SortColumnAction=D;var N=function(e){function t(t,o,n,i){var l=e.call(this,t)||this;return t.selectedSheet?(0===o.topRow&&o.bottomRow===t.rows.length-1?l._isDraggingColumns=!0:l._isDraggingColumns=!1,l._isCopyCells=i,l._dragRange=o,l._dropRange=n,l._saveValues(!0),l):l}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return!!this._owner.selectedSheet&&(!!this._dropRange&&(this._saveValues(!1),!0))},t.prototype._saveValues=function(e){var t,o,n,i,l,s,r,a,h,d,c,u;for(c=[],u={},t=this._dropRange.topRow;t<=this._dropRange.bottomRow;t++)for(o=this._dropRange.leftCol;o<=this._dropRange.rightCol;o++)this._isDraggingColumns&&(u[o]||(u[o]={dataType:this._owner.columns[o].dataType,align:this._owner.columns[o].align,format:this._owner.columns[o].format})),n=t*this._owner.columns.length+o,l=this._owner.selectedSheet._styledCells[n]?this._owner._cloneObject(this._owner.selectedSheet._styledCells[n]):null,i=this._owner.getCellData(t,o,!1),c.push({rowIndex:t,columnIndex:o,cellContent:i,cellStyle:l});if(e?(this._oldDroppingCells=c,this._oldDroppingColumnSetting=u):(this._newDroppingCells=c,this._newDroppingColumnSetting=u),this._isCopyCells){if(this._isDraggingColumns)if(e)for(t=this._dragRange.topRow;t<=this._dragRange.bottomRow;t++)for(o=this._dragRange.leftCol;o<=this._dragRange.rightCol;o++)(a=this._owner.selectedSheet.findTable(t,o))&&(h=a.getRange(),d=a.getColumns(),a.showHeaderRow&&t===h.topRow&&(this._draggingTableColumns||(this._draggingTableColumns=[]),this._draggingTableColumns.push({rowIndex:t,columnIndex:o,cellContent:d[o-h.leftCol].name})));else if(this._draggingTableColumns&&this._draggingTableColumns.length>0&&this._draggingTableColumns&&this._draggingTableColumns.length>0)for(s=0;s<this._draggingTableColumns.length;s++)r=this._draggingTableColumns[s],(a=this._owner.selectedSheet.findTable(r.rowIndex,r.columnIndex))&&(h=a.getRange(),d=a.getColumns(),a.showHeaderRow&&r.rowIndex===h.topRow&&(r.updatedCellContent=d[r.columnIndex-h.leftCol].name))}else if(e)for(this._draggingCells=[],this._draggingColumnSetting={},t=this._dragRange.topRow;t<=this._dragRange.bottomRow;t++)for(o=this._dragRange.leftCol;o<=this._dragRange.rightCol;o++)this._isDraggingColumns&&(this._draggingColumnSetting[o]||(this._draggingColumnSetting[o]={dataType:this._owner.columns[o].dataType,align:this._owner.columns[o].align,format:this._owner.columns[o].format})),n=t*this._owner.columns.length+o,l=this._owner.selectedSheet._styledCells[n]?this._owner._cloneObject(this._owner.selectedSheet._styledCells[n]):null,i=this._owner.getCellData(t,o,!1),this._draggingCells.push({rowIndex:t,columnIndex:o,cellContent:i,cellStyle:l});else if(this._isDraggingColumns&&this._draggingCells&&this._draggingCells.length>0)for(s=0;s<this._draggingCells.length;s++)r=this._draggingCells[s],(a=this._owner.selectedSheet.findTable(r.rowIndex,r.columnIndex))&&(h=a.getRange(),d=a.getColumns(),a.showHeaderRow&&r.rowIndex===h.topRow&&(r.updatedCellContent=d[r.columnIndex-h.leftCol].name))},t.prototype._handleUndoRedo=function(e){var t,n,i,l,s,r,a,h,d,c,u=this,_=e?u._oldDroppingCells:u._newDroppingCells,g=e?u._oldDroppingColumnSetting:u._newDroppingColumnSetting;u._owner.selectedSheet&&(u._owner._clearCalcEngine(),u._owner.deferUpdate(function(){var f,p,w;if(u._affectedFormulas&&(r=e?u._affectedFormulas.oldFormulas:u._affectedFormulas.newFormulas),r&&r.length>0)for(t=0;t<r.length;t++)(a=r[t]).sheet.name===u._owner.selectedSheet.name?u._owner.setCellData(a.point.x,a.point.y,a.formula):a.sheet.grid.setCellData(a.point.x,a.point.y,a.formula);if(u._affectedDefinedNameVals&&(h=e?u._affectedDefinedNameVals.oldDefinedNameVals:u._affectedDefinedNameVals.newDefinedNameVals),h&&h.length>0)for(t=0;t<h.length;t++)d=h[t],(c=u._owner._getDefinedNameIndexByName(d.name))>-1&&(u._owner.definedNames[c].value=d.value);for(t=0;t<_.length;t++)n=_[t],u._owner.setCellData(n.rowIndex,n.columnIndex,n.cellContent),(f=u._owner.selectedSheet.findTable(n.rowIndex,n.columnIndex))&&(p=f.getRange(),w=f.getColumns(),f.showHeaderRow&&n.rowIndex===p.topRow&&(w[n.columnIndex-p.leftCol].name=n.cellContent)),i=n.rowIndex*u._owner.columns.length+n.columnIndex,n.cellStyle?u._owner.selectedSheet._styledCells[i]=n.cellStyle:delete u._owner.selectedSheet._styledCells[i];if(u._isDraggingColumns&&g&&Object.keys(g).forEach(function(e){u._owner.columns[+e].dataType=g[+e].dataType?g[+e].dataType:o.DataType.Object,u._owner.columns[+e].align=g[+e].align,u._owner.columns[+e].format=g[+e].format}),u._isCopyCells){if(u._draggingTableColumns&&u._draggingTableColumns.length>0)for(t=0;t<u._draggingTableColumns.length;t++)n=u._draggingTableColumns[t],(f=u._owner.selectedSheet.findTable(n.rowIndex,n.columnIndex))&&(p=f.getRange(),w=f.getColumns(),f.showHeaderRow&&n.rowIndex===p.topRow&&(u._owner.setCellData(n.rowIndex,n.columnIndex,e?n.cellContent:n.updatedCellContent),w[n.columnIndex-p.leftCol].name=e?n.cellContent:n.updatedCellContent))}else{for(t=0;t<u._draggingCells.length;t++)n=u._draggingCells[t],(f=u._owner.selectedSheet.findTable(n.rowIndex,n.columnIndex))?(p=f.getRange(),w=f.getColumns(),f.showHeaderRow&&n.rowIndex===p.topRow?(u._owner.setCellData(n.rowIndex,n.columnIndex,e?n.cellContent:n.updatedCellContent),w[n.columnIndex-p.leftCol].name=e?n.cellContent:n.updatedCellContent):u._owner.setCellData(n.rowIndex,n.columnIndex,e?n.cellContent:null)):u._owner.setCellData(n.rowIndex,n.columnIndex,e?n.cellContent:null),i=n.rowIndex*u._owner.columns.length+n.columnIndex,e?n.cellStyle&&(u._owner.selectedSheet._styledCells[i]=n.cellStyle):u._owner.selectedSheet._styledCells[i]&&delete u._owner.selectedSheet._styledCells[i];if(u._isDraggingColumns&&u._draggingColumnSetting&&Object.keys(u._draggingColumnSetting).forEach(function(t){u._owner.columns[+t].dataType=e&&u._draggingColumnSetting[+t].dataType?u._draggingColumnSetting[+t].dataType:o.DataType.Object,u._owner.columns[+t].align=e?u._draggingColumnSetting[+t].align:null,u._owner.columns[+t].format=e?u._draggingColumnSetting[+t].format:null}),e){if(u._isDraggingColumns)if(u._dragRange.leftCol<u._dropRange.leftCol)for(s=u._dragRange.leftCol,l=u._dropRange.leftCol;l<=u._dropRange.rightCol;l++)u._owner._updateColumnFiler(l,s),s++;else for(s=u._dragRange.rightCol,l=u._dropRange.rightCol;l>=u._dropRange.leftCol;l--)u._owner._updateColumnFiler(l,s),s--}else if(u._isDraggingColumns)if(u._dragRange.leftCol>u._dropRange.leftCol)for(s=u._dropRange.leftCol,l=u._dragRange.leftCol;l<=u._dragRange.rightCol;l++)u._owner._updateColumnFiler(l,s),s++;else for(s=u._dropRange.rightCol,l=u._dragRange.rightCol;l>=u._dragRange.leftCol;l--)u._owner._updateColumnFiler(l,s),s--}}))},t}(S);t._MoveCellsAction=N;var A=function(e){function t(t){var o=e.call(this,t)||this;return o._oldValues=[],o._mergeAction=new E(t),o._celltyleAction=new I(t),o._cutSheet=t._copiedSheet,o._selection=t.selection,o._cutSelection=t.selectionMode===i.SelectionMode.ListBox?t._getSelectionForListBoxMode(o._cutSheet.grid):t._copiedRanges[0],o._saveCutValues(!0),o}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){var e,t,o;this._cutSheet===this._owner.selectedSheet?this._owner:this._cutSheet.grid;for(this._saveCutValues(!1),this._newValues=[],e=this._selection.topRow;e<=this._selection.bottomRow;e++)for(t=this._selection.leftCol;t<=this._selection.rightCol;t++){if(!this._owner.columns[t])return!1;o=null==(o=this._owner.getCellData(e,t,!!this._owner.columns[t].dataMap))?"":o,this._newValues.push({row:e,col:t,value:o})}return this._mergeAction.saveNewState(),this._celltyleAction.saveNewState(),!0},t.prototype.updateForPasting=function(e){var t=this._owner.getCellData(e.row,e.col,!!this._owner.columns[e.col].dataMap);t=null==t?"":t,this._oldValues.push({row:e.row,col:e.col,value:t}),this._selection.row=Math.min(this._selection.topRow,e.topRow),this._selection.row2=Math.max(this._selection.bottomRow,e.bottomRow),this._selection.col=Math.min(this._selection.leftCol,e.leftCol),this._selection.col2=Math.max(this._selection.rightCol,e.rightCol)},t.prototype._saveCutValues=function(e){var t,o,n,i=this._cutSheet===this._owner.selectedSheet?this._owner:this._cutSheet.grid,l=[];for(t=this._cutSelection.topRow;t<=this._cutSelection.bottomRow;t++)if(null!=i.rows[t])for(o=this._cutSelection.leftCol;o<=this._cutSelection.rightCol;o++)n=null==(n=i.getCellData(t,o,!!i.columns[o].dataMap))?"":n,l.push({row:t,col:o,value:n});e?this._oldCutValues=l:this._newCutValues=l},t.prototype._handleUndoRedo=function(e){var t=this,o=e?t._oldCutValues:t._newCutValues,n=e?t._oldValues:t._newValues;t._owner._clearCalcEngine(),t._owner.selectedSheet.selectionRanges.clear(),t._owner.deferUpdate(function(){var i,l,s=t._cutSheet===t._owner.selectedSheet?t._owner:t._cutSheet.grid;for(t._owner.selectedSheet.selectionRanges.push(t._selection),i=0;i<o.length;i++)l=o[i],s.setCellData(l.row,l.col,l.value);for(i=0;i<n.length;i++)l=n[i],t._owner.setCellData(l.row,l.col,l.value);e?(t._mergeAction.undo(),t._celltyleAction.undo()):(t._mergeAction.redo(),t._celltyleAction.redo()),t._owner.refresh(!1)})},t}(S);t._CutAction=A;var F=function(e){function t(t,o){var n=e.call(this,t)||this;return n._table=o,n._saveValues(!0),n}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return this._saveValues(!1),!0},t.prototype._saveValues=function(e){var t={name:this._table.name,style:this._table.style,showHeaderRow:this._table.showHeaderRow,showTotalRow:this._table.showTotalRow,showbandedRows:this._table.showBandedRows,showBandedColumns:this._table.showBandedColumns,alterFirstColumn:this._table.alterFirstColumn,alterLastColumn:this._table.alterLastColumn};e?this._oldTableSetting=t:this._newTableSetting=t},t.prototype._handleUndoRedo=function(e){var t=e?this._oldTableSetting:this._newTableSetting;this._owner.beginUpdate(),this._owner._isUndoing=!0,this._table.name=t.name,this._table.style=t.style,this._table.showHeaderRow=t.showHeaderRow,this._table.showTotalRow=t.showTotalRow,this._table.showBandedRows=t.showbandedRows,this._table.showBandedColumns=t.showBandedColumns,this._table.alterFirstColumn=t.alterFirstColumn,this._table.alterLastColumn=t.alterLastColumn,this._owner._isUndoing=!1,this._owner.endUpdate()},t}(S);t._TableSettingAction=F;var M=function(e){function t(t,o){var n=e.call(this,t)||this;return n._addedTable=o,n}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype._handleUndoRedo=function(e){var t,o,n;if(this._addedTable.showHeaderRow)for(o=this._addedTable.getRange(),n=this._addedTable.getColumns(),t=0;t<o.columnSpan;t++)this._owner.setCellData(o.topRow,o.leftCol+t,e?this._addedTable._orgHeaderCellsContent[t]:n[t].name);e?this._owner.selectedSheet.tables.remove(this._addedTable):this._owner.selectedSheet.tables.push(this._addedTable),this._owner.refresh()},t}(S);t._TableAction=M;var V=function(e){function t(t){var o=e.call(this,t)||this;return o._oldFilterDefinition=t.filter.filterDefinition,o._oldRowsVisible=o._getRowsVisible(),o}return __extends(t,e),t.prototype.undo=function(){this._handleUndoRedo(!0)},t.prototype.redo=function(){this._handleUndoRedo(!1)},t.prototype.saveNewState=function(){return this._newFilterDefinition=this._owner.filter.filterDefinition,this._newRowsVisible=this._getRowsVisible(),!0},t.prototype._handleUndoRedo=function(e){var t=e?this._oldFilterDefinition:this._newFilterDefinition;this._owner.filter.filterDefinition!==t?(this._owner._isUndoing=!0,this._owner.selectedSheet._filterDefinition=t,this._owner.selectedSheet._applyFilterSetting(),this._owner._isUndoing=!1,this._owner.filter.apply()):this._setRowVisible(e)},t.prototype._getRowsVisible=function(){for(var e,t=[],o=0;o<this._owner.rows.length;o++)(e=this._owner.rows[o])&&t.push(e.visible);return t},t.prototype._setRowVisible=function(e){for(var t,o=e?this._oldRowsVisible:this._newRowsVisible,n=0;n<o.length;n++)(t=this._owner.rows[n])&&(t.visible=o[n])},t}(S);t._FilteringAction=V;var L=function(e){function t(t,o){var n=e.call(this,t)||this;return n._idx=-1,n._isDisableDelRow=!1,n._owner=o,n.applyTemplate("",n.getTemplate(),{_insRows:"insert-rows",_delRows:"delete-rows",_insCols:"insert-columns",_delCols:"delete-columns",_convertTable:"convert-table"}),n._init(),n}return __extends(t,e),Object.defineProperty(t.prototype,"visible",{get:function(){return"none"!==this.hostElement.style.display},enumerable:!0,configurable:!0}),t.prototype.show=function(e,t){if(this._owner.selectedSheet){var n=(t?t.x:e.clientX)+(e?window.pageXOffset:0),i=(t?t.y:e.clientY)+(e?window.pageYOffset:0);this.hostElement.style.position="absolute",this.hostElement.style.display="inline",this._owner._isDisableDeleteRow(this._owner.selection.topRow,this._owner.selection.bottomRow)&&(this._isDisableDelRow=!0,o.addClass(this._delRows,"wj-state-disabled")),this._showTableOperation(),this._owner.selection.isValid||o.addClass(this._convertTable,"wj-state-disabled"),i+this.hostElement.clientHeight>window.innerHeight&&(i-=this.hostElement.clientHeight),n+this.hostElement.clientWidth>window.innerWidth&&(n-=this.hostElement.clientWidth),this.hostElement.style.top=i+"px",this.hostElement.style.left=n+"px"}},t.prototype.hide=function(){this._idx=-1;var e=this.hostElement.querySelectorAll(".wj-context-menu-item");this._removeSelectedState(e),this.hostElement.style.display="none",this._isDisableDelRow=!1,o.removeClass(this._delRows,"wj-state-disabled"),o.removeClass(this._convertTable,"wj-state-disabled")},t.prototype.moveToNext=function(){var e=this.hostElement.querySelectorAll(".wj-context-menu-item");for(this._removeSelectedState(e),this._idx++,1===this._idx&&this._isDisableDelRow&&this._idx++;e[this._idx]&&"none"===e[this._idx].style.display;)this._idx++;this._idx>=e.length&&(this._idx=0),o.addClass(e[this._idx],"wj-context-menu-item-selected")},t.prototype.moveToPrev=function(){var e=this.hostElement.querySelectorAll(".wj-context-menu-item");for(this._removeSelectedState(e),this._idx--,1===this._idx&&this._isDisableDelRow&&this._idx--;this._idx>0&&"none"===e[this._idx].style.display;)this._idx--;this._idx<0&&(this._idx=e.length-1),o.addClass(e[this._idx],"wj-context-menu-item-selected")},t.prototype.moveToFirst=function(){var e=this.hostElement.querySelectorAll(".wj-context-menu-item");this._removeSelectedState(e),this._idx=0,o.addClass(e[this._idx],"wj-context-menu-item-selected")},t.prototype.moveToLast=function(){var e=this.hostElement.querySelectorAll(".wj-context-menu-item");this._removeSelectedState(e),this._idx=e.length-1,e[this._idx]&&"none"===e[this._idx].style.display&&this._idx--,o.addClass(e[this._idx],"wj-context-menu-item-selected")},t.prototype.handleContextMenu=function(){if(-1===this._idx)this.moveToNext();else{switch(this.hostElement.querySelectorAll(".wj-context-menu-item")[this._idx]){case this._insCols:this._owner.insertColumns();break;case this._insRows:this._owner.insertRows();break;case this._delCols:this._owner.deleteColumns();break;case this._delRows:this._isDisableDelRow||this._owner.deleteRows();break;case this._convertTable:this._addTable()}this.hide(),this._owner.hostElement.focus()}},t.prototype._init=function(){var e=this,t=this.hostElement.querySelectorAll(".wj-context-menu-item");e.hostElement.style.zIndex="9999",document.querySelector("body").appendChild(e.hostElement),e.addEventListener(document.body,"mousemove",function(){e._removeSelectedState(t)}),e.addEventListener(e.hostElement,"contextmenu",function(e){e.preventDefault()}),e.addEventListener(e._insRows,"click",function(t){e._owner.insertRows(),e.hide(),e._owner.hostElement.focus()}),e.addEventListener(e._delRows,"click",function(t){e._isDisableDelRow||e._owner.deleteRows(),e.hide(),e._owner.hostElement.focus()}),e.addEventListener(e._insCols,"click",function(t){e._owner.insertColumns(),e.hide(),e._owner.hostElement.focus()}),e.addEventListener(e._delCols,"click",function(t){e._owner.deleteColumns(),e.hide(),e._owner.hostElement.focus()}),e.addEventListener(e._convertTable,"click",function(t){e._addTable(),e.hide(),e._owner.hostElement.focus()})},t.prototype._removeSelectedState=function(e){for(var t=0;t<e.length;t++)o.removeClass(e[t],"wj-context-menu-item-selected")},t.prototype._showTableOperation=function(){var e,t,o=this._owner.selection;for(e=o.topRow;e<=o.bottomRow;e++)for(t=o.leftCol;t<=o.rightCol;t++)if(null!=this._owner.selectedSheet.findTable(e,t))return this._convertTable.style.display="none",void(this._convertTable.parentElement.style.display="none");o.isSingleCell||this._owner._containsMergedCells(o)?(this._convertTable.style.display="none",this._convertTable.parentElement.style.display="none"):(this._convertTable.style.display="inline",this._convertTable.parentElement.style.display="inline")},t.prototype._addTable=function(){var e,t;0!==this._owner.undoStack.stackSize&&(e=this._owner.selectedSheet._addTable(this._owner.selection),t=new M(this._owner,e),this._owner.undoStack._addAction(t))},t.controlTemplate='<div class="wj-context-menu wj-control wj-flexsheet-context-menu" width="150px"><div class="wj-context-menu-item" wj-part="insert-rows">Insert Row</div><div class="wj-context-menu-item" wj-part="delete-rows">Delete Rows</div><div class="wj-context-menu-item" wj-part="insert-columns">Insert Column</div><div class="wj-context-menu-item" wj-part="delete-columns">Delete Columns</div><div><div class="wj-state-disabled" style="width:100%;height:1px;background-color:lightgray;"></div><div class="wj-context-menu-item" wj-part="convert-table">Convert To Table</div></div></div>',t}(o.Control);t._ContextMenu=L;var H=function(e){function t(t,o){var n=e.call(this,t)||this;return n._splitterMousedownHdl=n._splitterMousedownHandler.bind(n),n._owner=o,n.applyTemplate("",n.getTemplate(),{_divSheet:"left",_divSplitter:"splitter",_divRight:"right"}),n._init(),n}return __extends(t,e),Object.defineProperty(t.prototype,"sheetControl",{get:function(){return this._sheetControl},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"visible",{get:function(){return"none"!==this.hostElement.style.display},set:function(e){this.hostElement.style.display=e?"block":"none",this._divSheet.style.display=e?"block":"none"},enumerable:!0,configurable:!0}),t.prototype.getSheetBlanketSize=function(){return 20},t.prototype.adjustSize=function(){var e=this._owner.scrollSize.width-this._owner.clientSize.width,t=(this._owner.scrollSize.height,this._owner.clientSize.height,this._divSplitter.parentElement);e<=0?(t.style.minWidth="100px",this._divSplitter.style.display="none",this._divRight.style.display="none",this._divSheet.style.width="100%",this._divSplitter.removeEventListener("mousedown",this._splitterMousedownHdl,!0)):(t.style.minWidth="300px",this._divSplitter.style.display="none",this._divRight.style.display="none",this._divSheet.style.width="100%",this._divSplitter.removeEventListener("mousedown",this._splitterMousedownHdl,!0),this._divSplitter.addEventListener("mousedown",this._splitterMousedownHdl,!0)),this._sheetControl._adjustSize()},t.prototype._init=function(){var e=this;e._funSplitterMousedown=function(t){e._splitterMouseupHandler(t)},e._divSplitter.parentElement.style.height=e.getSheetBlanketSize()+"px",e._sheetControl=new $(e._divSheet,this._owner)},t.prototype._splitterMousedownHandler=function(e){this._startPos=e.pageX,document.addEventListener("mousemove",this._splitterMousemoveHandler.bind(this),!0),document.addEventListener("mouseup",this._funSplitterMousedown,!0),e.preventDefault()},t.prototype._splitterMousemoveHandler=function(e){null!==this._startPos&&void 0!==this._startPos&&this._adjustDis(e.pageX-this._startPos)},t.prototype._splitterMouseupHandler=function(e){document.removeEventListener("mousemove",this._splitterMousemoveHandler,!0),document.removeEventListener("mouseup",this._funSplitterMousedown,!0),this._adjustDis(e.pageX-this._startPos),this._startPos=null},t.prototype._adjustDis=function(e){var t=this._divRight.offsetWidth-e,o=this._divSheet.offsetWidth+e;t<=100?(t=100,e=this._divRight.offsetWidth-t,o=this._divSheet.offsetWidth+e):o<=100&&(e=(o=100)-this._divSheet.offsetWidth,t=this._divRight.offsetWidth-e),0!=e&&(this._divRight.style.width=t+"px",this._divSheet.style.width=o+"px",this._startPos=this._startPos+e)},t.controlTemplate='<div><div wj-part="left" style ="float:left;height:100%;overflow:hidden"></div><div wj-part="splitter" style="float:left;height:100%;width:6px;background-color:#e9eaee;padding:2px;cursor:e-resize"><div style="background-color:#8a9eb2;height:100%"></div></div><div wj-part="right" style="float:left;height:100%;background-color:#e9eaee"></div></div>',t}(o.Control);t._TabHolder=H;var P=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.updateCell=function(t,n,l,s,r){var a,h,d,c,u,_,g,f,p,m,C,b,y,S,R,v=t.grid;switch(t.cellType===i.CellType.Cell&&this._resetCellStyle(t.columns[l],s),e.prototype.updateCell.call(this,t,n,l,s,r),r&&!r.isSingleCell&&(n=r.row,l=r.col,r.row2,r.col2),R=v.selectedSheet,m=v._getBindingColumn(t,n,t.columns[l]),t.cellType){case i.CellType.RowHeader:s.textContent=n+1+"";break;case i.CellType.ColumnHeader:a=R&&R._showDefaultHeader||o.isNullOrWhiteSpace(m.header)||!o.isNullOrWhiteSpace(m.binding)&&(m.header===m.binding||m.header===o.toHeaderCase(m.binding))?O.convertNumberToAlpha(l):m.header,s.textContent?s.innerHTML=s.innerHTML.replace(o.escapeHtml(s.textContent.trim()),a).replace(s.textContent,a):s.innerHTML+=a,s.style.textAlign="center";break;case i.CellType.Cell:if(h=n*v.columns.length+l,g=R&&R._styledCells?R._styledCells[h]:null,r&&!r.isSingleCell&&(n=(b=this._getFirstVisibleCell(v,r)).row,l=b.col),t.rows[n]instanceof G)t.columns[l].dataType===o.DataType.Boolean?1===s.childElementCount&&s.firstElementChild instanceof HTMLInputElement&&"checkbox"===s.firstElementChild.type&&(s.innerHTML=o.escapeHtml(v.getCellValue(n,l))):s.innerHTML||(s.innerHTML=o.escapeHtml(v.getCellValue(n,l))),o.addClass(s,"wj-header-row");else if(c=v.getCellValue(n,l,!1),u=v.getCellData(n,l,!1),_=null!=u&&"string"==typeof u&&"="===u[0],y=t.rows[n]instanceof i.GroupRow,C=(g?g.format:null)||(y?null:m.format),v.editRange&&v.editRange.contains(n,l)?!o.isNumber(c)||m.dataMap||_||(C&&(c=this._getFormattedValue(c,C)),(p=s.querySelector("input"))&&(p.value=c)):t.columns[l].dataType===o.DataType.Boolean?(f=s.querySelector('[type="checkbox"]'))&&(f.checked=v.getCellValue(n,l),f.disabled=f.disabled||!v.canEditCell(n,l)):m.dataMap&&!y?(c=v.getCellValue(n,l,!0),(d=s.firstChild)&&3===d.nodeType&&d.nodeValue!==c&&(d.nodeValue=c)):0===s.childElementCount&&s.textContent===v.getCellData(n,l,!0)&&(""!==(c=v.getCellValue(n,l,!0))&&o.isNumber(+c)&&!isNaN(+c)&&/[hsmy\:]/i.test(C)&&(S=w._fromOADate(+c),isNaN(S.getTime())||(c=o.Globalize.formatDate(S,C))),!C&&y||(c=o.isString(c)?c.replace(/^(\')(\s*[\w|=])/,"$2"):c,o.isString(c)?c&&this._isURL(c)?s.innerHTML='<a href="'+c+'" target="_blank">'+o.escapeHtml(c)+"</a>":s.innerHTML=o.escapeHtml(c):s.innerHTML=c)),g){var T,x=s.style;for(var k in g)"className"===k?g.className&&o.addClass(s,g.className):"format"!==k&&(T=g[k])&&(!o.hasClass(s,"wj-state-selected")&&!o.hasClass(s,"wj-state-multi-selected")||"color"!==k&&"backgroundColor"!==k?x[k]="whiteSpace"===k&&"normal"===T?"":T:x[k]="")}(s.style.backgroundColor||s.style.color)&&(g||(g={},R&&R._styledCells[h]),s.style.backgroundColor&&(g.backgroundColor=s.style.backgroundColor),s.style.color&&(g.color=s.style.color))}t.cellType===i.CellType.Cell&&(n!==v._lastVisibleFrozenRow||o.hasClass(s,"wj-frozen-row")||o.addClass(s,"wj-frozen-row"),l!==v._lastVisibleFrozenColumn||o.hasClass(s,"wj-frozen-col")||o.addClass(s,"wj-frozen-col"))},t.prototype._resetCellStyle=function(e,t){["fontFamily","fontSize","fontStyle","fontWeight","textDecoration","textAlign","verticalAlign","backgroundColor","color","whiteSpace","borderLeftStyle","borderLeftColor","borderLeftWidth","borderRightStyle","borderRightColor","borderRightWidth","borderTopStyle","borderTopColor","borderTopWidth","borderBottomStyle","borderBottomColor","borderBottomWidth"].forEach(function(o){"textAlign"===o?t.style.textAlign=e.getAlignment():t.style[o]=""})},t.prototype._getFormattedValue=function(e,t){return e!==Math.round(e)&&(t=t.replace(/([a-z])(\d*)(.*)/gi,"$0112$3")),o.Globalize.formatNumber(e,t,!0)},t.prototype._getFirstVisibleCell=function(e,t){var o,n;for(o=t.topRow;o<=t.bottomRow&&!e.rows[o].isVisible;o++);for(n=t.leftCol;n<=t.rightCol&&!e.columns[n].isVisible;n++);return new i.CellRange(o,n)},t.prototype._isURL=function(e){return new RegExp("^(https|http|ftp|rtsp|mms)://(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?(([0-9]{1,3}.){3}[0-9]{1,3}|([0-9a-z_!~*'()-]+.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z].[a-z]{2,6})(:[0-9]{1,4})?(/($|[a-zA-Z0-9.,?'\\+&amp;%$#=~_-]+))*").test(e)},t}(i.CellFactory);t._FlexSheetCellFactory=P;var W=[{name:"abs",description:"Returns the absolute value of a number."},{name:"acos",description:"Returns the arccosine of a number."},{name:"and",description:"Returns TRUE if all of its arguments are TRUE."},{name:"asin",description:"Returns the arcsine of a number."},{name:"atan",description:"Returns the arctangent of a number."},{name:"atan2",description:"Returns the arctangent from x- and y-coordinates."},{name:"average",description:"Returns the average of its arguments."},{name:"ceiling",description:"Rounds a number to the nearest integer or to the nearest multiple of significance."},{name:"char",description:"Returns the character specified by the code number."},{name:"choose",description:"Chooses a value from a list of values."},{name:"code",description:"Returns a numeric code for the first character in a text string."},{name:"column",description:"Returns the column number of a reference."},{name:"columns",description:"Returns the number of columns in a reference."},{name:"concatenate",description:"Joins several text items into one text item."},{name:"cos",description:"Returns the cosine of a number."},{name:"count",description:"Counts how many numbers are in the list of arguments."},{name:"counta",description:"Counts how many values are in the list of arguments."},{name:"countblank",description:"Counts the number of blank cells within a range."},{name:"countif",description:"Counts the number of cells within a range that meet the given criteria."},{name:"countifs",description:"Counts the number of cells within a range that meet multiple criteria."},{name:"date",description:"Returns the serial number of a particular date."},{name:"datedif",description:"Calculates the number of days, months, or years between two dates."},{name:"day",description:"Converts a serial number to a day of the month."},{name:"dcount",description:"Counts the cells that contain numbers in a database."},{name:"exp",description:"Returns e raised to the power of a given number."},{name:"false",description:"Returns the logical value FALSE."},{name:"find",description:"Finds one text value within another (case-sensitive)."},{name:"floor",description:"Rounds a number down, toward zero."},{name:"hlookup",description:"Looks in the top row of an array and returns the value of the indicated cell."},{name:"hour",description:"Converts a serial number to an hour."},{name:"if",description:"Specifies a logical test to perform."},{name:"index",description:"Uses an index to choose a value from a reference."},{name:"left",description:"Returns the leftmost characters from a text value."},{name:"len",description:"Returns the number of characters in a text string."},{name:"ln",description:"Returns the natural logarithm of a number."},{name:"lower",description:"Converts text to lowercase."},{name:"max",description:"Returns the maximum value in a list of arguments."},{name:"mid",description:"Returns a specific number of characters from a text string starting at the position you specify."},{name:"min",description:"Returns the minimum value in a list of arguments."},{name:"mod",description:"Returns the remainder from division."},{name:"month",description:"Converts a serial number to a month."},{name:"not",description:"Reverses the logic of its argument."},{name:"now",description:"Returns the serial number of the current date and time."},{name:"or",description:"Returns TRUE if any argument is TRUE."},{name:"pi",description:"Returns the value of pi."},{name:"power",description:"Returns the result of a number raised to a power."},{name:"product",description:"Multiplies its arguments."},{name:"proper",description:"Capitalizes the first letter in each word of a text value."},{name:"rand",description:"Returns a random number between 0 and 1."},{name:"rank",description:"Returns the rank of a number in a list of numbers."},{name:"rate",description:"Returns the interest rate per period of an annuity."},{name:"replace",description:"Replaces characters within text."},{name:"rept",description:"Repeats text a given number of times."},{name:"right",description:"Returns the rightmost characters from a text value."},{name:"round",description:"Rounds a number to a specified number of digits."},{name:"rounddown",description:"Rounds a number down, toward zero."},{name:"roundup",description:"Rounds a number up, away from zero."},{name:"row",description:"Returns the row number of a reference."},{name:"rows",description:"Returns the number of rows in a reference."},{name:"search",description:"Finds one text value within another (not case-sensitive)."},{name:"sin",description:"Returns the sine of the given angle."},{name:"sqrt",description:"Returns a positive square root."},{name:"stdev",description:"Estimates standard deviation based on a sample."},{name:"stdevp",description:"Calculates standard deviation based on the entire population."},{name:"substitute",description:"Substitutes new text for old text in a text string."},{name:"subtotal",description:"Returns a subtotal in a list or database."},{name:"sum",description:"Adds its arguments."},{name:"sumif",description:"Adds the cells specified by a given criteria."},{name:"sumifs",description:"Adds the cells in a range that meet multiple criteria."},{name:"sumproduct",description:"Multiplies corresponding components in the given arrays, and returns the sum of those products."},{name:"tan",description:"Returns the tangent of a number."},{name:"text",description:"Formats a number and converts it to text."},{name:"time",description:"Returns the serial number of a particular time."},{name:"today",description:"Returns the serial number of today's date."},{name:"trim",description:"Removes spaces from text."},{name:"true",description:"Returns the logical value TRUE."},{name:"trunc",description:"Truncates a number to an integer."},{name:"upper",description:"Converts text to uppercase."},{name:"value",description:"Converts a text argument to a number."},{name:"var",description:"Estimates variance based on a sample."},{name:"varp",description:"Calculates variance based on the entire population."},{name:"year",description:"Converts a serial number to a year."}],O=function(e){function t(t,n){var l=e.call(this,t,n)||this;return l._selectedSheetIndex=-1,l._columnHeaderClicked=!1,l._addingSheet=!1,l._mouseMoveHdl=l._mouseMove.bind(l),l._clickHdl=l._click.bind(l),l._touchStartHdl=l._touchStart.bind(l),l._touchEndHdl=l._touchEnd.bind(l),l._isContextMenuKeyDown=!1,l._isClicking=!1,l._definedNames=new o.ObservableArray,l._builtInTableStylesCache=null,l._needCopyToSheet=!0,l._isSorting=!1,l.selectedSheetChanged=new o.Event,l.draggingRowColumn=new o.Event,l.droppingRowColumn=new o.Event,l.loaded=new o.Event,l.unknownFunction=new o.Event,l.sheetCleared=new o.Event,l.prepareChangingRow=new o.Event,l.prepareChangingColumn=new o.Event,l.rowChanged=new o.Event,l.columnChanged=new o.Event,l._needCopyToSheet=!1,l._colorThemes=["FFFFFF","000000","EEECE1","1F497D","4F818D","C0504D","9BBB59","8064A2","4BACC6","F79646"],l._eCt.style.backgroundColor="white",o.addClass(l.hostElement,"wj-flexsheet"),o.setCss(l.hostElement,{fontFamily:"Arial"}),l._cf=new P,l._bndSortConverter=l._sheetSortConverter.bind(l),l.quickAutoSize=!1,l._init(),l.showSort=!1,l.allowSorting=!1,l.showGroups=!1,l.showMarquee=!0,l.showSelectedHeaders=i.HeadersVisibility.All,l.allowResizing=i.AllowResizing.Both,l.allowDragging=i.AllowDragging.None,l._needCopyToSheet=!0,l}return __extends(t,e),t.prototype._getProductInfo=function(){return"R20I,FlexSheet"},Object.defineProperty(t.prototype,"sheets",{get:function(){return this._sheets||(this._sheets=new X,this._sheets.selectedSheetChanged.addHandler(this._selectedSheetChange,this),this._sheets.collectionChanged.addHandler(this._sourceChange,this),this._sheets.sheetVisibleChanged.addHandler(this._sheetVisibleChange,this),this._sheets.sheetCleared.addHandler(this.onSheetCleared,this)),this._sheets},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"selectedSheetIndex",{get:function(){return this._selectedSheetIndex},set:function(e){e!==this._selectedSheetIndex&&(this._showSheet(e),this._sheets.selectedIndex=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"selectedSheet",{get:function(){return this._sheets[this._selectedSheetIndex]},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isFunctionListOpen",{get:function(){return this._functionListHost&&"none"!==this._functionListHost.style.display},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isTabHolderVisible",{get:function(){return this._tabHolder.visible},set:function(e){e!==this._tabHolder.visible&&(e?(this._divContainer.style.height=this._divContainer.parentElement.clientHeight-this._tabHolder.getSheetBlanketSize()+"px",this._eFocus.removeAttribute("tabindex")):(this._divContainer.style.height=this._divContainer.parentElement.clientHeight+"px",this._eFocus.tabIndex=this._orgTabIndex),this._tabHolder.visible=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"undoStack",{get:function(){return this._undoStack},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"sortManager",{get:function(){return this._sortManager},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"filter",{get:function(){return this._filter},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"showFilterIcons",{get:function(){return!!this._filter&&this._filter.showFilterIcons},set:function(e){this._filter&&this._filter.showFilterIcons!==e&&(this._filter.showFilterIcons=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"definedNames",{get:function(){return this._definedNames},enumerable:!0,configurable:!0}),t.prototype.onSelectedSheetChanged=function(e){this.selectedSheetChanged.raise(this,e)},t.prototype.onDraggingRowColumn=function(e){this.draggingRowColumn.raise(this,e)},t.prototype.onDroppingRowColumn=function(e){this.droppingRowColumn.raise(this,new o.EventArgs)},t.prototype.onLoaded=function(e){var t=this;t._toRefresh&&(clearTimeout(t._toRefresh),t._toRefresh=null),t._toRefresh=setTimeout(function(){t._setFlexSheetToDirty(),t.invalidate()},10),t.loaded.raise(this,new o.EventArgs)},t.prototype.onUnknownFunction=function(e){this.unknownFunction.raise(this,e)},t.prototype.onSheetCleared=function(e){this.sheetCleared.raise(this,new o.EventArgs)},t.prototype.onPrepareChangingRow=function(e){this.prepareChangingRow.raise(this,e)},t.prototype.onPrepareChangingColumn=function(e){this.prepareChangingColumn.raise(this,e)},t.prototype.onRowChanged=function(e){this.rowChanged.raise(this,e)},t.prototype.onColumnChanged=function(e){this.columnChanged.raise(this,e)},t.prototype.refresh=function(t){void 0===t&&(t=!0);var o,n,i;if(this._divContainer.style.height=this._divContainer.parentElement.clientHeight-(this.isTabHolderVisible?this._tabHolder.getSheetBlanketSize():0)+"px",!this.preserveSelectedState&&this.selectedSheet&&(this.selectedSheet.selectionRanges.clear(),this.selectedSheet.selectionRanges.push(this.selection)),t&&this._clearCalcEngine(),this._lastVisibleFrozenRow=-1,this.frozenRows>0)for(var l=this.frozenRows-1;l>=0;l--)if(this.rows[l]&&this.rows[l].isVisible){this._lastVisibleFrozenRow=l;break}if(this._lastVisibleFrozenColumn=-1,this.frozenColumns>0)for(var s=this.frozenColumns-1;s>=0;s--)if(this.columns[s]&&this.columns[s].isVisible){this._lastVisibleFrozenColumn=s;break}if(this.selectedSheet){if(this.selectedSheet._freezeHiddenRowCnt>0)for(o=0;o<this.selectedSheet._freezeHiddenRowCnt;o++)(n=this.rows[o])instanceof G||(n.visible=!1);if(this.selectedSheet._freezeHiddenColumnCnt>0)for(i=0;i<this.selectedSheet._freezeHiddenColumnCnt;i++)this.columns[i].visible=!1}e.prototype.refresh.call(this,t),this._tabHolder.adjustSize()},t.prototype.setCellData=function(e,t,n,i,l){void 0===i&&(i=!1),void 0===l&&(l=!0);var s=o.isString(n)&&n.length>1&&"="===n[0];return this._clearCalcEngine(),this.cells.setCellData(e,t,n,i&&!s,l)},t.prototype.containsFocus=function(){return this.isFunctionListOpen||e.prototype.containsFocus.call(this)},t.prototype.addUnboundSheet=function(e,t,o,n,i){var l=this._addSheet(e,t,o,n,i);return 0===l.selectionRanges.length&&l.selectionRanges.push(this.selection),l},t.prototype.addBoundSheet=function(e,t,o,n){var i=this._addSheet(e,0,0,o,n);return t&&(i.itemsSource=t,this.childItemsPath&&(i.grid.childItemsPath=this.childItemsPath)),0===i.selectionRanges.length&&i.selectionRanges.push(this.selection),i},t.prototype.applyCellsStyle=function(e,t,o){void 0===o&&(o=!1);var n,i,l,s,r,a=t||[this.selection];if(this.selectedSheet){if(!e&&this._cloneStyle)return this.selectedSheet._styledCells=this._cloneObject(this._cloneStyle),this._cloneStyle=null,void this.refresh(!1);if(a){for(t||o?o&&!this._cloneStyle&&(this._cloneStyle=this._cloneObject(this.selectedSheet._styledCells)):(this.undoStack.stackSize>0&&(r=new I(this,this._cloneStyle)),this._cloneStyle=null),s=0;s<a.length;s++)for(n=(l=a[s]).topRow;n<=l.bottomRow;n++)for(i=l.leftCol;i<=l.rightCol;i++)this._applyStyleForCell(n,i,e);r&&(r.saveNewState(),this._undoStack._addAction(r))}t||this.refresh(!1)}},t.prototype.freezeAtCursor=function(){var e,t,o,n,i,l=this;if(l.selectedSheet){if(l.selection&&0===l.frozenRows&&0===l.frozenColumns){if(l._ptScrl.y<0)for(e=0;e<l.selection.topRow-1;e++)if(!((i=l.rows[e])instanceof G)){if(!(i._pos+l._ptScrl.y<0)){l.selectedSheet._freezeHiddenRowCnt=e;break}i.visible=!1}if(l._ptScrl.x<0)for(t=0;t<l.selection.leftCol-1;t++){if(!(l.columns[t]._pos+l._ptScrl.x<0)){l.selectedSheet._freezeHiddenColumnCnt=t;break}l.columns[t].visible=!1}o=l.selection.leftCol>0?l.selection.leftCol:0,n=l.selection.topRow>0?l.selection.topRow:0}else{for(e=0;e<l.frozenRows-1;e++)l.rows[e].visible=!0;for(t=0;t<l.frozenColumns-1;t++)l.columns[t].visible=!0;l._filter.apply(),o=0,n=0,l.selectedSheet._freezeHiddenRowCnt=0,l.selectedSheet._freezeHiddenColumnCnt=0}l.frozenRows=l.selectedSheet.grid.frozenRows=n,l.frozenColumns=l.selectedSheet.grid.frozenColumns=o,setTimeout(function(){l._setFlexSheetToDirty(),l.invalidate(),l.scrollIntoView(l.selection.topRow,l.selection.leftCol)},10)}},t.prototype.showColumnFilter=function(){var e=this.selection.col>0?this.selection.col:0;this.columns.length>0&&this._filter.editColumnFilter(this.columns[e])},t.prototype.clear=function(){this.beginUpdate(),this.selection=new i.CellRange,this.sheets.clear(),this._selectedSheetIndex=-1,this.columns.clear(),this.rows.clear(),this.columnHeaders.columns.clear(),this.rowHeaders.rows.clear(),this._undoStack.clear(),this._ptScrl=new o.Point,this._clearCalcEngine(),this._definedNames.clear(),this._builtInTableStylesCache=null,this.addUnboundSheet(),this.endUpdate()},t.prototype.getSelectionFormatState=function(){var e,t,o=this.rows.length,n=this.columns.length,i={isBold:!1,isItalic:!1,isUnderline:!1,textAlign:"left",isMergedCell:!1};if(0===o||0===n)return i;if(this.selection){if(this.selection.row>=o||this.selection.row2>=o||this.selection.col>=n||this.selection.col2>=n)return i;for(e=this.selection.topRow;e<=this.selection.bottomRow;e++)for(t=this.selection.leftCol;t<=this.selection.rightCol;t++)this._checkCellFormat(e,t,i)}return i},t.prototype.insertRows=function(e,t){var n,l,s,r,a,h,d=o.isNumber(e)&&e>=0?e:this.selection&&this.selection.topRow>-1?this.selection.topRow:0,c=o.isNumber(t)?t:1,u=this.rows[d],_=!1;if(this.selectedSheet){if(this.rows.length>0?d>=this.rows.length&&(d=this.rows.length-1):d=0,this._clearCalcEngine(),this.finishEditing(),0===d&&u&&u.constructor===G&&(d=1),this.onPrepareChangingRow(new U(d,c,!0)),this.undoStack.stackSize>0&&(n=new k(this,d,c,!0)),this._updateCellsForUpdatingRow(this.rows.length,d,c),(!this.collectionView||0===this.collectionView.sortDescriptions.length)&&(l=this._updateAffectedFormula(d,c,!0,!0),s=this._updateAffectedNamedRanges(d,c,!0,!0)),n&&(n._affectedFormulas=l,n._affectedDefinedNameVals=s),this.collectionView){for(_=!0,a=this.itemsSource instanceof o.CollectionView,this.collectionView.beginUpdate(),r=0;r<c;r++)a?(h=this.itemsSource.newItemCreator?this.itemsSource.newItemCreator():{},this.itemsSource.sourceCollection.splice(d-(this.allowAddNew&&this.newRowAtTop?2:1),0,h)):(this.selectedSheet.grid.collectionView.beginUpdate(),h={},this.itemsSource.splice(d-(this.allowAddNew&&this.newRowAtTop?2:1),0,h),this.itemsSource!==this.selectedSheet.grid.itemsSource&&this.selectedSheet.grid.itemsSource.splice(d-(this.allowAddNew&&this.newRowAtTop?2:1),0,h)),this.selectedSheet._orgItemsSource&&this.selectedSheet._orgItemsSource.splice(d-(this.allowAddNew&&this.newRowAtTop?2:1),0,h);a||this.selectedSheet.grid.collectionView.endUpdate(),this.collectionView.endUpdate()}else{for(this.rows.beginUpdate(),r=0;r<c;r++)this.rows.insert(d,new i.Row);this.rows.endUpdate()}this._updateTablesForUpdatingRow(d,c),this.selection&&-1!==this.selection.row&&-1!==this.selection.col||(this.selection=new i.CellRange(0,0)),n&&(n.saveNewState(),this._undoStack._addAction(n)),this.onRowChanged(new U(d,c,!0)),_&&this.refresh()}},t.prototype.deleteRows=function(e,t){var n,l,s,r,a,h,d,c,u,_=o.isNumber(t)&&t>=0?t:this.selection&&this.selection.topRow>-1?this.selection.bottomRow-this.selection.topRow+1:1,g=o.isNumber(e)&&e>=0?e:this.selection&&this.selection.topRow>-1?this.selection.topRow:-1,f=o.isNumber(e)&&e>=0?e+_-1:this.selection&&this.selection.topRow>-1?this.selection.bottomRow:-1,p=!1;if(this.selectedSheet&&!(g>=this.rows.length)&&(f=Math.min(f,this.rows.length-1),this._clearCalcEngine(),this.finishEditing(),g>-1&&f>-1)){for(this.onPrepareChangingRow(new U(g,_,!1)),this.undoStack.stackSize>0&&(n=new k(this,g,_,!1)),this._updateCellsForUpdatingRow(this.rows.length,g,_,!0),l=this._updateAffectedFormula(f,f-g+1,!1,!0),s=this._updateAffectedNamedRanges(f,f-g+1,!1,!0),r=this._updateTablesForUpdatingRow(g,_,!0),n&&(n._affectedFormulas=l,n._affectedDefinedNameVals=s,n._deletedTables=r),u=!!this.collectionView&&this.itemsSource instanceof o.CollectionView,this.rows.beginUpdate();f>=g;f--)(!(a=this.rows[f])||a.constructor!==G&&a.isVisible)&&(a.dataItem&&this.collectionView?(p=!0,this.collectionView.beginUpdate(),(h=this._getCvIndex(f))>-1&&(d=this.collectionView.items[h],u?this.itemsSource.sourceCollection.splice(this.itemsSource.sourceCollection.indexOf(d),1):(this.selectedSheet.grid.collectionView.beginUpdate(),this.itemsSource.splice(this.itemsSource.indexOf(d),1),this.itemsSource!==this.selectedSheet.grid.itemsSource&&this.selectedSheet.grid.itemsSource.splice(this.itemsSource.indexOf(d),1)),this.selectedSheet._orgItemsSource&&this.selectedSheet._orgItemsSource.splice(this.selectedSheet._orgItemsSource.indexOf(d),1)),u||this.selectedSheet.grid.collectionView.endUpdate(),this.collectionView.endUpdate()):this.rows.removeAt(f));this.rows.endUpdate(),c=this.rows.length,this.selectedSheet.selectionRanges.clear(),0===c?(this.select(new i.CellRange),"move"===this.hostElement.style.cursor&&(this.hostElement.style.cursor="default")):f===c-1?this.select(new i.CellRange(f,0,f,this.columns.length-1)):this.select(new i.CellRange(this.selection.topRow,this.selection.col,this.selection.topRow,this.selection.col2)),n&&(n.saveNewState(),this._undoStack._addAction(n)),this.onRowChanged(new U(g,_,!1)),p&&this.refresh()}},t.prototype.insertColumns=function(e,t){var n,l,s,r,a,h,d=o.isNumber(e)&&e>=0?e:this.selection&&this.selection.leftCol>-1?this.selection.leftCol:0,c=o.isNumber(t)?t:1;if(this.selectedSheet){for(this.columns.length>0?d>=this.columns.length&&(d=this.columns.length-1):d=0,this._clearCalcEngine(),this.finishEditing(),this.onPrepareChangingColumn(new U(d,c,!0)),this.undoStack.stackSize>0&&(n=new x(this,d,c,!0)),this._updateCellsForUpdatingColumn(this.columns.length,d,c),a=this._updateAffectedFormula(d,c,!0,!1),h=this._updateAffectedNamedRanges(d,c,!0,!1),n&&(n._affectedFormulas=a,n._affectedDefinedNameVals=h),this.columns.beginUpdate(),s=0;s<c;s++)(l=new i.Column).isRequired=!1,this.itemsSource&&(l.binding=this._getUniqueColumnName(),(r=this.allowAddNew&&this.newRowAtTop?this.rows[1]:this.rows[0])&&(r._ubv||(r._ubv={}),r._ubv[l._hash]=l.header)),this.columns.insert(d,l);this.columns.endUpdate(),this._sortManager._updateSortSortDescription(d,c),this._sortManager.commitSort(!1),this._updateTablesForUpdatingColumn(d,c),this.selection&&-1!==this.selection.row&&-1!==this.selection.col||(this.selection=new i.CellRange(0,0)),n&&(n.saveNewState(),this._undoStack._addAction(n)),this.onColumnChanged(new U(d,c,!0))}},t.prototype.deleteColumns=function(e,t){var n,l,s,r,a,h=o.isNumber(t)&&t>=0?t:this.selection&&this.selection.leftCol>-1?this.selection.rightCol-this.selection.leftCol+1:1,d=o.isNumber(e)&&e>=0?e:this.selection&&this.selection.leftCol>-1?this.selection.leftCol:-1,c=o.isNumber(e)&&e>=0?e+h-1:this.selection&&this.selection.leftCol>-1?this.selection.rightCol:-1;if(this.selectedSheet&&!(d>=this.columns.length)&&(c=Math.min(c,this.columns.length-1),this._clearCalcEngine(),this.finishEditing(),d>-1&&c>-1)){for(this.onPrepareChangingColumn(new U(d,h,!1)),this.undoStack.stackSize>0&&(l=new x(this,d,h,!1)),this._updateCellsForUpdatingColumn(this.columns.length,d,h,!0),s=this._updateAffectedFormula(c,c-d+1,!1,!1),r=this._updateAffectedNamedRanges(c,c-d+1,!1,!1),a=this._updateTablesForUpdatingColumn(d,h,!0),l&&(l._affectedFormulas=s,l._affectedDefinedNameVals=r,l._deletedTables=a),this.columns.beginUpdate();c>=d;c--)this.columns[c].isVisible&&(this.columns.removeAt(c),this._sortManager.deleteSortLevel(c));this.columns.endUpdate(),this._sortManager._updateSortSortDescription(d,h,!1),this._sortManager.commitSort(!1),n=this.columns.length,this.selectedSheet.selectionRanges.clear(),0===n?(this.select(new i.CellRange),"move"===this.hostElement.style.cursor&&(this.hostElement.style.cursor="default")):c===n-1?this.select(new i.CellRange(0,c,this.rows.length-1,c)):this.select(new i.CellRange(this.selection.row,this.selection.leftCol,this.selection.row2,this.selection.leftCol)),l&&(l.saveNewState(),this._undoStack._addAction(l)),this.onColumnChanged(new U(d,h,!1))}},t.prototype.mergeRange=function(e,t){void 0===t&&(t=!1);var o,n,l,s=e||this.selection,r=-1,a=-1;if(this.selectedSheet){if(s){if(1===s.rowSpan&&1===s.columnSpan)return;for(o=s.topRow;o<=s.bottomRow;o++)for(n=s.leftCol;n<=s.rightCol;n++)if(this.selectedSheet.findTable(o,n))return;if(e||t||(this.undoStack.stackSize>0&&(l=new E(this)),this.hostElement.focus()),!this._resetMergedRange(s)){for(o=s.topRow;o<=s.bottomRow;o++)if(this.rows[o].isVisible){r=o;break}for(n=s.leftCol;n<=s.rightCol;n++)if(this.columns[n].isVisible){a=n;break}r>-1&&a>-1&&this.selectedSheet._mergedRanges.push(new i.CellRange(r,a,s.bottomRow,s.rightCol))}l&&(l.saveNewState(),this._undoStack._addAction(l))}e||this.refresh()}},t.prototype.getMergedRange=function(t,o,n,l){void 0===l&&(l=!0);var s,r,a,h,d=this.selectedSheet?this.selectedSheet._getMergedRange(o,n):null;return t===this.cells&&d?!d.isSingleCell&&(this.frozenRows>0||this.frozenColumns>0)&&(d.topRow<this.frozenRows&&d.bottomRow>=this.frozenRows||d.leftCol<this.frozenColumns&&d.rightCol>=this.frozenColumns)?(s=d.topRow,r=d.bottomRow,a=d.leftCol,h=d.rightCol,o>=this.frozenRows&&d.topRow<this.frozenRows&&(s=this.frozenRows),o<this.frozenRows&&d.bottomRow>=this.frozenRows&&(r=this.frozenRows-1),r>=this.rows.length&&(r=this.rows.length-1),n>=this.frozenColumns&&d.leftCol<this.frozenColumns&&(a=this.frozenColumns),n<this.frozenColumns&&d.rightCol>=this.frozenColumns&&(h=this.frozenColumns-1),h>=this.columns.length&&(h=this.columns.length-1),new i.CellRange(s,a,r,h)):d.bottomRow>=this.rows.length?new i.CellRange(d.topRow,d.leftCol,this.rows.length-1,d.rightCol):d.rightCol>=this.columns.length?new i.CellRange(d.topRow,d.leftCol,d.bottomRow,this.columns.length-1):d.clone():n>=0&&this.columns&&this.columns.length>n&&o>=0&&this.rows&&this.rows.length>o?e.prototype.getMergedRange.call(this,t,o,n,l):null},t.prototype.evaluate=function(e,t,n,i){void 0===i&&(i=!0);var l=this._evaluate(e,t,n);return i&&null!=l&&!o.isPrimitive(l)?l.value:l},t.prototype.getCellValue=function(e,t,n,i){void 0===n&&(n=!1);var l,s,r=i&&i!==this.selectedSheet?i.grid.columns[t]:this.columns[t],a=this._getCellStyle(e,t,i);return l=a&&a.format?a.format:"",s=i&&i!==this.selectedSheet?i.grid.getCellData(e,t,!1):this.getCellData(e,t,!1),o.isString(s)&&"="===s[0]&&(s=this._evaluate(s,n?l:"",i,e,t)),n?(l||null==s||o.isPrimitive(s)||(a?a.format=s.format:this._applyStyleForCell(e,t,{format:s.format})),s=this._formatEvaluatedResult(s,r,l)):null==s||o.isPrimitive(s)||(s=s.value),null==s?"":s},t.prototype.showFunctionList=function(e){var t,n,i=this,l=i._cumulativeOffset(e),s=i._cumulativeOffset(i._root);i._functionTarget=o.tryCast(e,HTMLInputElement),i._functionTarget&&i._functionTarget.value&&"="===i._functionTarget.value[0]?(i._functionList._cv.filter=function(e){var t,o=e.actualvalue.toLowerCase(),n=i._getCurrentFormulaIndex(i._functionTarget.value);return-1===n&&(n=0),(t=i._functionTarget.value.substr(n+1).trim().toLowerCase()).length>0&&0===o.indexOf(t)||"="===i._functionTarget.value},i._functionList.selectedIndex=0,t=l.y+e.clientHeight+2+(o.hasClass(e,"wj-grid-editor")?this._ptScrl.y:0),n=l.x+(o.hasClass(e,"wj-grid-editor")?this._ptScrl.x:0),o.setCss(i._functionListHost,{height:i._functionList._cv.items.length>5?"218px":"auto",display:i._functionList._cv.items.length>0?"block":"none",top:"",left:""}),i._functionListHost.scrollTop=0,i._functionListHost.offsetHeight+t>s.y+i._root.offsetHeight?t=t-e.clientHeight-i._functionListHost.offsetHeight-5:t+=5,i._functionListHost.offsetWidth+n>s.x+i._root.offsetWidth&&(n=s.x+i._root.offsetWidth-i._functionListHost.offsetWidth),o.setCss(i._functionListHost,{top:t,left:n})):i.hideFunctionList()},t.prototype.hideFunctionList=function(){this._functionListHost.style.display="none"},t.prototype.selectPreviousFunction=function(){this._functionList.selectedIndex>0&&this._functionList.selectedIndex--},t.prototype.selectNextFunction=function(){this._functionList.selectedIndex<this._functionList.itemsSource.length&&this._functionList.selectedIndex++},t.prototype.applyFunctionToCell=function(){var e,t=this;t._functionTarget&&(-1===(e=t._getCurrentFormulaIndex(t._functionTarget.value))?e=t._functionTarget.value.indexOf("="):e+=1,t._functionTarget.value=t._functionTarget.value.substring(0,e)+t._functionList.selectedValue+"(","="!==t._functionTarget.value[0]&&(t._functionTarget.value="="+t._functionTarget.value),t._functionTarget.focus(),t.hideFunctionList())},t.prototype.save=function(e){var t=this._saveToWorkbook();return e&&t.save(e),t},t.prototype.saveAsync=function(e,t,o){var n=this._saveToWorkbook();return n.saveAsync(e,t,o),n},t.prototype.saveToWorkbookOM=function(){return this._saveToWorkbook()._serialize()},t.prototype.load=function(e){var t,i,l=this;if(e instanceof Blob)(i=new FileReader).onload=function(){var e=i.result;e=n.Workbook._base64EncArr(new Uint8Array(e)),(t=new n.Workbook).load(e),l._loadFromWorkbook(t)},i.readAsArrayBuffer(e);else if(e instanceof n.Workbook)l._loadFromWorkbook(e);else{if(e instanceof ArrayBuffer)e=n.Workbook._base64EncArr(new Uint8Array(e));else if(!o.isString(e))throw"Invalid workbook.";(t=new n.Workbook).load(e),l._loadFromWorkbook(t)}},t.prototype.loadAsync=function(e,t,i){var l,s,r=this;if(e instanceof Blob)(s=new FileReader).onload=function(){var e=s.result;e=n.Workbook._base64EncArr(new Uint8Array(e)),(l=new n.Workbook).loadAsync(e,function(e){r._loadFromWorkbook(e),t&&t(e)},i)},s.readAsArrayBuffer(e);else if(e instanceof n.Workbook)r._loadFromWorkbook(e),t&&t(e);else{if(e instanceof ArrayBuffer)e=n.Workbook._base64EncArr(new Uint8Array(e));else if(!o.isString(e))throw"Invalid workbook.";(l=new n.Workbook).loadAsync(e,function(e){r._loadFromWorkbook(e),t&&t(e)},i)}},t.prototype.loadFromWorkbookOM=function(e){var t;e instanceof n.Workbook?t=e:(t=new n.Workbook)._deserialize(e),this._loadFromWorkbook(t)},t.prototype.undo=function(){var e=this;setTimeout(function(){e._undoStack.undo()},100)},t.prototype.redo=function(){var e=this;setTimeout(function(){e._undoStack.redo()},100)},t.prototype.select=function(t,n){void 0===n&&(n=!0);var l,s,r;if(o.isNumber(t)&&o.isNumber(n)&&(t=new i.CellRange(t,n),n=!0),t.rowSpan!==this.rows.length&&t.columnSpan!==this.columns.length)for(s=t.topRow;s<=t.bottomRow;s++)for(r=t.leftCol;r<=t.rightCol;r++)(l=this.getMergedRange(this.cells,s,r))&&!t.equals(l)&&(t.row<=t.row2?(t.row=Math.min(t.topRow,l.topRow),t.row2=Math.max(t.bottomRow,l.bottomRow)):(t.row=Math.max(t.bottomRow,l.bottomRow),t.row2=Math.min(t.topRow,l.topRow)),t.col<=t.col2?(t.col=Math.min(t.leftCol,l.leftCol),t.col2=Math.max(t.rightCol,l.rightCol)):(t.col=Math.max(t.rightCol,l.rightCol),t.col2=Math.min(t.leftCol,l.leftCol)));this._isPasting&&this.collectionView&&(this.collectionView._pendingRefresh=!1),e.prototype.select.call(this,t,n)},t.prototype.addCustomFunction=function(e,t,n,i,l){o._deprecated("addCustomFunction","addFunction"),this._calcEngine.addCustomFunction(e,t,i,l),this._addCustomFunctionDescription(e,n)},t.prototype.addFunction=function(e,t,o,n,i){this._calcEngine.addFunction(e,t,n,i),this._addCustomFunctionDescription(e,o)},t.prototype.dispose=function(){var t=window.navigator.userAgent;this._needCopyToSheet=!1,document.removeEventListener("mousemove",this._mouseMoveHdl),document.body.removeEventListener("click",this._clickHdl),(t.match(/iPad/i)||t.match(/iPhone/i))&&(document.body.removeEventListener("touchstart",this._touchStartHdl),document.body.removeEventListener("touchend",this._touchEndHdl)),this.hideFunctionList(),e.prototype.dispose.call(this)},t.prototype.getClipString=function(t){var n,l,s,r,a,h,d="",c=!0;if(!this.selectedSheet)return e.prototype.getClipString.call(this,t);if(this._isCutting=!1,!t)if(this.selectedSheet.selectionRanges.length>1){if(this._isMultipleRowsSelected()){for(d="",0===(n=this.selectedSheet.selectionRanges.slice(0)).length&&(n=[this.selection]),n.sort(this._sortByRow),s=0;s<n.length;s++)d&&(d+="\n"),d+=this.getClipString(n[s]);return d}if(this._isMultipleColumnsSelected()){for(d="",0===(n=this.selectedSheet.selectionRanges.slice(0)).length&&(n=[this.selection]),n.sort(this._sortByColumn),l=(r=n[0]).topRow,c=!0;l<=r.bottomRow;l++)for(c||(d+="\n"),c=!1,s=0,f=!0;s<n.length;s++)a=n[s],f||(d+="\t"),f=!1,d+=this.getClipString(new i.CellRange(l,a.col,l,a.col2));return d}o.assert(!1,"Copy or Cut operation cannot be used on multiple selections.")}else switch(t=this.selection,this.selectionMode){case i.SelectionMode.Row:case i.SelectionMode.RowRange:t.col=0,t.col2=this.columns.length-1;break;case i.SelectionMode.ListBox:t.col=0,t.col2=this.columns.length-1;for(var u=0;u<this.rows.length;u++)this.rows[u].isSelected&&this.rows[u].isVisible&&(t.row=t.row2=u,d&&(d+="\n"),d+=this.getClipString(t));return d}if(!(t=o.asType(t,i.CellRange)).isValid)return"";for(var _=t.topRow,c=!0;_<=t.bottomRow;_++)if(this.rows[_].isVisible){c||(d+="\n"),c=!1;for(var g=t.leftCol,f=!0;g<=t.rightCol;g++)this.columns[g].isVisible&&(f||(d+="\t"),f=!1,(h=(h=this.getCellValue(_,g,!0).toString()).replace(/\t/g," ")).indexOf("\n")>-1&&(h='"'+h.replace(/"/g,'""')+'"'),d+=h)}return d},t.prototype.setClipString=function(t,n){var l,s,r,a,h,d,c,u,_,g,f,p,w,m,C,b,y,S,R,v,T,x,k,I=null==n,E=!1,D=!1;if(this.selectedSheet){if(n=n?o.asType(n,i.CellRange):this.selection,(t=o.asString(t).replace(/\r\n/g,"\n").replace(/\r/g,"\n"))&&"\n"==t[t.length-1]&&(t=t.substring(0,t.length-1)),T=t,u=this._edtHdl._parseClipString(o.asString(t)),I&&!n.isSingleCell&&u.length&&this._edtHdl._expandClipRows(u,n),D=this._containsMultiLineText(u),(!this._copiedRanges||0===this._copiedRanges.length||T.trim()!==this._getRangeString(this._copiedRanges,this._copiedSheet).trim()&&!this._containsRandFormula(this._copiedRanges,this._copiedSheet)||this._cutValue)&&!D)return T!==this._cutValue&&(this._cutValue=null,e.prototype.setClipString.call(this,t)),this._copiedRanges=null,void(this._copiedSheet=null);if(x=this._getRangeString(this._copiedRanges,this._copiedSheet,!1),(x=o.asString(x).replace(/\r\n/g,"\n").replace(/\r/g,"\n"))&&"\n"==x[x.length-1]&&(x=x.substring(0,x.length-1)),u=this._edtHdl._parseClipString(o.asString(x)),I&&!n.isSingleCell&&u.length&&this._edtHdl._expandClipRows(u,n),(a=n.topRow+u.length-1)>=this.rows.length&&(a=this.rows.length-1),(h=n.leftCol+u[0].length-1)>=this.columns.length&&(h=this.columns.length-1),l=new i.CellRange(n.topRow,n.leftCol,a,h),!this.onPasting(new i.CellRangeEventArgs(this.cells,l)))return this._cutValue=null,this._copiedRanges=null,this._copiedSheet=null,!1;if(this.beginUpdate(),D||!this._copiedRanges||this._copiedRanges.length>1||0===this._copiedRanges.length)for(s=n.topRow,d=(S=this._copiedRanges&&this._copiedRanges.length>1?this._copiedRanges[0]:new i.CellRange).topRow,f=0;f<u.length&&s<this.rows.length;f++,s++)if(this.rows[s].isVisible){for(_=u[f],c=S.leftCol,m=(r=n.leftCol)-c,p=0;p<_.length&&r<this.columns.length;p++,r++)this.columns[r].isVisible?(g=_[p],this.columns[r].isReadOnly||this.rows[s].isReadOnly||(E=this._postSetClipStringProcess(g,s,r,d,c),l.row2=Math.max(l.row2,s),l.col2=Math.max(l.col2,r)),c>=0&&c++):p--;d>=0&&d++}else f--;else if(this._copiedRanges&&1===this._copiedRanges.length)for(R=0,(S=this.selectionMode===i.SelectionMode.ListBox?this._getSelectionForListBoxMode(this._copiedSheet.grid):this._copiedRanges[0]).rowSpan>n.rowSpan?S.rowSpan:n.rowSpan,S.columnSpan>n.columnSpan?S.columnSpan:n.columnSpan,s=n.topRow,f=0;f<u.length&&s<this.rows.length;f++,s++)if(v=0,this.rows[s].isVisible){for(;this._copiedSheet.grid.rows[S.topRow+R]&&!this._copiedSheet.grid.rows[S.topRow+R].isVisible;)R++;if(R>=S.rowSpan&&(R%=S.rowSpan),!this._copiedSheet.grid.rows[S.topRow+R])break;for(w=s-S.topRow-R,_=u[f],r=n.leftCol,p=0;p<_.length&&r<this.columns.length;p++,r++)if(this.columns[r]&&this.columns[r].isVisible){if(v>=S.columnSpan&&(v%=S.columnSpan),!this._copiedSheet.grid.columns[S.leftCol+v])break;if(m=r-S.leftCol-v,!this.columns[r].isReadOnly&&!this.rows[s].isReadOnly){if(null!=this._copiedSheet.grid.columns[S.leftCol+v].dataMap,g=_[p],k=this._getCellStyle(S.topRow+R,S.leftCol+v,this._copiedSheet),g&&"string"==typeof g&&"="===g[0]&&(0!==w||0!==m))try{C=this._calcEngine._parse(g),b=new i.CellRange(S.topRow+R,S.leftCol+v),y=new i.CellRange(S.topRow+R+w,S.leftCol+v+m),C._moveCellRangeExp(this.selectedSheetIndex,b,y,!1,!0)&&(g="="+C._getStringExpression())}catch(e){}this._copiedSheet.grid.columns[S.leftCol+v].format&&(k?k.format||(k.format=this._copiedSheet.grid.columns[S.leftCol+v].format):k={format:this._copiedSheet.grid.columns[S.leftCol+v].format}),E=this._postSetClipStringProcess(g,s,r,S.topRow+R,S.leftCol+v,k),l.row2=Math.max(l.row2,s),l.col2=Math.max(l.col2,r)}v++}else p--;R++}else f--;this._isCutting&&(this._delCutData(u.length,u[0].length),this._isCutting=!1,this._cutValue=T,this._copiedRanges=null,this._copiedSheet=null),this.endUpdate(),this.collectionView&&E&&this.collectionView.refresh(),this.select(l),this.onPasted(new i.CellRangeEventArgs(this.cells,l))}else e.prototype.setClipString.call(this,t,n)},t.prototype.getBuiltInTableStyle=function(e){var t;return null==this._builtInTableStylesCache&&(this._builtInTableStylesCache={}),null==(t=this._builtInTableStylesCache[e.toLowerCase()])&&(t=this._createBuiltInTableStyle(e),Object.freeze(t),this._builtInTableStylesCache[e.toLowerCase()]=t),t},t.prototype._getCvIndex=function(t){return t>-1&&this.collectionView?this.rows[t]instanceof G?t:e.prototype._getCvIndex.call(this,t):-1},t.prototype._init=function(){var e=this,t=this,n=window.navigator.userAgent,l=function(e){document.removeEventListener("mouseup",l),t._mouseUp(e)};t.hostElement.setAttribute("tabindex","-1"),t._divContainer=t.hostElement.querySelector('[wj-part="container"]'),t._tabHolder=new H(t.hostElement.querySelector('[wj-part="tab-holder"]'),t),t._contextMenu=new L(t.hostElement.querySelector('[wj-part="context-menu"]'),t),t._gpCells=new z(t,i.CellType.Cell,t.rows,t.columns,t._eCt),t._gpCHdr=new z(t,i.CellType.ColumnHeader,t._hdrRows,t.columns,t._eCHdrCt),t._gpRHdr=new z(t,i.CellType.RowHeader,t.rows,t._hdrCols,t._eRHdrCt),t._gpTL=new z(t,i.CellType.TopLeft,t._hdrRows,t._hdrCols,t._eTLCt),t._sortManager=new Q(t),t._filter=new he(t),t._filter.filterApplied.addHandler(function(){t.selectedSheet&&(t.selectedSheet._filterDefinition=t._filter.filterDefinition,t.selectedSheet.itemsSource&&(t.selectedSheet._storeRowSettings(),t.selectedSheet._setRowSettings()))}),t._calcEngine=new d(t),t._calcEngine.unknownFunction.addHandler(function(e,o){t.onUnknownFunction(o)},t),t._initFuncsList(),t._undoStack=new Z(t),t.loadedRows.addHandler(function(){if(t.itemsSource&&!(t.rows[0]instanceof G)){for(var e,o=new G,n=0;n<t.columns.length;n++)e=t.columns[n],o._ubv||(o._ubv={}),o._ubv[e._hash]=e.header;t.rows[0]instanceof i._NewRowTemplate&&t.newRowAtTop?t.rows.insert(1,o):t.rows.insert(0,o)}t._filter&&t._filter.apply()}),t.itemsSourceChanged.addHandler(function(){var o;for(o=0;o<t.columns.length;o++)t.columns[o].isRequired=!1;t.collectionView&&t.collectionView.currentChanged.removeHandler(e._cvCurrentChanged,e)}),t.copied.addHandler(function(e,n){var i;t.selectedSheet&&(t._copiedSheet=t.selectedSheet,t._needCopyToSheet=!0,t.selectedSheet.selectionRanges.length>1?t._isMultipleRowsSelected()?((i=t.selectedSheet.selectionRanges.slice(0)).sort(t._sortByRow),t._copiedRanges=i):t._isMultipleColumnsSelected()?((i=t.selectedSheet.selectionRanges.slice(0)).sort(t._sortByColumn),t._copiedRanges=i):o.assert(!1,"Copy operation cannot be used on multiple selections."):t._copiedRanges=[n.range])}),t.rows.collectionChanged.addHandler(function(e,o){t._clearForEmptySheet("rows"),t.itemsSource||!t.selectedSheet||!t._needCopyToSheet||t._isCopying||t._isUndoing||o.item instanceof i._NewRowTemplate||t._copyRowsToSelectedSheet()},t),t.columns.collectionChanged.addHandler(function(e,o){t._clearForEmptySheet("columns"),t.selectedSheet&&t._needCopyToSheet&&!t._isCopying&&!t._isUndoing&&t._copyColumnsToSelectedSheet()},t),t.definedNames.collectionChanged.addHandler(function(e,n){if(n.action===o.NotifyCollectionChangedAction.Add||n.action===o.NotifyCollectionChangedAction.Change){var i=n.action===o.NotifyCollectionChangedAction.Add?"inserted":"updated";if(!(n.item instanceof q))throw t.definedNames.remove(n.item),"Invalid defined name item object was "+i+".  The DefinedName instance should be "+i+" in the definedNames array.";if(!n.item||!n.item.name||null==n.item.value)throw t.definedNames.remove(n.item),"Invalid defined name was "+i+".";if(null!=n.item.sheetName&&!t._validateSheetName(n.item.sheetName))throw t.definedNames.remove(n.item),"The sheet name ("+n.item.sheetName+") does not exist in FlexSheet.";if(t._checkExistDefinedName(n.item.name,n.item.sheetName,n.index))throw t.definedNames.remove(n.item),"The "+n.item.name+" already existed in definedNames."}}),t.addEventListener(t.hostElement,"mousedown",function(e){document.addEventListener("mouseup",l),t._isDescendant(t._divContainer,e.target)&&t._mouseDown(e)},!0),t.addEventListener(t.hostElement,"drop",function(){t._columnHeaderClicked=!1}),t.addEventListener(t.hostElement,"contextmenu",function(e){var n,l,s,r,a,h,d,c,u;!e.defaultPrevented&&t.selectedSheet&&(t.activeEditor||(t._isContextMenuKeyDown&&t.selection.row>-1&&t.selection.col>-1&&t.rows.length>0&&t.columns.length>0?(s=t.columns[t.selection.col],l=t.rows[t.selection.row],d=t._cumulativeOffset(t.hostElement),c=t._cumulativeScrollOffset(t.hostElement),r=s.pos+t._eCt.offsetLeft+d.x+s.renderSize/2+t._ptScrl.x,a=l.pos+t._eCt.offsetTop+d.y+l.renderSize/2+t._ptScrl.y,h=new o.Point(r-c.x,a-c.y),n=t.hitTest(r,a),t._isContextMenuKeyDown=!1):n=t.hitTest(e),e.preventDefault(),n&&n.cellType!==i.CellType.None&&(n.cellType===i.CellType.TopLeft?u=new i.CellRange(0,0,t.rows.length-1,t.columns.length-1):n.cellType===i.CellType.Cell&&(u=new i.CellRange(n.row,n.col)).intersects(t.selection)&&(u=null),u&&(t.selection=u,t.selectedSheet&&(t.selectedSheet.selectionRanges.clear(),t.selectedSheet.selectionRanges.push(u))),t._contextMenu.show(e,h))))}),t.prepareCellForEdit.addHandler(t._prepareCellForEditHandler,t),t.cellEditEnded.addHandler(function(e,o){(!o.data||46!==o.data.keyCode&&8!==o.data.keyCode)&&setTimeout(function(){t.hideFunctionList()},200)}),t.cellEditEnding.addHandler(function(e,o){(!o.data||46!==o.data.keyCode&&8!==o.data.keyCode)&&t._clearCalcEngine()}),t.pasting.addHandler(function(){t._needCopyToSheet=!1,t._isPasting=!0}),t.pasted.addHandler(function(){t.selection;t._needCopyToSheet=!0,t._isPasting=!1,t._clearCalcEngine()}),t.resizingColumn.addHandler(function(){t._resizing=!0}),t.resizingRow.addHandler(function(){t._resizing=!0}),t.resizedColumn.addHandler(function(){t._resizing=!1}),t.resizedRow.addHandler(function(){t._resizing=!1}),t.selectionChanged.addHandler(function(){var e=t.selection;t._isCopying||!e.isValid||t.containsFocus()||t.hostElement.focus(),e.rightCol>=t.columns.length&&(t.selection=new i.CellRange(e.row,Math.min(e.col,t.columns.length-1),e.row2,Math.min(t.selection.col2,t.columns.length-1))),t._enableMulSel||t._isCopying||!t.selectedSheet||t.selectedSheet.selectionRanges.clear()}),t.addEventListener(t.hostElement,"keydown",function(e){var n,l,s=!1,r=!1;if(e.ctrlKey){if(89===e.keyCode&&(t.finishEditing(),t.redo(),e.preventDefault()),90===e.keyCode&&(t.finishEditing(),t.undo(),e.preventDefault()),t.selectedSheet&&65===e.keyCode&&(t.selectedSheet.selectionRanges.clear(),t.selectedSheet.selectionRanges.push(t.selection)),67!==e.keyCode&&45!=e.keyCode||(t.activeEditor&&(t._copiedRanges=null,t._copiedSheet=null),t._cutValue=null),88===e.keyCode&&!t.activeEditor){if(e.stopPropagation(),t.selectionMode===i.SelectionMode.ListBox)for(var a=0;a<t.rows.length;a++)if(t.rows[a].isSelected)if(s){if(r)continue;o.assert(!1,"Cut operation cannot be used on multiple selections.")}else s=!0,r=!0;else r&&(r=!1);t.selectedSheet.selectionRanges.length>0&&(1===t.selectedSheet.selectionRanges.length?(t.finishEditing(),n=new i.CellRangeEventArgs(t.cells,t.selection),t.onCopying(n)&&(t._cutValue=null,l=t.getClipString(),t._isCutting=!0,o.Clipboard.copy(l),t.onCopied(n))):o.assert(!1,"Cut operation cannot be used on multiple selections."))}e.keyCode===o.Key.Space&&t.selection.isValid&&t.selectionMode===i.SelectionMode.CellRange&&t.select(new i.CellRange(0,t.selection.col,t.rows.length-1,t.selection.col))}if(e.keyCode===o.Key.Escape&&t._contextMenu.hide(),(93===e.keyCode||e.shiftKey&&121===e.keyCode)&&(t._isContextMenuKeyDown=!0),t.selectedSheet&&!t._edtHdl.activeEditor)switch(e.keyCode){case o.Key.Left:case o.Key.Right:case o.Key.Up:case o.Key.Down:case o.Key.PageUp:case o.Key.PageDown:case o.Key.Home:case o.Key.End:case o.Key.Tab:case o.Key.Enter:t.selectedSheet._addSelection(t.selection),t.scrollIntoView(t.selection.row,t.selection.col)}}),t.addEventListener(document.body,"keydown",function(e){!t._isDescendant(t.hostElement,e.target)&&t.hostElement!==e.target||t._edtHdl.activeEditor||!t.selectedSheet||e.keyCode!==o.Key.Delete&&e.keyCode!==o.Key.Back||(t._delSeletionContent(e),e.preventDefault()),t._contextMenu.visible&&(e.keyCode===o.Key.Down&&t._contextMenu.moveToNext(),e.keyCode===o.Key.Up&&t._contextMenu.moveToPrev(),e.keyCode===o.Key.Home&&t._contextMenu.moveToFirst(),e.keyCode===o.Key.End&&t._contextMenu.moveToLast(),e.keyCode===o.Key.Enter&&t._contextMenu.handleContextMenu(),e.preventDefault())},!0),document.body.addEventListener("click",t._clickHdl),document.addEventListener("mousemove",t._mouseMoveHdl),(n.match(/iPad/i)||n.match(/iPhone/i))&&(document.body.addEventListener("touchstart",t._touchStartHdl),document.body.addEventListener("touchend",t._touchEndHdl)),t.addEventListener(t.hostElement,"drop",function(){t._htDown=null})},t.prototype._initFuncsList=function(){var e=this;e._functionListHost=document.createElement("div"),o.addClass(e._functionListHost,"wj-flexsheet-formula-list"),document.querySelector("body").appendChild(e._functionListHost),e._functionListHost.style.display="none",e._functionListHost.style.position="absolute",e._functionList=new l.ListBox(e._functionListHost),e._functionList.isContentHtml=!0,e._functionList.itemsSource=e._getFunctions(),e._functionList.displayMemberPath="displayValue",e._functionList.selectedValuePath="actualvalue",e.addEventListener(e._functionListHost,"click",e.applyFunctionToCell.bind(e)),e.addEventListener(e._functionListHost,"keydown",function(t){t.keyCode===o.Key.Escape&&(e.hideFunctionList(),e.hostElement.focus(),t.preventDefault()),t.keyCode===o.Key.Enter&&(e.applyFunctionToCell(),e.hostElement.focus(),t.preventDefault(),t.stopPropagation())})},t.prototype._getFunctions=function(){for(var e,t=[],o=0;o<W.length;o++)e=W[o],t.push({displayValue:'<div class="wj-flexsheet-formula-name">'+e.name+'</div><div class="wj-flexsheet-formula-description">'+e.description+"</div>",actualvalue:e.name});return t},t.prototype._addCustomFunctionDescription=function(e,t){for(var o={displayValue:'<div class="wj-flexsheet-formula-name">'+e+"</div>"+(t?'<div class="wj-flexsheet-formula-description">'+t+"</div>":""),actualvalue:e},n=this._functionList.itemsSource,i=-1,l=0;l<n.length;l++)if(n[l].actualvalue===e){i=l;break}i>-1?n.splice(i,1,o):n.push(o)},t.prototype._getCurrentFormulaIndex=function(e){var t=-1;return["+","-","*","/","^","(","&"].forEach(function(o){var n=e.lastIndexOf(o);n>t&&(t=n)}),t},t.prototype._prepareCellForEditHandler=function(){var e=this,t=e._edtHdl._edt;t&&(e.addEventListener(t,"keydown",function(t){if(e.isFunctionListOpen)switch(t.keyCode){case o.Key.Up:e.selectPreviousFunction(),t.preventDefault(),t.stopPropagation();break;case o.Key.Down:e.selectNextFunction(),t.preventDefault(),t.stopPropagation();break;case o.Key.Tab:case o.Key.Enter:e.applyFunctionToCell(),t.preventDefault(),t.stopPropagation();break;case o.Key.Escape:e.hideFunctionList(),t.preventDefault(),t.stopPropagation()}}),e.addEventListener(t,"keyup",function(n){(n.keyCode>40||n.keyCode<32)&&n.keyCode!==o.Key.Tab&&n.keyCode!==o.Key.Escape&&setTimeout(function(){e.showFunctionList(t)},0)}))},t.prototype._addSheet=function(e,t,o,n,i){var l=this,s=new K(l,i,e,t,o);return l.sheets.isValidSheetName(s)||s._setValidName(l.sheets.getValidSheetName(s)),s.nameChanged.addHandler(function(e,t){l._updateDefinedNameWithSheetRefUpdating(t.oldValue,t.newValue)}),"number"==typeof n?(n<0&&(n=0),n>=l.sheets.length&&(n=l.sheets.length)):n=l.sheets.length,l.sheets.insert(n,s),s},t.prototype._showSheet=function(e){!this.sheets||!this.sheets.length||e>=this.sheets.length||e<0||e===this.selectedSheetIndex||this.sheets[e]&&!this.sheets[e].visible||(this.finishEditing(),this._clearCalcEngine(),this._isCopying=!0,this.selectedSheetIndex>-1&&this.selectedSheetIndex<this.sheets.length&&this._copyTo(this.sheets[this.selectedSheetIndex]),this.sheets[e]&&(this._selectedSheetIndex=e,this._copyFrom(this.sheets[e])),this._isCopying=!1,this._filter.closeEditor())},t.prototype._selectedSheetChange=function(e,t){this._showSheet(t.newValue),this.invalidate(!0),this.onSelectedSheetChanged(t)},t.prototype._sourceChange=function(e,t){if(t.action===o.NotifyCollectionChangedAction.Add||t.action===o.NotifyCollectionChangedAction.Change)t.item._attachOwner(this),t.action===o.NotifyCollectionChangedAction.Add?(this._addingSheet=!0,t.index<=this.selectedSheetIndex&&(this._selectedSheetIndex+=1)):t.index===this.selectedSheetIndex&&this._copyFrom(t.item,!0),this.selectedSheetIndex=t.index;else if(t.action===o.NotifyCollectionChangedAction.Reset){for(var n=0;n<this.sheets.length;n++)this.sheets[n]._attachOwner(this);this.sheets.length>0?(0===this.selectedSheetIndex&&this._copyFrom(this.selectedSheet,!0),this.selectedSheetIndex=0):(this.rows.clear(),this.columns.clear(),this._selectedSheetIndex=-1)}else this.sheets.length>0?this.selectedSheetIndex>=this.sheets.length?this.selectedSheetIndex=0:this.selectedSheetIndex>t.index&&(this._selectedSheetIndex-=1):(this.rows.clear(),this.columns.clear(),this._selectedSheetIndex=-1);this.invalidate(!0)},t.prototype._sheetVisibleChange=function(e,t){t.item.visible||t.index===this.selectedSheetIndex&&(this.selectedSheetIndex===this.sheets.length-1?this.selectedSheetIndex=t.index-1:this.selectedSheetIndex=t.index+1)},t.prototype._applyStyleForCell=function(e,t,o){var n,i,l,s=this,r=s.rows[e];null==r||r instanceof G||!r.isVisible||(l=e*s.columns.length+t,(i=s.selectedSheet._getMergedRange(e,t))&&(l=i.topRow*s.columns.length+i.leftCol),(n=s.selectedSheet._styledCells[l])?(n.className="normal"===o.className?"":o.className||n.className,n.textAlign=o.textAlign||n.textAlign,n.verticalAlign=o.verticalAlign||n.verticalAlign,n.fontFamily=o.fontFamily||n.fontFamily,n.fontSize=o.fontSize||n.fontSize,n.backgroundColor=o.backgroundColor||n.backgroundColor,n.color=o.color||n.color,n.fontStyle="none"===o.fontStyle?"":o.fontStyle||n.fontStyle,n.fontWeight="none"===o.fontWeight?"":o.fontWeight||n.fontWeight,n.textDecoration="none"===o.textDecoration?"":o.textDecoration||n.textDecoration,n.format=o.format||n.format,n.whiteSpace=o.whiteSpace||n.whiteSpace,n.borderTopColor=o.borderTopColor||n.borderTopColor,n.borderTopStyle=o.borderTopStyle||n.borderTopStyle,n.borderTopWidth=o.borderTopWidth||n.borderTopWidth,n.borderBottomColor=o.borderBottomColor||n.borderBottomColor,n.borderBottomStyle=o.borderBottomStyle||n.borderBottomStyle,n.borderBottomWidth=o.borderBottomWidth||n.borderBottomWidth,n.borderLeftColor=o.borderLeftColor||n.borderLeftColor,n.borderLeftStyle=o.borderLeftStyle||n.borderLeftStyle,n.borderLeftWidth=o.borderLeftWidth||n.borderLeftWidth,n.borderRightColor=o.borderRightColor||n.borderRightColor,n.borderRightStyle=o.borderRightStyle||n.borderRightStyle,n.borderRightWidth=o.borderRightWidth||n.borderRightWidth):s.selectedSheet._styledCells[l]={className:o.className,textAlign:o.textAlign,verticalAlign:o.verticalAlign,fontStyle:o.fontStyle,fontWeight:o.fontWeight,fontFamily:o.fontFamily,fontSize:o.fontSize,textDecoration:o.textDecoration,backgroundColor:o.backgroundColor,color:o.color,format:o.format,whiteSpace:o.whiteSpace,borderTopColor:o.borderTopColor,borderTopStyle:o.borderTopStyle,borderTopWidth:o.borderTopWidth,borderBottomColor:o.borderBottomColor,borderBottomStyle:o.borderBottomStyle,borderBottomWidth:o.borderBottomWidth,borderLeftColor:o.borderLeftColor,borderLeftStyle:o.borderLeftStyle,borderLeftWidth:o.borderLeftWidth,borderRightColor:o.borderRightColor,borderRightStyle:o.borderRightStyle,borderRightWidth:o.borderRightWidth})},t.prototype._checkCellFormat=function(e,t,o){var n,i,l=e*this.columns.length+t;this.selectedSheet&&((n=this.selectedSheet._getMergedRange(e,t))&&(o.isMergedCell=!0,l=n.topRow*this.columns.length+n.leftCol),(i=this.selectedSheet._styledCells[l])&&(o.isBold=o.isBold||"bold"===i.fontWeight,o.isItalic=o.isItalic||"italic"===i.fontStyle,o.isUnderline=o.isUnderline||"underline"===i.textDecoration),e===this.selection.row&&t===this.selection.col&&(i&&i.textAlign?o.textAlign=i.textAlign:t>-1&&(o.textAlign=this.columns[t].getAlignment()||o.textAlign)))},t.prototype._resetMergedRange=function(e){var t,o,n,i,l=!1;for(t=e.topRow;t<=e.bottomRow;t++)for(o=e.leftCol;o<=e.rightCol;o++)(i=this.selectedSheet._getMergedRange(t,o))&&(l=!0,n=this.selectedSheet._mergedRanges.indexOf(i),this.selectedSheet._mergedRanges.splice(n,1));return l},t.prototype._updateCellsForUpdatingRow=function(e,t,o,n){var i,l,s,r,a,h,d,c=e*this.columns.length;if(n)for(l=i=t*this.columns.length;l<c;l++)s=l-o*this.columns.length,(r=this.selectedSheet._styledCells[l])&&(l>=(t+o)*this.columns.length&&(this.selectedSheet._styledCells[s]=r),delete this.selectedSheet._styledCells[l]);else for(i=t*this.columns.length-1,l=c-1;l>i;l--)s=l+this.columns.length*o,(r=this.selectedSheet._styledCells[l])&&(this.selectedSheet._styledCells[s]=r,delete this.selectedSheet._styledCells[l]);if(this.selectedSheet._mergedRanges.length>0)for(h=this.selectedSheet._mergedRanges.length-1;h>=0;h--)a=this.selectedSheet._mergedRanges[h],n?(d=t+o-1)<a.topRow?(a.row-=o,a.row2-=o):d>=a.topRow&&d<=a.bottomRow?t<=a.topRow&&d>=a.bottomRow?this.selectedSheet._mergedRanges.splice(h,1):t<a.topRow?a.row<=a.row2?(a.row+=t-a.topRow,a.row2-=o):(a.row2+=t-a.topRow,a.row-=o):t===a.topRow&&o===a.rowSpan?this.selectedSheet._mergedRanges.splice(h,1):a.row<=a.row2?a.row2-=o:a.row-=o:t<=a.topRow?this.selectedSheet._mergedRanges.splice(h,1):t<=a.bottomRow&&(a.row<=a.row2?a.row2+=t-a.bottomRow-1:a.row+=t-a.bottomRow-1):t<=a.topRow?(a.row+=o,a.row2+=o):t>a.topRow&&t<=a.bottomRow&&(a.row<=a.row2?a.row2+=o:a.row+=o)},t.prototype._updateCellsForUpdatingColumn=function(e,t,o,n){var i,l,s,r,a,h,d,c=this.rows.length*e;if(n)for(i=t;i<c;i++)l=i-o*(Math.floor(i/e)+((r=i%e)>=t?1:0)),(s=this.selectedSheet._styledCells[i])&&((r<t||r>=t+o)&&(this.selectedSheet._styledCells[l]=s),delete this.selectedSheet._styledCells[i]);else for(i=c-1;i>=t;i--)l=i+Math.floor(i/e)*o+((r=i%e)>=t?1:0),(s=this.selectedSheet._styledCells[i])&&(this.selectedSheet._styledCells[l]=s,delete this.selectedSheet._styledCells[i]);if(this.selectedSheet._mergedRanges.length>0)for(h=this.selectedSheet._mergedRanges.length-1;h>=0;h--)a=this.selectedSheet._mergedRanges[h],n?(d=t+o-1)<a.leftCol?(a.col-=o,a.col2-=o):d>=a.leftCol&&d<=a.rightCol?t<=a.leftCol&&d>=a.rightCol?this.selectedSheet._mergedRanges.splice(h,1):t<a.leftCol?a.col<=a.col2?(a.col+=t-a.leftCol,a.col2-=o):(a.col2+=t-a.leftCol,a.col-=o):t===a.leftCol&&o===a.columnSpan?this.selectedSheet._mergedRanges.splice(h,1):a.col<=a.col2?a.col2-=o:a.col-=o:t<=a.leftCol?this.selectedSheet._mergedRanges.splice(h,1):t<=a.rightCol&&(a.col<=a.col2?a.col2-=a.rightCol-t+1:a.col-=a.rightCol-t+1):t<=a.leftCol?(a.col+=o,a.col2+=o):t>a.leftCol&&t<=a.rightCol&&(a.col<=a.col2?a.col2+=o:a.col+=o)},t.prototype._cloneObject=function(e){var t;if(null==e||!o.isObject(e))return e;t={};for(var n in e)e.hasOwnProperty(n)&&null!=e[n]&&(e[n].clone?t[n]=e[n].clone():t[n]=this._cloneObject(e[n]));return t},t.prototype._evaluate=function(e,t,o,n,i){return e&&e.length>1?(e="="===e[0]?e:"="+e,this._calcEngine.evaluate(e,t,o,n,i)):e},t.prototype._copyTo=function(e){var t,o,n,l=this,s=e.grid.autoGenerateColumns;if(e._storeRowSettings(),n=this.selection.clone(),e.grid.selection=new i.CellRange,e.grid.rows.clear(),e.grid.columns.clear(),e.grid.columnHeaders.columns.clear(),e.grid.rowHeaders.rows.clear(),l.itemsSource)e.grid.autoGenerateColumns=!1,e.itemsSource=l.itemsSource,e.grid.collectionView.beginUpdate();else for(e.itemsSource=null,o=0;o<l.rows.length;o++)e.grid.rows.push(l.rows[o]);for(e._sortList=l.sortManager._committedList.slice(),e._getFilterSetting(),t=0;t<l.columns.length;t++)e.grid.columns.push(l.columns[t]);e.grid.collectionView&&(l._resetMappedColumns(e.grid),e.grid.collectionView.endUpdate()),e.grid.autoGenerateColumns=s,e.grid.frozenRows=l.frozenRows,e.grid.frozenColumns=l.frozenColumns,e.grid.allowAddNew=l.allowAddNew,null!=l.newRowAtTop&&(e.grid.newRowAtTop=l.newRowAtTop),e.grid.selection=n,e._scrollPosition=l.scrollPosition,setTimeout(function(){l._setFlexSheetToDirty(),l.refresh(!0)},10)},t.prototype._copyFrom=function(e,t){void 0===t&&(t=!0);var n,l,s,r,a,h,d=this,c=d.autoGenerateColumns;if(d._isCopying=!0,d._dragable=!1,d.itemsSource=null,d.rows.clear(),d.columns.clear(),d.columnHeaders.columns.clear(),d.rowHeaders.rows.clear(),h=e.grid.selection.clone(),d.selection=new i.CellRange,e.selectionRanges.length>1&&d.selectionMode===i.SelectionMode.CellRange&&(d._enableMulSel=!0),e.itemsSource)d.autoGenerateColumns=!1,d.itemsSource=e.itemsSource,d.collectionView.beginUpdate();else for(l=0;l<e.grid.rows.length;l++)d.rows.push(e.grid.rows[l]);for(d.sortManager.sortDescriptions.sourceCollection=e._sortList.slice(),d.sortManager._committedList=e._sortList.slice(),n=0;n<e.grid.columns.length;n++)(r=e.grid.columns[n]).isRequired=!1,d.columns.push(r);for(d.collectionView&&(d._resetMappedColumns(d),d.collectionView.endUpdate(),d.collectionView.collectionChanged.addHandler(function(t,n){switch(n.action){case o.NotifyCollectionChangedAction.Add:e._orgItemsSource&&e._orgItemsSource.splice(n.index,0,n.item);break;case o.NotifyCollectionChangedAction.Remove:e._orgItemsSource&&e._orgItemsSource.splice(e._orgItemsSource.indexOf(n.item),1);break;case o.NotifyCollectionChangedAction.Reset:setTimeout(function(){d.invalidate()},10)}},d)),d.rows.length&&d.columns.length&&(d.selection=h),e._applyFilterSetting(),l=0;l<d.rows.length;l++)(s=e._rowSettings[l])&&((a=d.rows[l]).height=s.height,a.allowMerging=s.allowMerging,a.visible=s.visible,a instanceof i.GroupRow&&(a.isCollapsed=!!s.isCollapsed),a.isSelected=!!s.isSelected,a.isReadOnly=!!s.readOnly);d.autoGenerateColumns=c,d.frozenRows=e.grid.frozenRows,d.frozenColumns=e.grid.frozenColumns,d._isCopying=!1,d._addingSheet?(d._toRefresh&&(clearTimeout(d._toRefresh),d._toRefresh=null),d._toRefresh=setTimeout(function(){d._setFlexSheetToDirty(),d.invalidate()},10),d._addingSheet=!1):t&&d.refresh(),d.scrollPosition=e._scrollPosition,d._ptScrl=e._scrollPosition},t.prototype._resetMappedColumns=function(e){var t,o,n=0;if(e._mappedColumns=null,e.collectionView)for(o=e.collectionView.sortDescriptions;n<o.length;n++)(t=e.columns.getColumn(o[n].property))&&t.dataMap&&(e._mappedColumns||(e._mappedColumns={}),e._mappedColumns[t.binding]=t.dataMap)},t.prototype._loadFromWorkbook=function(e){var t,o,n,i,l=0,r=this;if(null!=e.sheets&&0!==e.sheets.length){if(r.beginUpdate(),r.clear(),r._reservedContent=e.reservedContent,t=e.sheets.length,e.colorThemes&&e.colorThemes.length>0)for(i=0;i<this._colorThemes.length;i++)this._colorThemes[i]=e.colorThemes[i];for(;l<t;l++){if(l>0&&r.addUnboundSheet(),r.selectedSheet.grid.wj_sheetInfo={},s.FlexGridXlsxConverter.load(r.selectedSheet.grid,e,{sheetIndex:l,includeColumnHeaders:!1}),r.selectedSheet.name=r.selectedSheet.grid.wj_sheetInfo.name,r.selectedSheet.visible=r.selectedSheet.grid.wj_sheetInfo.visible,r.selectedSheet._styledCells=r.selectedSheet.grid.wj_sheetInfo.styledCells,r.selectedSheet.grid.wj_sheetInfo.mergedRanges)for(n=0;n<r.selectedSheet.grid.wj_sheetInfo.mergedRanges.length;n++)r.selectedSheet._mergedRanges[n]=r.selectedSheet.grid.wj_sheetInfo.mergedRanges[n];if(r._copyFrom(r.selectedSheet,!1),null!=r.selectedSheet.grid.wj_sheetInfo.tables&&r.selectedSheet.grid.wj_sheetInfo.tables.length>0)for(i=0;i<r.selectedSheet.grid.wj_sheetInfo.tables.length;i++)this._parseFromWorkbookTable(r.selectedSheet.grid.wj_sheetInfo.tables[i],r.selectedSheet)}if(null!=e.activeWorksheet&&e.activeWorksheet>-1&&e.activeWorksheet<r.sheets.length?r.selectedSheetIndex=e.activeWorksheet:r.selectedSheetIndex=0,e.definedNames&&e.definedNames.length>0)for(i=0;i<e.definedNames.length;i++)o=e.definedNames[i],r.definedNames.push(new q(r,o.name,o.value,o.sheetName));r.endUpdate(),r.onLoaded()}},t.prototype._saveToWorkbook=function(){var e,t,i,l,r,a;if(0===this.sheets.length)throw"The flexsheet is empty.";if(l=this.sheets[0],0===this.selectedSheetIndex&&(l._storeRowSettings(),l.itemsSource instanceof o.CollectionView||this._copyRowsToSelectedSheet()),l._setRowSettings(),l.tables.length>0)for(l.grid.wj_sheetInfo.tables=[],a=0;a<l.tables.length;a++)l.grid.wj_sheetInfo.tables.push(this._parseToWorkbookTable(l.tables[a]));for((e=s.FlexGridXlsxConverter.save(l.grid,{sheetName:l.name,sheetVisible:l.visible,includeColumnHeaders:!1})).reservedContent=this._reservedContent,r=1;r<this.sheets.length;r++){if(l=this.sheets[r],this.selectedSheetIndex===r&&(l._storeRowSettings(),l.itemsSource instanceof o.CollectionView||this._copyRowsToSelectedSheet()),l._setRowSettings(),l.tables.length>0)for(l.grid.wj_sheetInfo.tables=[],a=0;a<l.tables.length;a++)l.grid.wj_sheetInfo.tables.push(this._parseToWorkbookTable(l.tables[a]));t=s.FlexGridXlsxConverter.save(l.grid,{sheetName:l.name,sheetVisible:l.visible,includeColumnHeaders:!1}),e._addWorkSheet(t.sheets[0],r)}for(e.activeWorksheet=this.selectedSheetIndex,a=0;a<this.definedNames.length;a++){var h=this.definedNames[a];(i=new n.DefinedName).name=h.name,i.value=h.value,i.sheetName=h.sheetName,e.definedNames.push(i)}if(this._colorThemes&&this._colorThemes.length>0)for(a=0;a<this._colorThemes.length;a++)e.colorThemes[a]=this._colorThemes[a];return e},t.prototype._mouseDown=function(e){var t,n,l,s=window.navigator.userAgent,r=this.hitTest(e);this.columns;if(this.selectedSheet&&(this.selectedSheet._scrollPosition=this.scrollPosition),this._dragable)return this._isDragging=!0,this._draggingMarker=document.createElement("div"),o.setCss(this._draggingMarker,{position:"absolute",display:"none",borderStyle:"dotted",cursor:"move"}),document.body.appendChild(this._draggingMarker),this._draggingTooltip=new o.Tooltip,this._draggingCells=this.selection,this.selectedSheet&&this.selectedSheet.selectionRanges.clear(),this.onDraggingRowColumn(new B(this._draggingRow,e.shiftKey)),void e.preventDefault();if(r.cellType!==i.CellType.None&&(this._isClicking=!0),this.selectionMode===i.SelectionMode.CellRange?e.ctrlKey?this._enableMulSel||(this._enableMulSel=!0):r.cellType!==i.CellType.None&&(this.selectedSheet&&this.selectedSheet.selectionRanges.clear(),this._enableMulSel&&this.refresh(!1),this._enableMulSel=!1):(this._enableMulSel=!1,this.selectedSheet&&this.selectedSheet.selectionRanges.clear()),this._htDown=r,0!==this.rows.length&&0!==this.columns.length&&(s.match(/iPad/i)||s.match(/iPhone/i)||this._contextMenu.hide(),this.selectionMode===i.SelectionMode.CellRange)){if(r.cellType===i.CellType.RowHeader&&3===e.which)return l=new i.CellRange(r.row,0,r.row,this.columns.length-1),void(this.selection.contains(l)||(this.selection=l));if((r.cellType===i.CellType.ColumnHeader||r.cellType===i.CellType.None)&&!(r.col>-1&&this.columns[r.col].isSelected)&&o.hasClass(e.target,"wj-cell")&&!r.edgeRight){if(this._columnHeaderClicked=!0,n=this.itemsSource&&this.rows[0]&&!this.rows[0].isVisible?1:0,e.shiftKey)this._multiSelectColumns(r);else{if(t=new i.CellRange(n,r.col,this.rows.length-1,r.col),3===e.which&&this.selection.contains(t))return;this.select(t)}this._eCt.children[n]&&this._eCt.children[n].children[r.col]&&this._eCt.children[n].children[r.col].focus()}}},t.prototype._mouseMove=function(e){var t,o=this.hitTest(e),n=this.selection,l=this.rows.length,s=this.columns.length,r=this.hostElement.style.cursor;return 0===this.rows.length||0===this.columns.length?(this._dragable=!1,void(o.cellType===i.CellType.Cell&&(this.hostElement.style.cursor="default"))):this._isDragging?(this.hostElement.style.cursor="move",void this._showDraggingMarker(e)):(t=this.itemsSource?0===n.topRow||1===n.topRow:0===n.topRow,n&&o.cellType!==i.CellType.None&&!this.itemsSource&&(this._draggingColumn=t&&n.bottomRow===l-1,this._draggingRow=0===n.leftCol&&n.rightCol===s-1,o.cellType===i.CellType.Cell?(this._draggingColumn&&((o.col===n.leftCol-1||o.col===n.rightCol)&&o.edgeRight||o.row===l-1&&o.edgeBottom)&&(r="move"),this._draggingRow&&!this._containsGroupRows(n)&&((o.row===n.topRow-1||o.row===n.bottomRow)&&o.edgeBottom||o.col===s-1&&o.edgeRight)&&(r="move")):o.cellType===i.CellType.ColumnHeader?o.edgeBottom&&(this._draggingColumn&&o.col>=n.leftCol&&o.col<=n.rightCol?r="move":this._draggingRow&&0===n.topRow&&(r="move")):o.cellType===i.CellType.RowHeader&&o.edgeRight&&(this._draggingColumn&&0===n.leftCol?r="move":this._draggingRow&&o.row>=n.topRow&&o.row<=n.bottomRow&&!this._containsGroupRows(n)&&(r="move")),this._dragable="move"===r,this.hostElement.style.cursor=r),void(this._htDown&&this._htDown.panel&&(o=new i.HitTestInfo(this._htDown.panel,e),this._multiSelectColumns(o),o.cellType===i.CellType.Cell&&this.scrollIntoView(o.row,o.col))))},t.prototype._mouseUp=function(e){try{this._isDragging&&(this._draggingCells.equals(this._dropRange)||(this._handleDropping(e),this.onDroppingRowColumn()))}finally{this._isDragging&&(this._draggingCells=null,this._dropRange=null,document.body.removeChild(this._draggingMarker),this._draggingMarker=null,this._draggingTooltip.hide(),this._draggingTooltip=null,this._isDragging=!1,this._draggingColumn=!1,this._draggingRow=!1),this._htDown&&this._htDown.cellType!==i.CellType.None&&this.selectedSheet&&(this._htDown.cellType===i.CellType.TopLeft&&this.selectionMode===i.SelectionMode.CellRange&&(this.selection=new i.CellRange(0,0,this.rows.length-1,this.columns.length-1)),this.selection.isValid&&this.selectedSheet._addSelection(this.selection),this._enableMulSel=!1),this._isClicking=!1,this._columnHeaderClicked=!1,this._htDown=null}},t.prototype._click=function(){var e=this,t=window.navigator.userAgent;t.match(/iPad/i)||t.match(/iPhone/i)||e._contextMenu.hide(),setTimeout(function(){e.hideFunctionList()},200)},t.prototype._touchStart=function(e){var t=this;o.hasClass(e.target,"wj-context-menu-item")||t._contextMenu.hide(),t._longClickTimer=setTimeout(function(){var n;t._isDescendant(t._divContainer,e.target)&&(n=t.hitTest(e))&&n.cellType!==i.CellType.None&&!t._resizing&&(n.cellType===i.CellType.TopLeft&&(t.selection=new i.CellRange(0,0,t.rows.length-1,t.columns.length-1),t.selectedSheet&&(t.selectedSheet.selectionRanges.clear(),t.selectedSheet.selectionRanges.push(t.selection))),t._contextMenu.show(null,new o.Point(e.pageX+10,e.pageY+10)))},500)},t.prototype._touchEnd=function(){clearTimeout(this._longClickTimer)},t.prototype._showDraggingMarker=function(e){var n,l,s,r,a,h,d,c,u,_=new i.HitTestInfo(this.cells,e),g=this.selection,f=this.columns.length,p=this.rows.length,w=this._cumulativeScrollOffset(this.hostElement),m=this._root.getBoundingClientRect(),C=m.left+w.x,b=m.top+w.y;if(this.scrollIntoView(_.row,_.col),this._draggingColumn){for(l=g.rightCol-g.leftCol+1,a=0,((s=_.col)<0||s+l>f)&&(s=f-l),n=this.cells.getCellBoundingRect(0,s),h=this._root.offsetHeight-this._eCHdr.offsetHeight,r=(r=this.cells.height)>h?h:r,d=0;d<l;d++)a+=this.columns[s+d].renderSize;c=t.convertNumberToAlpha(s)+" : "+t.convertNumberToAlpha(s+l-1),this._dropRange?(this._dropRange.col=s,this._dropRange.col2=s+l-1):this._dropRange=new i.CellRange(0,s,this.rows.length-1,s+l-1)}else if(this._draggingRow){for(l=g.bottomRow-g.topRow+1,r=0,((s=_.row)<0||s+l>p)&&(s=p-l),n=this.cells.getCellBoundingRect(s,0),h=this._root.offsetWidth-this._eRHdr.offsetWidth,d=0;d<l;d++)r+=this.rows[s+d].renderSize;a=(a=this.cells.width)>h?h:a,c=s+1+" : "+(s+l),this._dropRange?(this._dropRange.row=s,this._dropRange.row2=s+l-1):this._dropRange=new i.CellRange(s,0,s+l-1,this.columns.length-1)}if(n){if(u={display:"inline",zIndex:"9999",opacity:.5,top:n.top-(this._draggingColumn?this._ptScrl.y:0)+w.y,left:n.left-(this._draggingRow?this._ptScrl.x:0)+w.x,height:r,width:a},n.top=n.top-(this._draggingColumn?this._ptScrl.y:0),n.left=n.left-(this._draggingRow?this._ptScrl.x:0),this.rightToLeft&&this._draggingRow&&(u.left=u.left-a+n.width+2*this._ptScrl.x,n.left=n.left+2*this._ptScrl.x),this._draggingRow){if(C+this._eRHdr.offsetWidth!==u.left||b+this._root.offsetHeight+1<u.top+u.height)return}else if(b+this._eCHdr.offsetHeight!==u.top||C+this._root.offsetWidth+1<u.left+u.width)return;o.setCss(this._draggingMarker,u),this._draggingTooltip.show(this.hostElement,c,n)}},t.prototype._handleDropping=function(e){var t,n,i,l,s,r,a,h=this;if(h.selectedSheet&&h._draggingCells&&h._dropRange&&!h._containsMergedCells(h._draggingCells)&&!h._containsMergedCells(h._dropRange)){if(h._clearCalcEngine(),h._draggingColumn&&h._draggingCells.leftCol>h._dropRange.leftCol||h._draggingRow&&h._draggingCells.topRow>h._dropRange.topRow)if(e.shiftKey){if(!h._allowExchangeCells(h._draggingRow,!0))return void console.warn("Can not complete operation: You are attempting to change a position of table row or column in a way that is not allowed.");if(h._draggingColumn){for(l=h._dropRange.leftCol,n=h._draggingCells.leftCol;n<=h._draggingCells.rightCol;n++)h.columns.moveElement(n,l),l++;h._exchangeTableColumns(!0)}else if(h._draggingRow)for(i=h._dropRange.topRow,t=h._draggingCells.topRow;t<=h._draggingCells.bottomRow;t++)h.rows.moveElement(t,i),i++;h._exchangeCellStyle(!0)}else{for(this.undoStack.stackSize>0&&(s=new N(h,h._draggingCells,h._dropRange,e.ctrlKey)),i=h._dropRange.topRow,t=h._draggingCells.topRow;t<=h._draggingCells.bottomRow;t++){for(l=h._dropRange.leftCol,n=h._draggingCells.leftCol;n<=h._draggingCells.rightCol;n++)h._moveCellContent(t,n,i,l,e.ctrlKey),h._draggingColumn&&i===h._dropRange.topRow&&(h.columns[l].dataType=h.columns[n].dataType?h.columns[n].dataType:o.DataType.Object,h.columns[l].align=h.columns[n].align,h.columns[l].format=h.columns[n].format,e.ctrlKey||(h.columns[n].dataType=o.DataType.Object,h.columns[n].align=null,h.columns[n].format=null)),l++;i++}if(h._draggingColumn&&!e.ctrlKey)for(l=h._dropRange.leftCol,n=h._draggingCells.leftCol;n<=h._draggingCells.rightCol;n++)h._updateColumnFiler(n,l),l++}else if(h._draggingColumn&&h._draggingCells.leftCol<h._dropRange.leftCol||h._draggingRow&&h._draggingCells.topRow<h._dropRange.topRow)if(e.shiftKey){if(!h._allowExchangeCells(h._draggingRow,!1))return void console.warn("Can not complete operation: You are attempting to change a position of table row or column in a way that is not allowed.");if(h._draggingColumn){for(l=h._dropRange.rightCol,n=h._draggingCells.rightCol;n>=h._draggingCells.leftCol;n--)h.columns.moveElement(n,l),l--;h._exchangeTableColumns(!1)}else if(h._draggingRow)for(i=h._dropRange.bottomRow,t=h._draggingCells.bottomRow;t>=h._draggingCells.topRow;t--)h.rows.moveElement(t,i),i--;h._exchangeCellStyle(!1)}else{for(this.undoStack.stackSize>0&&(s=new N(h,h._draggingCells,h._dropRange,e.ctrlKey)),i=h._dropRange.bottomRow,t=h._draggingCells.bottomRow;t>=h._draggingCells.topRow;t--){for(l=h._dropRange.rightCol,n=h._draggingCells.rightCol;n>=h._draggingCells.leftCol;n--)h._moveCellContent(t,n,i,l,e.ctrlKey),h._draggingColumn&&i===h._dropRange.bottomRow&&(h.columns[l].dataType=h.columns[n].dataType?h.columns[n].dataType:o.DataType.Object,h.columns[l].align=h.columns[n].align,h.columns[l].format=h.columns[n].format,e.ctrlKey||(h.columns[n].dataType=o.DataType.Object,h.columns[n].align=null,h.columns[n].format=null)),l--;i--}if(h._draggingColumn&&!e.ctrlKey)for(l=h._dropRange.rightCol,n=h._draggingCells.rightCol;n>=h._draggingCells.leftCol;n--)h._updateColumnFiler(n,l),l--}e.ctrlKey||(r=h._updateFormulaForDropping(e.shiftKey),a=h._updateNamedRangesForDropping(e.shiftKey)),s&&s.saveNewState()&&(s._affectedFormulas=r,s._affectedDefinedNameVals=a,h._undoStack._addAction(s)),h._undoStack._pendingAction&&(h._undoStack._pendingAction._affectedFormulas=r,h._undoStack._pendingAction._affectedDefinedNameVals=a),h.select(h._dropRange),h.selectedSheet._addSelection(h.selection),h.hostElement.focus()}},t.prototype._moveCellContent=function(e,t,o,n,i){var l,s,r,a,h,d,c,u,_=this.getCellData(e,t,!1),g=e*this.columns.length+t,f=o*this.columns.length+n,p=this.selectedSheet._styledCells[g],w=!0;if((s=this.selectedSheet.findTable(o,n))&&(c=s.getRange(),u=s.getColumns(),s.showHeaderRow&&o===c.topRow&&(h=u[a=n-c.leftCol].name,null==_||""===_?w=!1:u[a].name=_)),w?this.setCellData(o,n,_):w=!0,p?this.selectedSheet._styledCells[f]=this._cloneObject(p):delete this.selectedSheet._styledCells[f],i)(l=this.selectedSheet.findTable(e,t))&&(d=l.getRange(),l===s&&e===o&&l.showHeaderRow&&e===d.topRow&&(r=t-d.leftCol,l._updateColumnName(r,_)));else{if(delete this.selectedSheet._styledCells[g],l=this.selectedSheet.findTable(e,t)){if(d=l.getRange(),l===s&&e===o&&l.showHeaderRow&&e===d.topRow)return r=t-d.leftCol,void l._updateColumnName(r,h);if(l.showHeaderRow&&e===d.topRow)return}this.setCellData(e,t,null)}},t.prototype._allowExchangeCells=function(e,t){var o,n,l,s,r,a=this.selectedSheet.tables;for(o=0;o<a.length;o++)if(n=a[o],e?(l=n.getRange(ne.Data),this._draggingCells.rowSpan,s=new i.CellRange(this._draggingCells.topRow,l.leftCol,this._draggingCells.bottomRow,l.rightCol),r=new i.CellRange(this._dropRange.topRow,l.leftCol,this._dropRange.bottomRow,l.rightCol)):(l=n.getRange(),this._draggingCells.columnSpan,s=new i.CellRange(l.topRow,this._draggingCells.leftCol,l.bottomRow,this._draggingCells.rightCol),r=new i.CellRange(l.topRow,this._dropRange.leftCol,l.bottomRow,this._dropRange.rightCol)),l.intersects(s)&&!l.contains(s)||l.intersects(r)&&!l.contains(r)||l.contains(s)&&!l.contains(r)||!l.contains(s)&&l.contains(r))return!1;return!0},t.prototype._exchangeTableColumns=function(e){var t,o,n,i,l,s,r=this.selectedSheet.tables;for(t=0;t<r.length;t++)if(o=r[t],(n=o.getRange()).leftCol<=this._draggingCells.leftCol&&n.rightCol>=this._draggingCells.rightCol)for(i=(e?this._draggingCells.leftCol:this._draggingCells.rightCol)-n.leftCol,l=(e?this._dropRange.leftCol:this._dropRange.rightCol)-n.leftCol,s=0;s<this._draggingCells.columnSpan;s++)o._moveColumns(i,l),e?(i++,l++):(i--,l--)},t.prototype._exchangeCellStyle=function(e){var t,o,n,i,l,s=0,r=[];for(t=this._draggingCells.topRow;t<=this._draggingCells.bottomRow;t++)for(o=this._draggingCells.leftCol;o<=this._draggingCells.rightCol;o++)n=t*this.columns.length+o,this.selectedSheet._styledCells[n]?(r.push(this._cloneObject(this.selectedSheet._styledCells[n])),delete this.selectedSheet._styledCells[n]):r.push(void 0);if(e){if(this._draggingColumn)for(l=this._draggingCells.rightCol-this._draggingCells.leftCol+1,o=this._draggingCells.leftCol-1;o>=this._dropRange.leftCol;o--)for(t=0;t<this.rows.length;t++)n=t*this.columns.length+o,i=t*this.columns.length+o+l,this.selectedSheet._styledCells[n]?(this.selectedSheet._styledCells[i]=this._cloneObject(this.selectedSheet._styledCells[n]),delete this.selectedSheet._styledCells[n]):delete this.selectedSheet._styledCells[i];else if(this._draggingRow)for(l=this._draggingCells.bottomRow-this._draggingCells.topRow+1,t=this._draggingCells.topRow-1;t>=this._dropRange.topRow;t--)for(o=0;o<this.columns.length;o++)n=t*this.columns.length+o,i=(t+l)*this.columns.length+o,this.selectedSheet._styledCells[n]?(this.selectedSheet._styledCells[i]=this._cloneObject(this.selectedSheet._styledCells[n]),delete this.selectedSheet._styledCells[n]):delete this.selectedSheet._styledCells[i]}else if(this._draggingColumn)for(l=this._draggingCells.rightCol-this._draggingCells.leftCol+1,o=this._draggingCells.rightCol+1;o<=this._dropRange.rightCol;o++)for(t=0;t<this.rows.length;t++)n=t*this.columns.length+o,i=t*this.columns.length+o-l,this.selectedSheet._styledCells[n]?(this.selectedSheet._styledCells[i]=this._cloneObject(this.selectedSheet._styledCells[n]),delete this.selectedSheet._styledCells[n]):delete this.selectedSheet._styledCells[i];else if(this._draggingRow)for(l=this._draggingCells.bottomRow-this._draggingCells.topRow+1,t=this._draggingCells.bottomRow+1;t<=this._dropRange.bottomRow;t++)for(o=0;o<this.columns.length;o++)n=t*this.columns.length+o,i=(t-l)*this.columns.length+o,this.selectedSheet._styledCells[n]?(this.selectedSheet._styledCells[i]=this._cloneObject(this.selectedSheet._styledCells[n]),delete this.selectedSheet._styledCells[n]):delete this.selectedSheet._styledCells[i];for(t=this._dropRange.topRow;t<=this._dropRange.bottomRow;t++)for(o=this._dropRange.leftCol;o<=this._dropRange.rightCol;o++)n=t*this.columns.length+o,r[s]?this.selectedSheet._styledCells[n]=r[s]:delete this.selectedSheet._styledCells[n],s++},t.prototype._containsMergedCells=function(e,t){var o,n,i,l,s;if(t=t||this.selectedSheet,s=t===this.selectedSheet?this:t.grid,!t)return!1;for(o=e.topRow;o<=e.bottomRow;o++)for(n=e.leftCol;n<=e.rightCol;n++)if(i=o*s.columns.length+n,(l=t._mergedRanges[i])&&l.isValid&&!l.isSingleCell)return!0;return!1},t.prototype._multiSelectColumns=function(e){var t;e&&this._columnHeaderClicked&&((t=new i.CellRange(e.row,e.col)).row=this.itemsSource&&this.rows[0]&&!this.rows[0].isVisible?1:0,t.row2=this.rows.length-1,t.col2=this.selection.col2,this.select(t))},t.prototype._cumulativeOffset=function(e){var t=0,n=0;do{t+=e.offsetTop||0,n+=e.offsetLeft||0,e=e.offsetParent}while(e);return new o.Point(n,t)},t.prototype._cumulativeScrollOffset=function(e){var t=0,n=0;do{t+=e.scrollTop||0,n+=e.scrollLeft||0,e=e.offsetParent}while(e&&!(e instanceof HTMLBodyElement));return t+=document.body.scrollTop||document.documentElement.scrollTop,n+=document.body.scrollLeft||document.documentElement.scrollLeft,new o.Point(n,t)},t.prototype._checkHitWithinSelection=function(e){var t;if(null!=e&&e.cellType===i.CellType.Cell){if((t=this.getMergedRange(this.cells,e.row,e.col))&&t.contains(this.selection))return!0;if(this.selection.row===e.row&&this.selection.col===e.col)return!0}return!1},t.prototype._clearForEmptySheet=function(e){this.selectedSheet&&0===this[e].length&&!0!==this._isCopying&&!0!==this._isUndoing&&!0!==this._isSorting&&(this.selectedSheet._mergedRanges.length=0,this.selectedSheet._styledCells=null,this.select(new i.CellRange))},t.prototype._containsGroupRows=function(e){var t;for(t=e.topRow;t<=e.bottomRow;t++)if(this.rows[t]instanceof i.GroupRow)return!0;return!1},t.prototype._delSeletionContent=function(e){var t,n,l,s,r,a,h,d,c,u,_=this.selectedSheet.selectionRanges.slice(),g=!1,f=new R(this),p=this.editableCollectionView,w=!1,m=this.scrollPosition;if(!this.isReadOnly)if(this.allowDelete&&this.selection.isValid&&0===this.selection.leftCol&&this.selection.rightCol===this.columns.length-1)this.deleteRows(this.selection.topRow,this.selection.rowSpan);else{for(this.beginUpdate(),this.undoStack.stackSize>0&&(f=new R(this)),null!=_&&0!==_.length||(_=[this.selection]),l=0;l<_.length;l++){if(t=_[l],n=new i.CellRange,c=new i.CellEditEndingEventArgs(this.cells,n,e),this.selectedSheet.tables.length>0)for(a=0;a<this.selectedSheet.tables.length;a++)h=this.selectedSheet.tables[a],t.contains(h.getRange())&&(f&&f._storeDeletedTables(h),this.selectedSheet.tables.remove(h));for(r=t.topRow;r<=t.bottomRow;r++)if((u=this.rows[r])&&!u.isReadOnly)for(s=t.leftCol;s<=t.rightCol;s++)(!(d=this._getBindingColumn(this.cells,r,this.columns[s])).isReadOnly&&!1===d.isRequired||null==d.isRequired&&d.dataType==o.DataType.String)&&this.getCellData(r,s,!0)&&(n.setRange(r,s),c.cancel=!1,this.onBeginningEdit(c)&&(p&&(w||(w=!0,p.beginUpdate()),p.editItem(u.dataItem),this._edtHdl._edItem=p.currentEditItem),this.setCellData(r,s,"",!0),g=!0,this.onCellEditEnding(c),this.onCellEditEnded(c)));w&&(p.endUpdate(),t.rowSpan>1&&p.commitEdit())}g&&f&&(f.saveNewState(),this._undoStack._addAction(f)),this.selection=t,this.scrollPosition=m,this.endUpdate()}},t.prototype._updateAffectedFormula=function(e,t,n,i){var l,s,r,a,h,d,c,u,_,g=[],f=[],p=this.selection.clone();for(this.selectedSheet._storeRowSettings(),this.beginUpdate(),l=0;l<this.sheets.length;l++)for(r=(s=this.sheets[l]).grid,a=0;a<r.rows.length;a++)for(h=0;h<r.columns.length;h++)if((u=r.getCellData(a,h,!1))&&o.isString(u)&&"="===u[0]&&(_=this._updateCellRef(u,l,e,t,n,i))){if(g.push({sheet:s,point:new o.Point(a,h),formula:u}),d=a,c=h,l===this.selectedSheetIndex&&(i?a>=e&&(n?d+=t:d-=t):h>=e&&(n?c+=t:c-=t),!n&&(i&&a<=e&&a>=e-t+1||!i&&h<=e&&h>=e-t+1)))continue;r.setCellData(a,h,_,!1),f.push({sheet:s,point:new o.Point(d,c),formula:_})}return this.selection=p,this.endUpdate(),{oldFormulas:g,newFormulas:f}},t.prototype._updateAffectedNamedRanges=function(e,t,n,i){var l,s,r,a,h=[],d=[];for(l=0;l<this.definedNames.length;l++)(r=(s=this.definedNames[l]).value)&&o.isString(r)&&(a=this._updateCellRef(r,this.selectedSheetIndex,e,t,n,i))&&(h.push({name:s.name,value:r}),s.value=a,d.push({name:s.name,value:a}));return{oldDefinedNameVals:h,newDefinedNameVals:d}},t.prototype._updateColumnFiler=function(e,t){for(var o=JSON.parse(this._filter.filterDefinition),n=0;n<o.filters.length;n++){var i=o.filters[n];if(i.columnIndex===e){i.columnIndex=t;break}}this._filter.filterDefinition=JSON.stringify(o)},t.prototype._isDescendant=function(e,t){for(var o=t.parentNode;null!=o;){if(o===e)return!0;o=o.parentNode}return!1},t.prototype._clearCalcEngine=function(){this._calcEngine._clearExpressionCache()},t.prototype._getRangeString=function(e,t,n){void 0===n&&(n=!0);var l,s,r,a,h,d="",c=!0,u=t.grid;if(o.isArray(e))if(e.length>1){if(this._isMultipleRowsSelected(e,t)){for(d="",s=0;s<e.length;s++)d&&(d+="\n"),d+=this._getRangeString(e[s],t);return d}if(!this._isMultipleColumnsSelected(e,t))return"";for(d="",l=0,c=!0;l<u.rows.length;l++){for(c||(d+="\n"),c=!1,s=0,p=!0;s<e.length;s++)(r=e[s].clone()).row=r.row2=l,p||(d+="\t"),p=!1,d+=this._getRangeString(e[s],t);return d}}else switch(h=e[0],this.selectionMode){case i.SelectionMode.Row:case i.SelectionMode.RowRange:h.col=0,h.col2=t.grid.columns.length-1;break;case i.SelectionMode.ListBox:h.col=0,h.col2=t.grid.columns.length-1;for(var _=0;_<t.grid.rows.length;_++)t.grid.rows[_].isSelected&&t.grid.rows[_].isVisible&&(h.row=h.row2=_,d&&(d+="\n"),d+=this._getRangeString(h,t));return d}for(var g=(h=o.asType(o.isArray(e)?e[0]:e,i.CellRange)).topRow;g<=h.bottomRow;g++)if(u.rows[g]&&u.rows[g].isVisible){c||(d+="\n"),c=!1;for(var f=h.leftCol,p=!0;f<=h.rightCol;f++)if(u.columns[f]&&u.columns[f].isVisible){p||(d+="\t"),p=!1;var w=this._getCellStyle(g,f,t),m=w?w.format:"",C=u.columns[f];n?(a=u.getCellData(g,f,!1),o.isString(a)&&"="===a[0]&&(a=this._evaluate(a,m,t,g,f)),a=this._formatEvaluatedResult(a,C,m)):(a=u.getCellData(g,f,!1),o.isDate(a)&&(a=o.Globalize.format(a,C.format)),C.dataMap&&(a=C.dataMap.getDisplayValue(a))),(a=(a=null==a?"":a.toString()).replace(/\t/g," ")).indexOf("\n")>-1&&(a='"'+a.replace(/"/g,'""')+'"'),d+=a}}return d},t.prototype._getSelectionForListBoxMode=function(e){for(var t,o=0;o<e.rows.length;o++)e.rows[o].isSelected&&(t?t.row2=o:t=new i.CellRange(o,0,o,e.columns.length-1));return t},t.prototype._containsRandFormula=function(e,t){for(var n=0;n<e.length;n++)for(var i=e[n],l=i.topRow;l<=i.bottomRow&&l<t.grid.rows.length;l++)for(var s=i.leftCol;s<=i.rightCol&&s<t.grid.columns.length;s++){var r=t.grid.getCellData(l,s,!1);if(o.isString(r)&&"="===r[0]&&-1!==r.search(/rand/i))return!0}return!1},t.prototype._isMultipleRowsSelected=function(e,t){var o,n,i;e&&e.length>1?i=e:this.selectedSheet.selectionRanges.length>1&&(i=this.selectedSheet.selectionRanges),o=i[0];for(var l=1;l<i.length;l++)if((n=i[l]).leftCol!==o.leftCol||n.rightCol!==o.rightCol)return!1;return!0},t.prototype._isMultipleColumnsSelected=function(e,t){var o,n,i;e&&e.length>1?i=e:this.selectedSheet.selectionRanges.length>1&&(i=this.selectedSheet.selectionRanges),o=i[0];for(var l=0;l<i.length;l++)if((n=i[l]).topRow!==o.topRow||n.bottomRow!==o.bottomRow)return!1;return!0},t.prototype._postSetClipStringProcess=function(e,t,n,l,s,r){var a,h,d,c,u,_=!1;return l>=0&&s>=0&&this._copiedSheet&&(a=this._copiedSheet._getMergedRange(l,s))&&a.topRow===l&&a.leftCol===s&&(h=(h=t+a.rowSpan-1)<this.rows.length?h:this.rows.length-1,d=(d=n+a.columnSpan-1)<this.columns.length?d:this.columns.length-1,this.mergeRange(new i.CellRange(t,n,h,d),!0)),c=new i.CellRangeEventArgs(this.cells,new i.CellRange(t,n),e),this.onPastingCell(c)&&this.cells.setCellData(t,n,c.data)&&(o.isString(c.data)&&(u=c.data.match(/\n/g))&&u.length>0&&(r?r.whiteSpace="pre":r={whiteSpace:"pre"},this.rows[t].height=this.rows.defaultSize*(u.length+1)),r&&this._applyStyleForCell(t,n,r),this.onPastedCell(c),_=!0),_},t.prototype._delCutData=function(e,t){var n,l,s,r,a=this._copiedSheet===this.selectedSheet?this:this._copiedSheet.grid;for(n=(r=this.selectionMode===i.SelectionMode.ListBox?this._getSelectionForListBoxMode(a):this._copiedRanges[0]).topRow;n<=r.bottomRow;n++)if(null!=a.rows[n])for(l=r.leftCol;l<=r.rightCol;l++)(this._copiedSheet!==this.selectedSheet||n<this.selection.topRow||n>this.selection.topRow+e||l<this.selection.leftCol||l>this.selection.leftCol+t)&&(0==(s=a._getBindingColumn(a.cells,n,a.columns[l])).isRequired||null==s.isRequired&&s.dataType==o.DataType.String)&&a.getCellData(n,l,!0)&&a.setCellData(n,l,"",!0)},t.prototype._containsMultiLineText=function(e){for(var t=0;t<e.length;t++)for(var o=e[t],n=0;n<o.length;n++)if(o[n].indexOf("\n")>=0)return!0;return!1},t.prototype._sortByRow=function(e,t){return e.topRow>t.topRow?1:e.topRow<t.topRow?-1:0},t.prototype._sortByColumn=function(e,t){return e.leftCol>t.leftCol?1:e.leftCol<t.leftCol?-1:0},t.prototype._setFlexSheetToDirty=function(){this.columns._dirty=!0,this.rows._dirty=!0,this.rowHeaders.columns._dirty=!0,this.rowHeaders.rows._dirty=!0,this.columnHeaders.columns._dirty=!0,this.columnHeaders.rows._dirty=!0},t.convertNumberToAlpha=function(e){var t,o,n="";if(e>=0)do{t=Math.floor(e/26),o=e%26,n=String.fromCharCode(o+65)+n,e=t-1}while(t);return n},t.prototype._updateFormulaForReorderingRows=function(e,t,o){void 0===o&&(o=!1);var n,i,l=o?e-t:t-e;this.beginUpdate();for(var s=0;s<this.columns.length;s++)if((n=this.getCellData(t,s,!1))&&"string"==typeof n&&"="===n[0]&&0!==l){try{i=this._calcEngine._parse(n)}catch(e){continue}i._updateCellRangeExpForReorderingRows(l)&&this.setCellData(t,s,"="+i._getStringExpression())}this.endUpdate()},t.prototype._updateFormulaForDropping=function(e){var t,n,i,l,s,r,a,h,d,c=[],u=[];for(this.beginUpdate(),i=0;i<this.sheets.length;i++)for(n=(t=this.sheets[i]).grid,l=0;l<n.rows.length;l++)for(r=0;r<n.columns.length;r++)(h=n.getCellData(l,r,!1))&&"string"==typeof h&&"="===h[0]&&(d=this._updateCellRefForDropping(h,i,e))&&(n.setCellData(l,r,d,!1),e&&i===this.selectedSheetIndex?(s=n.rows[l],a=n.columns[r],c.push({sheet:t,row:s,column:a,formula:h}),u.push({sheet:t,row:s,column:a,formula:d})):(c.push({sheet:t,point:new o.Point(l,r),formula:h}),u.push({sheet:t,point:new o.Point(l,r),formula:d})));return this.endUpdate(),{oldFormulas:c,newFormulas:u}},t.prototype._updateNamedRangesForDropping=function(e){var t,n,i,l,s=[],r=[];for(t=0;t<this.definedNames.length;t++)(i=(n=this.definedNames[t]).value)&&o.isString(i)&&(l=this._updateCellRefForDropping(i,this.selectedSheetIndex,e))&&(s.push({name:n.name,value:i}),n.value=l,r.push({name:n.name,value:l}));return{oldDefinedNameVals:s,newDefinedNameVals:r}},t.prototype._updateCellRefForDropping=function(e,t,o){void 0===o&&(o=!1);var n;try{n=this._calcEngine._parse(e)}catch(e){return null}return n._moveCellRangeExp(t,this._draggingCells,this._dropRange,o)?"="+n._getStringExpression():null},t.prototype._updateCellStyleForReorderingRows=function(e,t,o){var n,i,l=this.columns.length;for(n=0;n<l;n++)(i=this._getCellStyle(e,n))&&(o[t*l+n]=i)},t.prototype._scanFormulas=function(){for(var e=[],t=0;t<this.rows.length;t++)for(var n=0;n<this.columns.length;n++){var i=this.getCellData(t,n,!1);i&&o.isString(i)&&"="===i[0]&&e.push({row:t,column:n,formula:i})}return e},t.prototype._resetFormulas=function(e){var t=this;e&&t.deferUpdate(function(){for(var o=0;o<e.length;o++){var n=e[o];t.setCellData(n.row,n.column,n.formula)}})},t.prototype._getCellStyle=function(e,t,o){return(o=o||this.selectedSheet)?o.getCellStyle(e,t):null},t.prototype._validateSheetName=function(e){for(var t=0;t<this.sheets.length;t++)if(this.sheets[t].name===e)return!0;return!1},t.prototype._checkExistDefinedName=function(e,t,o){void 0===o&&(o=-1);for(var n=0;n<this.definedNames.length;n++)if(this.definedNames[n].name===e&&this.definedNames[n].sheetName===t&&n!==o)return!0;return!1},t.prototype._updateDefinedNameWithSheetRefUpdating=function(e,t){for(var o,n,i,l=0;l<this.definedNames.length;l++)if((o=this.definedNames[l]).sheetName===e&&null!=o.sheetName&&(o._sheetName=t),(n=o.value.match(/(\w+)\!\$?[A-Za-z]+\$?\d+/g))&&n.length>0)for(var s=0;s<n.length;s++)(i=n[s]).substring(0,i.indexOf("!"))===e&&(o.value=o.value.replace(i,i.replace(e,t)))},t.prototype._updateFormulasWithNameUpdating=function(e,t,o){void 0===o&&(o=!1);var n,i,l,s,r,a,h,d,c,u,_=this.selection.clone(),g=!1;for(u=o?/\[/:/\w/,this.selectedSheet._storeRowSettings(),this.beginUpdate(),n=0;n<this.sheets.length;n++)for(s=this.sheets[n].grid,i=0;i<s.rows.length;i++)for(l=0;l<s.columns.length;l++)if((r=s.getCellData(i,l,!1))&&"string"==typeof r&&"="===r[0]){for(g=!1,a=r.indexOf(e),c=new RegExp(e,"g");a>-1;)h="",d="",a>0&&(h=r[a-1]),a+e.length<r.length&&(d=r[a+e.length]),!/\w/.test(h)&&(o&&u.test(d)||!o&&!u.test(d))&&(r=r.replace(c,function(o,n){return n===a?t:e}),g=!0),a=r.indexOf(e,a+e.length);g&&s.setCellData(i,l,r,!1)}this.selection=_,this.endUpdate()},t.prototype._getDefinedNameIndexByName=function(e){for(var t=0;t<this.definedNames.length;t++)if(this.definedNames[t].name===e)return t;return-1},t.prototype._updateTablesForUpdatingRow=function(e,t,o){var n,i,l,s,r;if(this.selectedSheet.tables.length>0)for(n=this.selectedSheet.tables.length-1;n>=0;n--)if(i=this.selectedSheet.tables[n],l=i.getRange(),o)if((s=e+t-1)<l.topRow)i._updateTableRange(-t,-t,0,0);else if(s>=l.topRow&&s<=l.bottomRow)if(e<l.topRow)i.showHeaderRow&&(i._showHeaderRow=!1),i._updateTableRange(e-l.topRow,-t,0,0);else{if(e===l.topRow&&t===l.rowSpan){null==r&&(r=[]),r.push(i),this.selectedSheet.tables.remove(i);continue}e===l.topRow&&i.showHeaderRow&&(i._showHeaderRow=!1),s===l.bottomRow&&i.showTotalRow&&(i._showTotalRow=!1),i._updateTableRange(0,-t,0,0)}else e<=l.topRow?(null==r&&(r=[]),r.push(i),this.selectedSheet.tables.remove(i)):e<=l.bottomRow&&(i.showTotalRow&&(i._showTotalRow=!1),i._updateTableRange(0,e-l.bottomRow-1,0,0));else e<=l.topRow?i._updateTableRange(t,t,0,0):e>l.topRow&&e<=l.bottomRow&&i._updateTableRange(0,t,0,0);return r},t.prototype._updateTablesForUpdatingColumn=function(e,t,o){var n,i,l,s,r,a,h,d;if(this.selectedSheet.tables.length>0)for(n=this.selectedSheet.tables.length-1;n>=0;n--)if(i=this.selectedSheet.tables[n],l=i.getRange(),o)if((s=e+t-1)<l.leftCol)i._updateTableRange(0,0,-t,-t);else if(s>=l.leftCol&&s<=l.rightCol){if(e<l.leftCol)r=t-l.leftCol+e,a=l.leftCol,i._updateTableRange(0,0,e-l.leftCol,-t);else{if(e===l.leftCol&&t===l.columnSpan){null==d&&(d=[]),d.push(i),this.selectedSheet.tables.remove(i);continue}r=t,a=e,i._updateTableRange(0,0,0,-r)}i._columns.splice(a-l.leftCol,r)}else e<=l.leftCol?(null==d&&(d=[]),d.push(i),this.selectedSheet.tables.remove(i)):e<=l.rightCol&&(r=l.rightCol-e+1,i._updateTableRange(0,0,0,-r),i._columns.splice(e,r));else if(e<=l.leftCol)i._updateTableRange(0,0,t,t);else if(e>l.leftCol&&e<=l.rightCol)for(i._updateTableRange(0,0,0,t),a=e-l.leftCol,h=0;h<t;h++)i._addColumn(a+h);return d},t.prototype._isDisableDeleteRow=function(e,t){var o,n,i;if(this.selectedSheet.tables.length>0)for(o=0;o<this.selectedSheet.tables.length;o++)if(n=this.selectedSheet.tables[o],i=n.getRange(),n.showHeaderRow&&i.topRow>=e&&i.topRow<=t)return!0;return!1},t.prototype._copy=function(t,o){var n,i;if("columns"==t){if(e.prototype._copy.call(this,t,o),this.itemsSource&&(n=this.rows[0])instanceof G){n._ubv=null,n._ubv={};for(var l=0;l<this.columns.length;l++)i=this.columns[l],n._ubv[i._hash]=i.header}return!0}return!1},t.prototype._getTableSheetIndex=function(e,t){this.sheets;for(var o=0;o<e.length;o++)if(e[o].indexOf(t)>-1)return o;return-1},t.prototype._sheetSortConverter=function(t,n,i,l){return i=e.prototype._sortConverter.call(this,t,n,i,l),o.isString(i)&&i.length>0&&"="===i[0]&&(i=this.evaluate(i)),i},t.prototype._formatEvaluatedResult=function(e,t,n){return o.isPrimitive(e)?(t.dataMap&&(e=t.dataMap.getDisplayValue(e)),!o.isInt(e)||t.format||t.dataMap||n?((n||t.format)&&o.isString(e)&&(+e).toString()===e&&(e=+e),e=null!=e?o.Globalize.format(e,n||t.format):""):e=e.toString()):e&&(!o.isInt(e.value)||t.format||t.dataMap||n||e.format?(o.isString(e.value)&&(+e.value).toString()===e.value&&(e.value=+e.value),e=null!=e.value?o.Globalize.format(e.value,n||e.format||t.format):""):e=e.value.toString()),e},t.prototype._updateCellRef=function(e,t,o,n,i,l){var s;try{s=this._calcEngine._parse(e)}catch(e){return null}return s._updateCellRangeExp(t,o,n,i,l)?"="+s._getStringExpression():null},t.prototype._copyRowsToSelectedSheet=function(){var e,t=this;if(t.selectedSheet){for(t.selectedSheet.grid.rows.clear(),e=0;e<t.rows.length;e++)t.selectedSheet.grid.rows.push(t.rows[e]);setTimeout(function(){t._setFlexSheetToDirty(),t.invalidate()},10)}},t.prototype._copyColumnsToSelectedSheet=function(){var e,t=this;if(t.selectedSheet){for(t.selectedSheet.grid.columns.clear(),e=0;e<t.columns.length;e++)t.selectedSheet.grid.columns.push(t.columns[e]);setTimeout(function(){t._setFlexSheetToDirty(),t.invalidate()},10)}},t.prototype._getUniqueColumnName=function(){for(var e=1;null!=this.columns.getColumn("col"+e);)e++;return"col"+e},t.prototype._parseFromWorkbookTable=function(e,t){var o,l,s,r,a,h,d,c,u,_,g,f=t===this.selectedSheet?this:t.grid;if(l=e.range.split(":"),s=l[0],r=l[1],a=n.Workbook.tableAddress(s),o=new i.CellRange(a.row,a.col),h=n.Workbook.tableAddress(r),o.row2=h.row,o.col2=h.col,o.bottomRow>=t.rowCount)for(g=o.bottomRow-t.rowCount+1,p=0;p<g;p++)f.rows.push(new i.Row);if(o.rightCol>=t.columnCount)for(g=o.rightCol-t.columnCount+1,p=0;p<g;p++)f.columns.push(new i.Column);if(e.columns&&e.columns.length>0){d=[];for(var p=0;p<e.columns.length;p++)c=e.columns[p],d[p]=new te(c.name,c.totalRowLabel,c.totalRowFunction,c.showFilterButton)}return null!=e.style&&(u=this._isBuiltInStyleName(e.style.name)?this.getBuiltInTableStyle(e.style.name):this._parseFromWorkbookTableStyle(e.style)),_=new ee(e.name,o,u,d,{showHeaderRow:e.showHeaderRow,showTotalRow:e.showTotalRow,showBandedColumns:e.showBandedColumns,showBandedRows:e.showBandedRows,alterFirstColumn:e.alterFirstColumn,alterLastColumn:e.alterLastColumn}),t.tables.push(_),_},t.prototype._parseFromWorkbookTableStyle=function(e){var t=new oe(e.name);return null!=e.firstBandedColumnStyle&&(t.firstBandedColumnStyle=this._parseFromWorkbookTableStyleElement(e.firstBandedColumnStyle)),null!=e.firstBandedRowStyle&&(t.firstBandedRowStyle=this._parseFromWorkbookTableStyleElement(e.firstBandedRowStyle)),null!=e.firstColumnStyle&&(t.firstColumnStyle=this._parseFromWorkbookTableStyleElement(e.firstColumnStyle)),null!=e.firstHeaderCellStyle&&(t.firstHeaderCellStyle=this._parseFromWorkbookTableStyleElement(e.firstHeaderCellStyle)),null!=e.firstTotalCellStyle&&(t.firstTotalCellStyle=this._parseFromWorkbookTableStyleElement(e.firstTotalCellStyle)),null!=e.headerRowStyle&&(t.headerRowStyle=this._parseFromWorkbookTableStyleElement(e.headerRowStyle)),null!=e.lastColumnStyle&&(t.lastColumnStyle=this._parseFromWorkbookTableStyleElement(e.lastColumnStyle)),null!=e.lastHeaderCellStyle&&(t.lastHeaderCellStyle=this._parseFromWorkbookTableStyleElement(e.lastHeaderCellStyle)),null!=e.lastTotalCellStyle&&(t.lastTotalCellStyle=this._parseFromWorkbookTableStyleElement(e.lastTotalCellStyle)),null!=e.secondBandedColumnStyle&&(t.secondBandedColumnStyle=this._parseFromWorkbookTableStyleElement(e.secondBandedColumnStyle)),null!=e.secondBandedRowStyle&&(t.secondBandedRowStyle=this._parseFromWorkbookTableStyleElement(e.secondBandedRowStyle)),null!=e.totalRowStyle&&(t.totalRowStyle=this._parseFromWorkbookTableStyleElement(e.totalRowStyle)),null!=e.wholeTableStyle&&(t.wholeTableStyle=this._parseFromWorkbookTableStyleElement(e.wholeTableStyle)),t},t.prototype._parseFromWorkbookTableStyleElement=function(e){var t;return t={fontWeight:e.font&&e.font.bold?"bold":"none",fontStyle:e.font&&e.font.italic?"italic":"none",textDecoration:e.font&&e.font.underline?"underline":"none",fontFamily:e.font&&e.font.family?e.font.family:"",fontSize:e.font&&e.font.size?e.font.size+"px":"",color:e.font&&e.font.color?e.font.color:"",backgroundColor:e.fill&&e.fill.color?e.fill.color:""},e.borders&&(e.borders.left&&(s.FlexGridXlsxConverter._parseBorderStyle(e.borders.left.style,"Left",t),t.borderLeftColor=e.borders.left.color),e.borders.right&&(s.FlexGridXlsxConverter._parseBorderStyle(e.borders.right.style,"Right",t),t.borderRightColor=e.borders.right.color),e.borders.top&&(s.FlexGridXlsxConverter._parseBorderStyle(e.borders.top.style,"Top",t),t.borderTopColor=e.borders.top.color),e.borders.bottom&&(s.FlexGridXlsxConverter._parseBorderStyle(e.borders.bottom.style,"Bottom",t),t.borderBottomColor=e.borders.bottom.color),e.borders.vertical&&(s.FlexGridXlsxConverter._parseBorderStyle(e.borders.vertical.style,"Vertical",t),t.borderVerticalColor=e.borders.vertical.color),e.borders.horizontal&&(s.FlexGridXlsxConverter._parseBorderStyle(e.borders.horizontal.style,"Horizontal",t),t.borderHorizontalColor=e.borders.horizontal.color)),null!=e.size&&(t.size=e.size),t},t.prototype._parseToWorkbookTable=function(e){var t,o,i=new n.WorkbookTable,l=e.getRange(),s=e.getColumns();i.name=e.name,t=n.Workbook.xlsxAddress(l.topRow,l.leftCol),o=n.Workbook.xlsxAddress(l.bottomRow,l.rightCol),i.range=t+":"+o,null!=e.style&&(e.style.isBuiltIn?(i.style=new n.WorkbookTableStyle,i.style.name=e.style.name):i.style=this._parseToWorkbookTableStyle(e.style)),i.showBandedColumns=e.showBandedColumns,i.showBandedRows=e.showBandedRows,i.showHeaderRow=e.showHeaderRow,i.showTotalRow=e.showTotalRow,i.alterFirstColumn=e.alterFirstColumn,i.alterLastColumn=e.alterLastColumn;for(var r=0;r<s.length;r++){var a=s[r],h=new n.WorkbookTableColumn;h.name=a.name,h.totalRowLabel=a.totalRowLabel,h.totalRowFunction=a.totalRowFunction,h.showFilterButton=a.showFilterButton,i.columns.push(h)}return i},t.prototype._parseToWorkbookTableStyle=function(e){var t=new n.WorkbookTableStyle;return t.name=e.name,null!=e.firstBandedColumnStyle&&(t.firstBandedColumnStyle=this._parseToWorkbookTableStyleElement(e.firstBandedColumnStyle,!0)),null!=e.firstBandedRowStyle&&(t.firstBandedRowStyle=this._parseToWorkbookTableStyleElement(e.firstBandedRowStyle,!0)),null!=e.firstColumnStyle&&(t.firstColumnStyle=this._parseToWorkbookTableStyleElement(e.firstColumnStyle)),null!=e.firstHeaderCellStyle&&(t.firstHeaderCellStyle=this._parseToWorkbookTableStyleElement(e.firstHeaderCellStyle)),null!=e.firstTotalCellStyle&&(t.firstTotalCellStyle=this._parseToWorkbookTableStyleElement(e.firstTotalCellStyle)),null!=e.headerRowStyle&&(t.headerRowStyle=this._parseToWorkbookTableStyleElement(e.headerRowStyle)),null!=e.lastColumnStyle&&(t.lastColumnStyle=this._parseToWorkbookTableStyleElement(e.lastColumnStyle)),null!=e.lastHeaderCellStyle&&(t.lastHeaderCellStyle=this._parseToWorkbookTableStyleElement(e.lastHeaderCellStyle)),null!=e.lastTotalCellStyle&&(t.lastTotalCellStyle=this._parseToWorkbookTableStyleElement(e.lastTotalCellStyle)),null!=e.secondBandedColumnStyle&&(t.secondBandedColumnStyle=this._parseToWorkbookTableStyleElement(e.secondBandedColumnStyle,!0)),null!=e.secondBandedRowStyle&&(t.secondBandedRowStyle=this._parseToWorkbookTableStyleElement(e.secondBandedRowStyle,!0)),null!=e.totalRowStyle&&(t.totalRowStyle=this._parseToWorkbookTableStyleElement(e.totalRowStyle)),null!=e.wholeTableStyle&&(t.wholeTableStyle=this._parseToWorkbookTableStyleElement(e.wholeTableStyle)),t},t.prototype._parseToWorkbookTableStyleElement=function(e,t){void 0===t&&(t=!1);var o,i=s.FlexGridXlsxConverter._parseCellStyle(e,!0);return t?(o=new n.WorkbookTableBandedStyle).size=e.size:o=new n.WorkbookTableCommonStyle,o._deserialize(i),o},t.prototype._isBuiltInStyleName=function(e){var t;if(0===e.search(/TableStyleLight/i)){if(t=+e.substring(15),!isNaN(t)&&t>=1&&t<=21)return!0}else if(0===e.search(/TableStyleMedium/i)){if(t=+e.substring(16),!isNaN(t)&&t>=1&&t<=28)return!0}else if(0===e.search(/TableStyleDark/i)&&(t=+e.substring(14),!isNaN(t)&&t>=1&&t<=11))return!0;return!1},t.prototype._getTable=function(e){for(var t,o,n,i=0;i<this.sheets.length;i++)for(o=this.sheets[i].tables,n=0;n<o.length;n++)if((t=o[n]).name.toLowerCase()===e.toLowerCase())return t;return null},t.prototype._isTableColumnRef=function(e,t){return new RegExp("\\[(\\s*@)?"+t+"\\]","i").test(e)},t.prototype._getThemeColor=function(e,t){var n,i,l=this._colorThemes[e];return null!=t?(n=new o.Color("#"+l),i=n.getHsl(),i[2]=t<0?i[2]*(1+t):i[2]*(1-t)+(1-1*(1-t)),(n=o.Color.fromHsl(i[0],i[1],i[2])).toString()):"#"+l},t.prototype._createBuiltInTableStyle=function(e){var t;if(0===e.search(/TableStyleLight/i)){if(t=+e.substring(15),!isNaN(t)&&t>=1&&t<=21)return t<=7?this._generateTableLightStyle1(t-1,e,!0):t<=14?this._generateTableLightStyle2(t-8,e):this._generateTableLightStyle1(t-15,e,!1)}else if(0===e.search(/TableStyleMedium/i)){if(t=+e.substring(16),!isNaN(t)&&t>=1&&t<=28)return t<=7?this._generateTableMediumStyle1(t-1,e):t<=14?this._generateTableMediumStyle2(t-8,e):t<=21?this._generateTableMediumStyle3(t-15,e):this._generateTableMediumStyle4(t-22,e)}else if(0===e.search(/TableStyleDark/i)&&(t=+e.substring(14),!isNaN(t)&&t>=1&&t<=11))return t<=7?this._generateTableDarkStyle1(t-1,e):this._generateTableDarkStyle2(t-8,e);return null},t.prototype._generateTableLightStyle1=function(e,t,o){var n=new oe(t,!0),i=0===e?1:e+3,l=o?"1px":"2px",s=o?"solid":"double",r=o?"1px":"3px";return n.wholeTableStyle={borderTopColor:this._getThemeColor(i),borderTopStyle:"solid",borderTopWidth:"1px",borderBottomColor:this._getThemeColor(i),borderBottomStyle:"solid",borderBottomWidth:"1px"},n.firstColumnStyle={fontWeight:"bold"},n.lastColumnStyle={fontWeight:"bold"},n.headerRowStyle={borderBottomColor:this._getThemeColor(i),borderBottomStyle:"solid",borderBottomWidth:l,fontWeight:"bold"},n.totalRowStyle={borderTopColor:this._getThemeColor(i),borderTopStyle:s,borderTopWidth:r,fontWeight:"bold"},0===e?(n.wholeTableStyle.color=this._getThemeColor(i),n.firstColumnStyle.color=this._getThemeColor(i),n.lastColumnStyle.color=this._getThemeColor(i),n.headerRowStyle.color=this._getThemeColor(i),n.totalRowStyle.color=this._getThemeColor(i),n.firstBandedRowStyle={backgroundColor:this._getThemeColor(0,-.15)},n.firstBandedColumnStyle={backgroundColor:this._getThemeColor(0,-.15)}):(o?(n.wholeTableStyle.color=this._getThemeColor(i,-.25),n.firstColumnStyle.color=this._getThemeColor(i,-.25),n.lastColumnStyle.color=this._getThemeColor(i,-.25),n.headerRowStyle.color=this._getThemeColor(i,-.25),n.totalRowStyle.color=this._getThemeColor(i,-.25)):(n.wholeTableStyle.color=this._getThemeColor(1),n.firstColumnStyle.color=this._getThemeColor(1),n.lastColumnStyle.color=this._getThemeColor(1),n.headerRowStyle.color=this._getThemeColor(1),n.totalRowStyle.color=this._getThemeColor(1)),n.firstBandedRowStyle={backgroundColor:this._getThemeColor(i,.8)},n.firstBandedColumnStyle={backgroundColor:this._getThemeColor(i,.8)}),o||(n.wholeTableStyle.borderLeftColor=this._getThemeColor(i),n.wholeTableStyle.borderLeftStyle="solid",n.wholeTableStyle.borderLeftWidth="1px",n.wholeTableStyle.borderRightColor=this._getThemeColor(i),n.wholeTableStyle.borderRightStyle="solid",n.wholeTableStyle.borderRightWidth="1px",n.wholeTableStyle.borderHorizontalColor=this._getThemeColor(i),n.wholeTableStyle.borderHorizontalStyle="solid",n.wholeTableStyle.borderHorizontalWidth="1px",n.wholeTableStyle.borderVerticalColor=this._getThemeColor(i),n.wholeTableStyle.borderVerticalStyle="solid",n.wholeTableStyle.borderVerticalWidth="1px"),n},t.prototype._generateTableLightStyle2=function(e,t){var o=new oe(t,!0),n=0===e?1:e+3;return o.wholeTableStyle={borderTopColor:this._getThemeColor(n),borderTopStyle:"solid",borderTopWidth:"1px",borderBottomColor:this._getThemeColor(n),borderBottomStyle:"solid",borderBottomWidth:"1px",borderLeftColor:this._getThemeColor(n),borderLeftStyle:"solid",borderLeftWidth:"1px",borderRightColor:this._getThemeColor(n),borderRightStyle:"solid",borderRightWidth:"1px",color:this._getThemeColor(1)},o.firstBandedRowStyle={borderTopColor:this._getThemeColor(n),borderTopStyle:"solid",borderTopWidth:"1px"},o.secondBandedRowStyle={borderTopColor:this._getThemeColor(n),borderTopStyle:"solid",borderTopWidth:"1px"},o.firstBandedColumnStyle={borderLeftColor:this._getThemeColor(n),borderLeftStyle:"solid",borderLeftWidth:"1px"},o.secondBandedColumnStyle={borderLeftColor:this._getThemeColor(n),borderLeftStyle:"solid",borderLeftWidth:"1px"},o.firstColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.lastColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.headerRowStyle={backgroundColor:this._getThemeColor(n),fontWeight:"bold",color:this._getThemeColor(0)},o.totalRowStyle={borderTopColor:this._getThemeColor(n),borderTopStyle:"double",borderTopWidth:"3px",fontWeight:"bold",color:this._getThemeColor(1)},o},t.prototype._generateTableMediumStyle1=function(e,t){var o=new oe(t,!0),n=0===e?1:e+3;return o.wholeTableStyle={borderTopStyle:"solid",borderTopWidth:"1px",borderBottomStyle:"solid",borderBottomWidth:"1px",borderLeftStyle:"solid",borderLeftWidth:"1px",borderRightStyle:"solid",borderRightWidth:"1px",borderHorizontalStyle:"solid",borderHorizontalWidth:"1px",color:this._getThemeColor(1)},0===e?(o.wholeTableStyle.borderTopColor=this._getThemeColor(n),o.wholeTableStyle.borderBottomColor=this._getThemeColor(n),o.wholeTableStyle.borderLeftColor=this._getThemeColor(n),o.wholeTableStyle.borderRightColor=this._getThemeColor(n),o.wholeTableStyle.borderHorizontalColor=this._getThemeColor(n),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(0,-.15)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(0,-.15)}):(o.wholeTableStyle.borderTopColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderBottomColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderLeftColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderRightColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderHorizontalColor=this._getThemeColor(n,.4),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(n,.8)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(n,.8)}),o.firstColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.lastColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.headerRowStyle={backgroundColor:this._getThemeColor(n),fontWeight:"bold",color:this._getThemeColor(0)},o.totalRowStyle={borderTopColor:this._getThemeColor(n),borderTopStyle:"double",borderTopWidth:"3px",fontWeight:"bold",color:this._getThemeColor(1)},o},t.prototype._generateTableMediumStyle2=function(e,t){var o=new oe(t,!0),n=0===e?1:e+3;return o.wholeTableStyle={borderVerticalStyle:"solid",borderVerticalWidth:"1px",borderVerticalColor:this._getThemeColor(0),borderHorizontalStyle:"solid",borderHorizontalWidth:"1px",borderHorizontalColor:this._getThemeColor(0),color:this._getThemeColor(1)},0===e?(o.wholeTableStyle.backgroundColor=this._getThemeColor(0,-.15),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(0,-.35)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(0,-.35)}):(o.wholeTableStyle.backgroundColor=this._getThemeColor(n,.8),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(n,.6)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(n,.6)}),o.firstColumnStyle={fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(n)},o.lastColumnStyle={fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(n)},o.headerRowStyle={borderBottomColor:this._getThemeColor(0),borderBottomStyle:"solid",borderBottomWidth:"3px",backgroundColor:this._getThemeColor(n),fontWeight:"bold",color:this._getThemeColor(0)},o.totalRowStyle={borderTopColor:this._getThemeColor(0),borderTopStyle:"solid",borderTopWidth:"3px",backgroundColor:this._getThemeColor(n),fontWeight:"bold",color:this._getThemeColor(0)},o},t.prototype._generateTableMediumStyle3=function(e,t){var o=new oe(t,!0),n=0===e?1:e+3;return o.wholeTableStyle={borderTopStyle:"solid",borderTopWidth:"2px",borderTopColor:this._getThemeColor(1),borderBottomStyle:"solid",borderBottomWidth:"2px",borderBottomColor:this._getThemeColor(1),color:this._getThemeColor(1)},0===e&&(o.wholeTableStyle.borderLeftColor=this._getThemeColor(1),o.wholeTableStyle.borderLeftStyle="solid",o.wholeTableStyle.borderLeftWidth="1px",o.wholeTableStyle.borderRightColor=this._getThemeColor(1),o.wholeTableStyle.borderRightStyle="solid",o.wholeTableStyle.borderRightWidth="1px",o.wholeTableStyle.borderVerticalColor=this._getThemeColor(1),o.wholeTableStyle.borderVerticalStyle="solid",o.wholeTableStyle.borderVerticalWidth="1px",o.wholeTableStyle.borderHorizontalColor=this._getThemeColor(1),o.wholeTableStyle.borderHorizontalStyle="solid",o.wholeTableStyle.borderHorizontalWidth="1px"),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(0,-.35)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(0,-.35)},o.firstColumnStyle={fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(n)},o.lastColumnStyle={fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(n)},o.headerRowStyle={borderBottomColor:this._getThemeColor(1),borderBottomStyle:"solid",borderBottomWidth:"2px",backgroundColor:this._getThemeColor(n),fontWeight:"bold",color:this._getThemeColor(0)},o.totalRowStyle={borderTopColor:this._getThemeColor(1),borderTopStyle:"double",borderTopWidth:"3px"},o},t.prototype._generateTableMediumStyle4=function(e,t){var o=new oe(t,!0),n=0===e?1:e+3;return o.wholeTableStyle={borderTopStyle:"solid",borderTopWidth:"1px",borderBottomStyle:"solid",borderBottomWidth:"1px",borderLeftStyle:"solid",borderLeftWidth:"1px",borderRightStyle:"solid",borderRightWidth:"1px",borderVerticalStyle:"solid",borderVerticalWidth:"1px",borderHorizontalStyle:"solid",borderHorizontalWidth:"1px",color:this._getThemeColor(1)},0===e?(o.wholeTableStyle.borderTopColor=this._getThemeColor(n),o.wholeTableStyle.borderBottomColor=this._getThemeColor(n),o.wholeTableStyle.borderLeftColor=this._getThemeColor(n),o.wholeTableStyle.borderRightColor=this._getThemeColor(n),o.wholeTableStyle.borderVerticalColor=this._getThemeColor(n),o.wholeTableStyle.borderHorizontalColor=this._getThemeColor(n),o.wholeTableStyle.backgroundColor=this._getThemeColor(0,-.15),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(0,-.35)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(0,-.35)}):(o.wholeTableStyle.borderTopColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderBottomColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderLeftColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderRightColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderVerticalColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderHorizontalColor=this._getThemeColor(n,.4),o.wholeTableStyle.backgroundColor=this._getThemeColor(n,.8),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(n,.6)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(n,.6)}),o.firstColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.lastColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.headerRowStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.totalRowStyle={borderTopColor:this._getThemeColor(n),borderTopStyle:"solid",borderTopWidth:"2px",fontWeight:"bold",color:this._getThemeColor(1)},o},t.prototype._generateTableDarkStyle1=function(e,t){var o=new oe(t,!0),n=0===e?1:e+3,i=0===e?.25:-.25;return o.wholeTableStyle={color:this._getThemeColor(0)},o.firstBandedRowStyle={backgroundColor:this._getThemeColor(n,i)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(n,i)},o.firstColumnStyle={borderRightColor:this._getThemeColor(0),borderRightStyle:"solid",borderRightWidth:"2px",fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(n,i)},o.lastColumnStyle={borderLeftColor:this._getThemeColor(0),borderLeftStyle:"solid",borderLeftWidth:"2px",fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(n,i)},o.headerRowStyle={borderBottomColor:this._getThemeColor(0),borderBottomStyle:"solid",borderBottomWidth:"2px",fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(1)},o.totalRowStyle={borderTopColor:this._getThemeColor(0),borderTopStyle:"solid",borderTopWidth:"2px",fontWeight:"bold",color:this._getThemeColor(0)},0===e?(o.wholeTableStyle.backgroundColor=this._getThemeColor(n,.5),o.totalRowStyle.backgroundColor=this._getThemeColor(n,.15)):(o.wholeTableStyle.backgroundColor=this._getThemeColor(n),o.totalRowStyle.backgroundColor=this._getThemeColor(n,-.5)),o},t.prototype._generateTableDarkStyle2=function(e,t){var o=new oe(t,!0),n=0===e?0:2*e+2,i=0===e?1:2*e+3,l=0===e?-.15:.8;return o.wholeTableStyle={backgroundColor:this._getThemeColor(n,l)},o.firstBandedRowStyle={backgroundColor:this._getThemeColor(n,l-.2)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(n,l-.2)},o.firstColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.lastColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.headerRowStyle={color:this._getThemeColor(0),backgroundColor:this._getThemeColor(i)},o.totalRowStyle={borderTopColor:this._getThemeColor(1),borderTopStyle:"double",borderTopWidth:"3px",fontWeight:"bold",color:this._getThemeColor(1)},o},t.controlTemplate='<div style="width:100%;height:100%"><div wj-part="container" style="width:100%">'+i.FlexGrid.controlTemplate+'</div><div wj-part="tab-holder" class="wj-tabholder" style="width:100%; min-width:100px"></div><div wj-part="context-menu" style="display:none;z-index:100"></div></div>',t}(i.FlexGrid);t.FlexSheet=O;var B=function(e){function t(t,o){var n=e.call(this)||this;return n._isDraggingRows=t,n._isShiftKey=o,n}return __extends(t,e),Object.defineProperty(t.prototype,"isDraggingRows",{get:function(){return this._isDraggingRows},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isShiftKey",{get:function(){return this._isShiftKey},enumerable:!0,configurable:!0}),t}(o.EventArgs);t.DraggingRowColumnEventArgs=B;var j=function(e){function t(t,o){var n=e.call(this)||this;return n._funcName=t,n._params=o,n}return __extends(t,e),Object.defineProperty(t.prototype,"funcName",{get:function(){return this._funcName},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"params",{get:function(){return this._params},enumerable:!0,configurable:!0}),t}(o.EventArgs);t.UnknownFunctionEventArgs=j;var U=function(e){function t(t,o,n){var i=e.call(this)||this;return i._index=t,i._count=o,i._added=n,i}return __extends(t,e),Object.defineProperty(t.prototype,"index",{get:function(){return this._index},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"count",{get:function(){return this._count},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"added",{get:function(){return this._added},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isAdd",{get:function(){return o._deprecated("RowColumnChangedEventArgs.isAdd","RowColumnChangedEventArgs.added"),this._added},enumerable:!0,configurable:!0}),t}(o.EventArgs);t.RowColumnChangedEventArgs=U;var z=function(e){function t(t,o,n,i,l){return e.call(this,t,o,n,i,l)||this}return __extends(t,e),t.prototype.getSelectedState=function(t,o,n){var l,s,r,a,h,d;if(this.grid){if(d=this.grid.getMergedRange(this,t,o),l=this.grid.selectedSheet?this.grid.selectedSheet.selectionRanges:null,h=e.prototype.getSelectedState.call(this,t,o,n),s=l?l.length:0,h===i.SelectedState.None&&s>0)for(r=0;r<l.length;r++)if((a=l[r])&&a instanceof i.CellRange){if(this.cellType===i.CellType.Cell){if(d){if(d.contains(a.row,a.col))return r!==s-1||this.grid._isClicking?i.SelectedState.Selected:this.grid.showMarquee?i.SelectedState.None:i.SelectedState.Cursor;if(d.intersects(a))return i.SelectedState.Selected}if(a.row===t&&a.col===o)return r!==s-1||this.grid._isClicking?i.SelectedState.Selected:this.grid.showMarquee?i.SelectedState.None:i.SelectedState.Cursor;if(a.contains(t,o))return i.SelectedState.Selected}if(this.grid.showSelectedHeaders&i.HeadersVisibility.Row&&this.cellType===i.CellType.RowHeader&&a.containsRow(t))return i.SelectedState.Selected;if(this.grid.showSelectedHeaders&i.HeadersVisibility.Column&&this.cellType===i.CellType.ColumnHeader&&a.containsColumn(o))return i.SelectedState.Selected}return h}},t.prototype.getCellData=function(t,n,i){var l,s,r,a,h;if(o.isString(n)&&(n=this.columns.indexOf(n))<0)throw"Invalid column name or binding.";return t>=this.rows.length||o.asNumber(n,!1,!0)>=this.columns.length?null:(l=e.prototype.getCellData.call(this,t,n,i),s=this.columns[o.asNumber(n,!1,!0)],r=this.grid?this.grid._getBindingColumn(this,t,s):s,i&&(h=e.prototype.getCellData.call(this,t,n,!1),a=this.grid?this.grid._getCellStyle(t,n):null,!o.isNumber(h)||0===h||!r||r.format||r.dataMap||a||(l=h.toString())),l)},t.prototype.setCellData=function(t,n,i,l,s){if(void 0===l&&(l=!0),void 0===s&&(s=!0),t>=this.rows.length||n>=this.columns.length)return!1;var r,a=this.getCellData(t,n,!1),h=this.grid._isPasting;return l&&i&&o.isString(i)&&"'"!==i[0]&&(this.grid.columns[n].dataType===o.DataType.String||o.isNullOrWhiteSpace(i)||isNaN(+i)?this.grid.columns[n].dataType===o.DataType.Boolean?i=o.changeType(i,o.DataType.Boolean,null):"="!==i[0]&&(r=o.Globalize.parseDate(i,""))&&(i=r):i===(+i).toString()?i=+i:l=!1),(i&&o.isString(i)&&("="===i[0]||"'"===i[0])||o.isString(a))&&(l=!1),e.prototype.setCellData.call(this,t,n,i,l&&!h,s)},t.prototype._renderCell=function(t,n,l,s,r,a){var h,d,c,u,_=n*this.grid.columns.length+l,g=this.grid.getMergedRange(this,n,l);return u=e.prototype._renderCell.call(this,t,n,l,s,r,a),this.cellType!==i.CellType.Cell?u:g&&_>g.topRow*this.grid.columns.length+g.leftCol?u:((h=t.childNodes[a])&&(null!=this.grid.editRange&&this.grid.editRange.contains(n,l)||this.grid.selectedSheet&&(c=this.grid.selectedSheet.findTable(n,l))&&c._updateCell(n,l,h),o.hasClass(h,"wj-state-selected")||o.hasClass(h,"wj-state-multi-selected")?(h.style.backgroundColor="",h.style.color=""):this.grid.selectedSheet&&(d=this.grid.selectedSheet._styledCells[_])&&(""!==d.backgroundColor&&(h.style.backgroundColor=d.backgroundColor),""!==d.color&&(h.style.color=d.color))),u)},t}(i.GridPanel);t.FlexSheetPanel=z;var G=function(e){function t(){var t=e.call(this)||this;return t.isReadOnly=!0,t}return __extends(t,e),t}(i.Row);t.HeaderRow=G;var q=function(){function e(e,t,o,n){if(this._owner=e,this._name=t,this._value=o,null!=n){if(!e._validateSheetName(n))throw"The sheet name:("+n+") does not exist in FlexSheet.";this._sheetName=n}}return Object.defineProperty(e.prototype,"name",{get:function(){return this._name},set:function(e){var t;if(this._name!==e){if(this._owner._checkExistDefinedName(name,this._sheetName))throw"The "+name+" already existed in definedNames.";t=this._name,this._name=e,this._owner._updateFormulasWithNameUpdating(t,this._name)}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this._value},set:function(e){this._value!==e&&(this._value=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"sheetName",{get:function(){return this._sheetName},enumerable:!0,configurable:!0}),e}();t.DefinedName=q;var K=function(){function e(e,t,n,i,l){this._visible=!0,this._unboundSortDesc=new o.ObservableArray,this._currentStyledCells={},this._currentMergedRanges=[],this._isEmptyGrid=!1,this._rowSettings=[],this._scrollPosition=new o.Point,this._freezeHiddenRowCnt=0,this._freezeHiddenColumnCnt=0,this._showDefaultHeader=!1,this.nameChanged=new o.Event,this.visibleChanged=new o.Event;var s=this;s._owner=e,s._name=n,s._sortList=[new J(-1,!0)],o.isNumber(i)&&!isNaN(i)&&i>=0?s._rowCount=i:s._rowCount=200,o.isNumber(l)&&!isNaN(l)&&l>=0?s._columnCount=l:s._columnCount=20,t?(s._showDefaultHeader=!0,s._grid=t):s._grid=this._createGrid(),s._grid.loadedRows.addHandler(function(){s._addHeaderRow(),s._setRowSettings()}),s._grid.itemsSourceChanged.addHandler(this._gridItemsSourceChanged,this),s._addHeaderRow(),s._unboundSortDesc.collectionChanged.addHandler(function(){var e,t,n=s._unboundSortDesc,i={};for(e=0;e<n.length;e++)if(!o.tryCast(n[e],Y))throw"sortDescriptions array must contain SortDescription objects.";if(s._owner){if(s._owner.rows.beginUpdate(),s._owner.rows.sort(s._compareRows()),!s._owner._isUndoing){for(e=0;e<s._owner.rows.length;e++)e!==(t=s._owner.rows[e])._idx&&s._owner._updateFormulaForReorderingRows(t._idx,e),s._owner._updateCellStyleForReorderingRows(t._idx,e,i);s._currentStyledCells=i}s._owner.rows.endUpdate(),s._owner.rows._dirty=!0,s._owner.rows._update(),s._owner.selectedSheet&&(s._owner._copyTo(s._owner.selectedSheet),s._owner._copyFrom(s._owner.selectedSheet))}}),s.tables.collectionChanged.addHandler(function(e,t){if(null!=t.item&&!(t.item instanceof ee))throw"The tables only allows to handle Table instance.";if(t.action===o.NotifyCollectionChangedAction.Add||t.action===o.NotifyCollectionChangedAction.Change){if(t.item){var n=void 0,i=void 0,l=t.item,r=l.getRange(),a=s===s._owner.selectedSheet?s._owner:s.grid;try{if(r.topRow>=a.rows.length||r.leftCol>=a.columns.length)throw"";if(r.leftCol+r.columnSpan>a.columns.length)throw"";if(r.topRow+r.rowSpan>a.rows.length)throw"";for(n=r.topRow;n<=r.bottomRow;n++)for(i=r.leftCol;i<=r.rightCol;i++)if(s.findTable(n,i)!==l)throw"";l._attachSheet(s)}catch(e){s.tables.removeAt(t.index)}}}else t.action===o.NotifyCollectionChangedAction.Remove&&t.item&&t.item._detachSheet()})}return Object.defineProperty(e.prototype,"grid",{get:function(){return null==this._grid.wj_sheetInfo&&(this._grid.wj_sheetInfo={}),this._grid},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"name",{get:function(){return this._name},set:function(e){if(!o.isNullOrWhiteSpace(e)&&(this._name&&this._name.toLowerCase()!==e.toLowerCase()||!this._name)){var t=new o.PropertyChangedEventArgs("sheetName",this._name,e);this._name=e,this.grid.wj_sheetInfo.name=e,this.onNameChanged(t)}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"visible",{get:function(){return this._visible},set:function(e){this._visible!==e&&(this._visible=e,this.grid.wj_sheetInfo.visible=e,this.onVisibleChanged(new o.EventArgs))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rowCount",{get:function(){return null!=this._grid?this._grid.rows.length:0},set:function(e){var t;if(!this.itemsSource&&o.isNumber(e)&&!isNaN(e)&&e>=0&&this._rowCount!==e){if(this._rowCount<e)for(t=0;t<e-this._rowCount;t++)this.grid.rows.push(new i.Row);else this.grid.rows.splice(e,this._rowCount-e);this._rowCount=e,this._owner&&this._owner.selectedSheet&&this._name===this._owner.selectedSheet.name&&this._owner._copyFrom(this,!0)}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"columnCount",{get:function(){return null!=this._grid?this._grid.columns.length:0},set:function(e){var t;if(!this.itemsSource&&o.isNumber(e)&&!isNaN(e)&&e>=0&&this._columnCount!==e){if(this._columnCount<e)for(t=0;t<e-this._columnCount;t++)this._grid.columns.push(new i.Column);else this._grid.columns.splice(e,this._columnCount-e);this._columnCount=e,this._owner&&this._owner.selectedSheet&&this._name===this._owner.selectedSheet.name&&this._owner._copyFrom(this,!0)}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"selectionRanges",{get:function(){var e=this;return this._selectionRanges||(this._selectionRanges=new o.ObservableArray,this._selectionRanges.collectionChanged.addHandler(function(){var t,o;e._owner&&!e._owner._isClicking&&((t=e._selectionRanges.length)>0&&(o=e._selectionRanges[t-1])&&o instanceof i.CellRange&&(e._owner.selection=o),t>1?(e._owner._enableMulSel=!0,e._owner.refresh(!1)):e._owner.refresh(),e._owner._enableMulSel=!1)},this)),this._selectionRanges},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"itemsSource",{get:function(){return null!=this._grid?this._grid.itemsSource:null},set:function(e){var t=this;null==t._grid&&(t._createGrid(),t._grid.itemsSourceChanged.addHandler(t._gridItemsSourceChanged,t)),t._isEmptyGrid&&t._clearGrid(),t._grid.itemsSource=e,t._owner&&t._owner._isCopying||null==e||(t._orgItemsSource=t._grid.collectionView._view.slice())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"filterSetting",{get:function(){return this===this._owner.selectedSheet&&this._getFilterSetting(),this._filterSetting},set:function(e){this._filterSetting=e,this===this._owner.selectedSheet&&this._applyFilterSetting()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"tables",{get:function(){return null==this._tables&&(this._tables=new o.ObservableArray),this._tables},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"_styledCells",{get:function(){return this._currentStyledCells||(this._currentStyledCells={}),this._currentStyledCells},set:function(e){this._currentStyledCells=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"_mergedRanges",{get:function(){return this._currentMergedRanges||(this._currentMergedRanges=[]),this._currentMergedRanges},enumerable:!0,configurable:!0}),e.prototype.onNameChanged=function(e){this.nameChanged.raise(this,e)},e.prototype.onVisibleChanged=function(e){this.visibleChanged.raise(this,e)},e.prototype.getCellStyle=function(e,t){var o,n=this._grid.rows.length,i=this._grid.columns.length;return e>=n||t>=i?null:(o=e*i+t,this._styledCells[o])},e.prototype.addTableFromArray=function(e,t,n,l,s,r,a,h){void 0===h&&(h=!0);var d,c,u,_,g,f,p,w,m,C,b,y=!1,S=this===this._owner.selectedSheet?this._owner:this.grid;if(null==n||0===n.length)throw"Invalid array to load.";if(!(null!=l&&0!==l.length||null!=(l=Object.keys(n[0]))&&0!==l.length))throw"Invalid array to load.";if(e>=this.rowCount||t>=this.columnCount)return null;var R=null==(a&&a.showHeaderRow)||a.showHeaderRow,v=!(!a||!a.showTotalRow),T=e+(R?1:0),x=T+n.length-1+(v?1:0);for(d=[],m=0;m<l.length;m++)C=l[m],c=new te(C),0===m?c._totalRowLabel="Total":m===l.length-1&&(c._totalRowFunction="Sum"),d.push(c);if(u=new i.CellRange(e,t,x,t+l.length-1),0!==(_=this._needShiftForTable(u))){if(!h)return null;if(!this._canShiftCells(u))return null;if(g=this._needAddRowCountForAddTable(_,u),S.collectionView){for(b=S.itemsSource instanceof o.CollectionView,S.collectionView.beginUpdate(),p=0;p<g;p++)b?S.itemsSource.sourceCollection.push({}):S.itemsSource.push({});S.collectionView.endUpdate()}else for(p=0;p<g;p++)S.rows.push(new i.Row);y=!0}if(t+l.length>=S.columns.length){if(!h)return null;if(f=t+l.length-S.columns.length+1,this.itemsSource&&f>0)return null;for(S.columns.beginUpdate(),p=0;p<f;p++)S.columns.push(new i.Column);S.columns.endUpdate()}if(S.beginUpdate(),y&&this._moveDownCells(_,u),R)for(m=0;m<l.length;m++)C=l[m],S.setCellData(e,t+m,C);for(w=0;w<n.length;w++)for(m=0;m<l.length;m++)C=l[m],S.setCellData(T+w,t+m,n[w][C]);return S.endUpdate(),this._addTable(u,s,r,d,a)},e.prototype.findTable=function(e,t){var o,n;if(this._tables&&this._tables.length>0)for(var i=0;i<this._tables.length;i++)if(o=this._tables[i],n=o.getRange(),e>=n.topRow&&e<=n.bottomRow&&t>=n.leftCol&&t<=n.rightCol)return o;return null},e.prototype._attachOwner=function(e){this._owner!==e&&(this._owner=e)},e.prototype._setValidName=function(e){this._name=e,this.grid.wj_sheetInfo.name=e},e.prototype._storeRowSettings=function(){var e,t=0;for(this._rowSettings=[];t<this._grid.rows.length;t++)(e=this._owner.rows[t])&&(this._rowSettings[t]={height:e.height,allowMerging:e.allowMerging,isCollapsed:e instanceof i.GroupRow?e.isCollapsed:null,visible:e.visible,isSelected:e.isSelected,readOnly:e.isReadOnly})},e.prototype._setRowSettings=function(){for(var e,t,o=0;o<this._rowSettings.length;o++)(t=this._rowSettings[o])&&(e=this._grid.rows[o])&&(e.height=t.height,e.allowMerging=t.allowMerging,e.visible=t.visible,e instanceof i.GroupRow&&(e.isCollapsed=!!t.isCollapsed),e.isSelected=!!t.isSelected,e.isReadOnly=!!t.readOnly)},e.prototype._addTable=function(e,t,o,n,i){if(!e.isValid)return null;var l;return null!=t&&null==this._owner._getTable(t)||(t=this._getUniqueTableName()),l=new ee(t,e,o,n,i),this.tables.push(l),l},e.prototype._addSelection=function(e){var t,o;for(this.selectionRanges.beginUpdate(),o=this.selectionRanges.length-1;o>=0;o--)t=this.selectionRanges[o],e.contains(t)&&this.selectionRanges.removeAt(o);e.isValid&&this.selectionRanges.push(e),this.selectionRanges.endUpdate()},e.prototype._compareRows=function(){var e=this,t=this._unboundSortDesc;return function(n,i){for(var l=0;l<t.length;l++){var s=t[l],r=n._ubv&&s.column?n._ubv[s.column._hash]:"",a=i._ubv&&s.column?i._ubv[s.column._hash]:"";if(o.isString(r)&&"="===r[0]&&(r=e._owner.evaluate(r)),o.isString(a)&&"="===a[0]&&(a=e._owner.evaluate(a)),r!==r&&(r=null),a!==a&&(a=null),o.isString(r)&&(r=r.toLowerCase()+r),o.isString(a)&&(a=a.toLowerCase()+a),""===r||null==r)return 1;if(""===a||null==a)return-1;var h=r<a?-1:r>a?1:0;if(o.isString(r)&&o.isNumber(a)&&(h=1),o.isString(a)&&o.isNumber(r)&&(h=-1),0!==h)return s.ascending?+h:-h}return 0}},e.prototype._createGrid=function(){var e,t,o,n,l=document.createElement("div");for(this._isEmptyGrid=!0,l.style.visibility="hidden",document.body.appendChild(l),e=new i.FlexGrid(l),document.body.removeChild(l),n=0;n<this._rowCount;n++)e.rows.push(new i.Row);for(o=0;o<this._columnCount;o++)(t=new i.Column).isRequired=!1,e.columns.push(t);return e.wj_sheetInfo={name:this.name,visible:this.visible,styledCells:this._styledCells,mergedRanges:this._mergedRanges},e},e.prototype._clearGrid=function(){this._grid.rows.clear(),this._grid.columns.clear(),this._grid.columnHeaders.columns.clear(),this._grid.rowHeaders.rows.clear()},e.prototype._gridItemsSourceChanged=function(){var e=this;e._owner&&!e._owner._isCopying&&e._owner.selectedSheet&&e._name===e._owner.selectedSheet.name&&(e._owner.filter.clear(),e._owner._copyFrom(e,!1),setTimeout(function(){e._owner._setFlexSheetToDirty(),e._owner.invalidate()},10))},e.prototype._addHeaderRow=function(){if(this._grid.itemsSource&&!(this._grid.rows[0]instanceof G)){for(var e,t=new G,o=0;o<this._grid.columns.length;o++)e=this._grid.columns[o],t._ubv||(t._ubv={}),t._ubv[e._hash]=e.header;this._grid.rows.insert(0,t)}},e.prototype._getUniqueTableName=function(){for(var e="Table1",t=2;;){if(null==this._owner._getTable(e))break;e="Table"+t,t+=1}return e},e.prototype._needShiftForTable=function(e){var t,o,n,i=0,l=0,s=this===this._owner.selectedSheet?this._owner:this.grid;for(t=e.topRow;t<=e.bottomRow;t++){if(t>=s.rows.length)return i=e.rowSpan-l;for(o=e.leftCol;o<=e.rightCol&&o<s.columns.length;o++)if(null!=(n=s.getCellData(t,o,!1))&&""!==n)return i=e.rowSpan-l;l++}return i},e.prototype._needAddRowCountForAddTable=function(e,t){var o,n,i,l,s,r=this===this._owner.selectedSheet?this._owner:this.grid;for(o=1;o<=e;o++)for(n=r.rows.length-o,i=t.leftCol;i<=t.rightCol&&i<r.columns.length;i++)if(l=r.getCellData(n,i,!1),s=this.getCellStyle(n,i),null!=l&&""!==l||null!=s)return e-o+1;return 0},e.prototype._moveDownTable=function(e){var t,o,n,i,l=e.getRange(),s=this===this._owner.selectedSheet?this._owner:this.grid;for(t=l.bottomRow;t>=l.topRow;t--)for(o=l.leftCol;o<=l.rightCol;o++)i=null!=s.columns[o].dataMap,n=s.getCellData(t,o,i),s.setCellData(t+1,o,n),s.setCellData(t,o,"");e._updateTableRange(1,1,0,0)},e.prototype._moveDownCells=function(e,t){var o,n,i,l,s,r,a,h,d,c,u=this===this._owner.selectedSheet?this._owner:this.grid;for(o=u.rows.length-1-e;o>=t.topRow;o--)for(n=t.leftCol;n<=t.rightCol&&n<u.columns.length;n++)c=null!=u.columns[n].dataMap,i=u.getCellData(o,n,c),u.setCellData(o+e,n,i),u.setCellData(o,n,""),l=this.getCellStyle(o,n),r=(o+e)*u.columns.length+n,s=o*u.columns.length+n,l&&(this._styledCells[r]=l,this._styledCells[s]=null),(a=this._mergedRanges[s])&&(a.row+=e,a.row2+=e,this._mergedRanges[r]=a,this._mergedRanges[s]=null),(h=this.findTable(o,n))&&(d=h.getRange()).topRow===o&&d.leftCol===n&&h._updateTableRange(e,e,0,0)},e.prototype._moveUpCells=function(e,t){var o,n,i,l,s,r,a,h,d,c,u=this===this._owner.selectedSheet?this._owner:this.grid;for(o=t.topRow;o<u.rows.length;o++)for(n=t.leftCol;n<=t.rightCol&&n<u.columns.length;n++)c=null!=u.columns[n].dataMap,i=u.getCellData(o,n,c),u.setCellData(o-e,n,i),u.setCellData(o,n,""),l=this.getCellStyle(o,n),r=(o-e)*u.columns.length+n,s=o*u.columns.length+n,l&&(this._styledCells[r]=l,this._styledCells[s]=null),(a=this._mergedRanges[s])&&(a.row-=e,a.row2-=e,this._mergedRanges[r]=a,this._mergedRanges[s]=null),(h=this.findTable(o,n))&&(d=h.getRange()).topRow===o&&d.leftCol===n&&h._updateTableRange(-e,-e,0,0)},e.prototype._moveDownCellsWithinTable=function(e,t,o){var n,i,l,s,r=this===this._owner.selectedSheet?this._owner:this.grid;for(n=o.bottomRow;n>o.topRow+e;n--)for(i=o.leftCol;i<=o.rightCol;i++)s=null!=r.columns[i].dataMap,l=r.getCellData(n,i,s),r.setCellData(n+t,i,l),r.setCellData(n,i,""),(n+t)*r.columns.length+i,n*r.columns.length+i},e.prototype._moveUpCellsWithinTable=function(e,t,o){var n,i,l,s,r=o.topRow+e,a=this===this._owner.selectedSheet?this._owner:this.grid;for(n=r;n<=o.bottomRow;n++)for(i=o.leftCol;i<=o.rightCol;i++)n>=r+t&&(s=null!=a.columns[i].dataMap,l=a.getCellData(n,i,s),a.setCellData(n-t,i,l)),a.setCellData(n,i,""),(n-t)*a.columns.length+i,n*a.columns.length+i},e.prototype._canShiftCells=function(e){var t,o,n,i,l,s,r=this===this._owner.selectedSheet?this._owner:this.grid;for(t=e.topRow;t<r.rows.length;t++)for(o=e.leftCol;o<=e.rightCol&&o<r.columns.length;o++){if((l=this.findTable(t,o))&&((s=l.getRange()).leftCol<e.leftCol||s.rightCol>e.rightCol))return!1;if(n=t*r.columns.length+o,(i=this._mergedRanges[n])&&(i.leftCol<e.leftCol||i.rightCol>e.rightCol))return!1}return!0},e.prototype._needMoveDownTable=function(e){var t,o,n=e.getRange(),i=e.getColumns(),l=this===this._owner.selectedSheet?this._owner:this.grid;if(0===n.topRow)return!0;for(t=0;t<i.length;t++)if(null!=(o=l.getCellData(n.topRow-1,n.leftCol+t,!1))&&""!==o)return!0;return!1},e.prototype._needAddRowCountForInsertTableRows=function(e,t){var o,n,i,l,s,r=this===this._owner.selectedSheet?this._owner:this.grid;for(o=1;o<=e;o++){if((n=r.rows.length-o)<=t.bottomRow)return e;for(i=t.leftCol;i<=t.rightCol&&i<r.columns.length;i++)if(l=r.getCellData(n,i,!1),s=this.getCellStyle(n,i),null!=l&&""!==l||null!=s)return e-o+1}return 0},e.prototype._getFilterSetting=function(){var e,t=0;for(this._filterDefinition=this._owner.filter.filterDefinition,this._filterSetting={},this._filterSetting.filterColumns=this._owner.filter.filterColumns,this._filterSetting.columnFilterSettings||(this._filterSetting.columnFilterSettings=[]);t<this._owner.filter._filters.length;t++)(e=this._owner.filter._filters[t])&&this._filterSetting.columnFilterSettings.push({column:e.column,filterType:e.filterType,dataMap:e.dataMap,valueFilterSetting:{maxValues:e.valueFilter.maxValues,uniqueValues:e.valueFilter.uniqueValues,sortValues:e.valueFilter.sortValues,dataMap:e.valueFilter.dataMap},conditionFilterSetting:{dataMap:e.conditionFilter.dataMap}})},e.prototype._applyFilterSetting=function(){var e,t,o,n,i,l,s,r,a,h,d=0;if(null==this._filterSetting)this._clearFilterSetting();else if(this._owner.filter.filterColumns=this._filterSetting.filterColumns,this._filterDefinition&&(this._owner.filter.filterDefinition=this._filterDefinition),null!=(e=this._filterSetting.columnFilterSettings)&&e.length>0)for(;d<e.length;d++)(t=e[d])&&null!=t.column&&(i=this._owner.filter.getColumnFilter(t.column))&&(l=i.valueFilter.showValues,s=i.valueFilter.filterText,r={operator:i.conditionFilter.condition1.operator,value:i.conditionFilter.condition1.value},a={operator:i.conditionFilter.condition2.operator,value:i.conditionFilter.condition2.value},h=i.conditionFilter.and,null!=t.dataMap&&(i.dataMap=t.dataMap),null!=t.filterType&&(i.filterType=t.filterType),(o=t.valueFilterSetting)&&(o.dataMap&&(i.valueFilter.dataMap=o.dataMap),null!=o.maxValues&&(i.valueFilter.maxValues=o.maxValues),null!=o.sortValues&&(i.valueFilter.sortValues=o.sortValues),o.uniqueValues&&(i.valueFilter.uniqueValues=o.uniqueValues)),(n=t.conditionFilterSetting)&&n.dataMap&&(i.conditionFilter.dataMap=n.dataMap),i.valueFilter.showValues=l,i.valueFilter.filterText=s,i.conditionFilter.condition1.operator=r.operator,i.conditionFilter.condition1.value=r.value,i.conditionFilter.condition2.operator=a.operator,i.conditionFilter.condition2.value=a.value,i.conditionFilter.and=h)},e.prototype._clearFilterSetting=function(){var e,t=0;for(this._owner.filter.filterColumns=null;t<this._owner.filter._filters.length;t++)(e=this._owner.filter._filters[t])&&(e.filterType=null,e.dataMap=null,e.valueFilter.uniqueValues=null,e.valueFilter.dataMap=null,e.valueFilter.maxValues=250,e.valueFilter.showValues=null,e.conditionFilter.dataMap=null);this._filterDefinition&&(this._owner.filter.filterDefinition=this._filterDefinition)},e.prototype._cloneMergedCells=function(){for(var e,t=0,o=[];t<this._mergedRanges.length;t++)e=this._mergedRanges[t],o.push(e.clone());return o},e.prototype._getMergedRange=function(e,t){var o,n;for(o=0;o<this._mergedRanges.length;o++)if(n=this._mergedRanges[o],e>=n.topRow&&e<=n.bottomRow&&t>=n.leftCol&&t<=n.rightCol)return n;return null},e}();t.Sheet=K;var X=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._current=-1,t.sheetCleared=new o.Event,t.selectedSheetChanged=new o.Event,t.sheetNameChanged=new o.Event,t.sheetVisibleChanged=new o.Event,t}return __extends(t,e),t.prototype.onSheetCleared=function(){this.sheetCleared.raise(this,new o.EventArgs)},Object.defineProperty(t.prototype,"selectedIndex",{get:function(){return this._current},set:function(e){this._moveCurrentTo(+e)},enumerable:!0,configurable:!0}),t.prototype.onSelectedSheetChanged=function(e){this.selectedSheetChanged.raise(this,e)},t.prototype.insert=function(t,o){var n;(n=o.name?this.getValidSheetName(o):this._getUniqueName())!==o.name&&(o.name=n),e.prototype.insert.call(this,t,o),this._postprocessSheet(o)},t.prototype.push=function(){for(var t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];this.length;for(var n,i=0;i<t.length;i++)(n=t[i].name?this.getValidSheetName(t[i]):this._getUniqueName())!==t[i].name&&(t[i].name=n),e.prototype.push.call(this,t[i]),this._postprocessSheet(t[i]);return this.length},t.prototype.splice=function(t,o,n){var i;return n?((i=n.name?this.getValidSheetName(n):this._getUniqueName())!==n.name&&(n.name=i),this._postprocessSheet(n),e.prototype.splice.call(this,t,o,n)):e.prototype.splice.call(this,t,o,n)},t.prototype.removeAt=function(t){this.hide(t)&&(e.prototype.removeAt.call(this,t),t<this.selectedIndex&&(this._current-=1))},t.prototype.onSheetNameChanged=function(e){this.sheetNameChanged.raise(this,e)},t.prototype.onSheetVisibleChanged=function(e){this.sheetVisibleChanged.raise(this,e)},t.prototype.selectFirst=function(){return this._moveCurrentTo(0)},t.prototype.selectLast=function(){return this._moveCurrentTo(this.length-1)},t.prototype.selectPrevious=function(){return this._moveCurrentTo(this._current-1)},t.prototype.selectNext=function(){return this._moveCurrentTo(this._current+1)},t.prototype.hide=function(e){return!(e<0&&e>=this.length)&&(!!this[e].visible&&(this[e].visible=!1,!0))},t.prototype.show=function(e){return!(e<0&&e>=this.length)&&(this[e].visible=!0,this._moveCurrentTo(e),!0)},t.prototype.clear=function(){e.prototype.clear.call(this),this._current=-1,this.onSheetCleared()},t.prototype.isValidSheetName=function(e){var t=this._getSheetIndexFrom(e.name),o=this.indexOf(e);return-1===t||t===o},t.prototype.getValidSheetName=function(e){for(var t,o=e.name,n=1,i=this.indexOf(e);;){if(-1===(t=this._getSheetIndexFrom(o))||t===i)break;o=e.name.concat((n+1).toString()),n+=1}return o},t.prototype._moveCurrentTo=function(e){var t,n=e;if(e<0||e>=this.length)return!1;if(this._current<n||0===n)for(;n<this.length&&!this[n].visible;)n++;else if(this._current>n)for(;n>=0&&!this[n].visible;)n--;if(n===this.length)for(n=e;n>=0&&!this[n].visible;)n--;return!(n<0)&&(n!==this._current&&(t=new o.PropertyChangedEventArgs("sheetIndex",this._current,n),this._current=n,this.onSelectedSheetChanged(t)),!0)},t.prototype._getSheetIndexFrom=function(e){var t;if(!e)return-1;e=e.toLowerCase();for(var o=0;o<this.length;o++)if(t=this[o],(t.name?t.name.toLowerCase():"")===e)return o;return-1},t.prototype._postprocessSheet=function(e){var t=this;e.nameChanged.addHandler(function(){var n,i=t._getSheetIndexFrom(e.name);t.isValidSheetName(e)||e._setValidName(t.getValidSheetName(e)),n=new o.NotifyCollectionChangedEventArgs(o.NotifyCollectionChangedAction.Change,e,o.isNumber(i)?i:t.length-1),t.onSheetNameChanged(n)}),e.visibleChanged.addHandler(function(){var n=t._getSheetIndexFrom(e.name),i=new o.NotifyCollectionChangedEventArgs(o.NotifyCollectionChangedAction.Change,e,o.isNumber(n)?n:t.length-1);t.onSheetVisibleChanged(i)})},t.prototype._getUniqueName=function(){for(var e="Sheet1",t=2;;){if(-1===this._getSheetIndexFrom(e))break;e="Sheet"+t,t+=1}return e},t}(o.ObservableArray);t.SheetCollection=X;var $=function(e){function t(t,o,n){var i=e.call(this,t,n)||this;i._rtl=!1,i._sheetTabClicked=!1;var l=i;return l._owner=o,l._sheets=o.sheets,l._rtl="rtl"==getComputedStyle(l._owner.hostElement).direction,l._initControl(),l.deferUpdate(function(){n&&l.initialize(n)}),i}return __extends(t,e),t.prototype.refresh=function(e){this._tabContainer.innerHTML="",this._tabContainer.innerHTML=this._getSheetTabs(),this._rtl&&this._adjustSheetsPosition(),this._adjustSize()},t.prototype._sourceChanged=function(e,t){void 0===t&&(t=o.NotifyCollectionChangedEventArgs.reset);var n=t;switch(n.action){case o.NotifyCollectionChangedAction.Add:n.index-1<0&&0,this._tabContainer.innerHTML="",this._tabContainer.innerHTML=this._getSheetTabs(),this._rtl&&this._adjustSheetsPosition(),this._adjustSize();break;case o.NotifyCollectionChangedAction.Remove:this._tabContainer.removeChild(this._tabContainer.children[n.index]),this._tabContainer.hasChildNodes()&&this._updateTabActive(n.index,!0),this._adjustSize();break;default:this.invalidate()}},t.prototype._selectedSheetChanged=function(e,t){this._updateTabActive(t.oldValue,!1),this._updateTabActive(t.newValue,!0),this._sheetTabClicked?this._sheetTabClicked=!1:this._scrollToActiveSheet(t.newValue,t.oldValue),this._adjustSize()},t.prototype._initControl=function(){var e=this;e.applyTemplate("",e.getTemplate(),{_sheetContainer:"sheet-container",_tabContainer:"container",_sheetPage:"sheet-page",_newSheet:"new-sheet"}),e._rtl&&(e._sheetPage.style.right="0px",e._tabContainer.parentElement.style.right=e._sheetPage.clientWidth+"px",e._tabContainer.style.right="0px",e._tabContainer.style.cssFloat="right",e._newSheet.style.right=e._sheetPage.clientWidth+e._tabContainer.parentElement.clientWidth+"px"),e._adjustNavigationButtons(e._rtl),e.addEventListener(e.hostElement,"mousedown",function(){e._owner._mouseHdl._htDown=null}),e.addEventListener(e._newSheet,"click",function(t){var o=e._owner.selectedSheetIndex;e._owner.addUnboundSheet(),e._scrollToActiveSheet(e._owner.selectedSheetIndex,o)}),e._sheets.collectionChanged.addHandler(e._sourceChanged,e),e._sheets.selectedSheetChanged.addHandler(e._selectedSheetChanged,e),e._sheets.sheetNameChanged.addHandler(e._updateSheetName,e),e._sheets.sheetVisibleChanged.addHandler(e._updateTabShown,e),e._initSheetPage(),e._initSheetTab()},t.prototype._initSheetTab=function(){var e=this;e.addEventListener(e._tabContainer,"mousedown",function(t){var o,n=t.target;n instanceof HTMLLIElement&&(e._sheetTabClicked=!0,o=e._getItemIndex(e._tabContainer,n),e._scrollSheetTabContainer(n),o>-1&&(e._sheets.selectedIndex=o))})},t.prototype._initSheetPage=function(){var e=this;e.hostElement.querySelector("div.wj-sheet-page").addEventListener("click",function(t){var o="[object HTMLButtonElement]"===t.target.toString()?t.target:t.target.parentElement,n=e._getItemIndex(e._sheetPage,o);if(0!==e._sheets.length)switch(n){case 0:e._sheets.selectFirst();break;case 1:e._sheets.selectPrevious();break;case 2:e._sheets.selectNext();break;case 3:e._sheets.selectLast()}})},t.prototype._getSheetTabs=function(){var e,t="";for(e=0;e<this._sheets.length;e++)t+=this._getSheetElement(this._sheets[e],this._sheets.selectedIndex===e);return t},t.prototype._getSheetElement=function(e,t){void 0===t&&(t=!1);var o="<li";return e.visible?t&&(o+=' class="active"'):o+=' class="hidden"',o+=">"+e.name+"</li>"},t.prototype._updateTabActive=function(e,t){e<0||e>=this._tabContainer.children.length||(t?o.addClass(this._tabContainer.children[e],"active"):o.removeClass(this._tabContainer.children[e],"active"))},t.prototype._updateTabShown=function(e,t){t.index<0||t.index>=this._tabContainer.children.length||(t.item.visible?o.removeClass(this._tabContainer.children[t.index],"hidden"):o.addClass(this._tabContainer.children[t.index],"hidden"),this._adjustSize())},t.prototype._adjustSize=function(){var e,t,o=this._tabContainer.childElementCount,n=0,i=0;if("none"!==this.hostElement.style.display){for(i=this._tabContainer.parentElement.scrollLeft,this._tabContainer.parentElement.style.width="",this._tabContainer.style.width="",this._sheetPage.parentElement.style.width="",e=0;e<o;e++)n+=this._tabContainer.children[e].offsetWidth+1;t=this.hostElement.offsetWidth-this._sheetPage.offsetWidth-this._newSheet.offsetWidth-2,this._tabContainer.parentElement.style.width=(n>t?t:n)+"px",this._tabContainer.style.width=n+"px",this._sheetPage.parentElement.style.width=this._sheetPage.offsetWidth+this._newSheet.offsetWidth+this._tabContainer.parentElement.offsetWidth+3+"px",this._tabContainer.parentElement.scrollLeft=i}},t.prototype._getItemIndex=function(e,t){for(var o=0;o<e.children.length;o++)if(e.children[o]===t)return o;return-1},t.prototype._updateSheetName=function(e,t){this._tabContainer.querySelectorAll("li")[t.index].textContent=t.item.name,this._adjustSize()},t.prototype._scrollSheetTabContainer=function(e){var t,o=this._tabContainer.parentElement.scrollLeft,n=this._sheetPage.offsetWidth,l=this._newSheet.offsetWidth,s=this._tabContainer.parentElement.offsetWidth;if(this._rtl)switch(i.FlexGrid._getRtlMode()){case"rev":(t=-this._tabContainer.offsetLeft)+e.offsetLeft+e.offsetWidth>s+o?this._tabContainer.parentElement.scrollLeft+=e.offsetWidth:t+e.offsetLeft<o&&(this._tabContainer.parentElement.scrollLeft-=e.offsetWidth);break;case"neg":e.offsetLeft<o?this._tabContainer.parentElement.scrollLeft-=e.offsetWidth:e.offsetLeft+e.offsetWidth>s+o&&(this._tabContainer.parentElement.scrollLeft+=e.offsetWidth);break;default:e.offsetLeft-l+o<0?this._tabContainer.parentElement.scrollLeft+=e.offsetWidth:e.offsetLeft+e.offsetWidth-l+o>s&&(this._tabContainer.parentElement.scrollLeft-=e.offsetWidth)}else e.offsetLeft+e.offsetWidth-n>s+o?this._tabContainer.parentElement.scrollLeft+=e.offsetWidth:e.offsetLeft-n<o&&(this._tabContainer.parentElement.scrollLeft-=e.offsetWidth)},t.prototype._adjustSheetsPosition=function(){var e,t,o=this._tabContainer.querySelectorAll("li"),n=0;for(t=0;t<o.length;t++)(e=o[t]).style.cssFloat="right",e.style.right=n+"px",n+=o[t].clientWidth},t.prototype._scrollToActiveSheet=function(e,t){var o,n,l,s=this._tabContainer.querySelectorAll("li");if(n=this._tabContainer.clientWidth>this._tabContainer.parentElement.clientWidth?this._tabContainer.clientWidth-this._tabContainer.parentElement.clientWidth:0,s.length>0&&e<s.length&&t<s.length){if(0===e&&!this._rtl||e===s.length-1&&this._rtl){if(this._rtl)switch(i.FlexGrid._getRtlMode()){case"rev":this._tabContainer.parentElement.scrollLeft=0;break;case"neg":this._tabContainer.parentElement.scrollLeft=-n;break;default:this._tabContainer.parentElement.scrollLeft=n}else this._tabContainer.parentElement.scrollLeft=0;return}if(0===e&&this._rtl||e===s.length-1&&!this._rtl){if(this._rtl)switch(i.FlexGrid._getRtlMode()){case"rev":this._tabContainer.parentElement.scrollLeft=n;break;case"neg":default:this._tabContainer.parentElement.scrollLeft=0}else this._tabContainer.parentElement.scrollLeft=n;return}if(e>=t)for(l=t+1;l<=e;l++)o=s[l],this._scrollSheetTabContainer(o);else for(l=t-1;l>=e;l--)o=s[l],this._scrollSheetTabContainer(o)}},t.prototype._adjustNavigationButtons=function(e){var t,n=this.hostElement.querySelectorAll(".wj-sheet-page button");n&&4===n.length&&(e?(t=n[0].querySelector("span"),o.removeClass(t,"wj-glyph-step-backward"),o.addClass(t,"wj-glyph-step-forward"),t=n[1].querySelector("span"),o.removeClass(t,"wj-glyph-left"),o.addClass(t,"wj-glyph-right"),t=n[2].querySelector("span"),o.removeClass(t,"wj-glyph-right"),o.addClass(t,"wj-glyph-left"),t=n[3].querySelector("span"),o.removeClass(t,"wj-glyph-step-forward"),o.addClass(t,"wj-glyph-step-backward")):(t=n[0].querySelector("span"),o.removeClass(t,"wj-glyph-step-forward"),o.addClass(t,"wj-glyph-step-backward"),t=n[1].querySelector("span"),o.removeClass(t,"wj-glyph-right"),o.addClass(t,"wj-glyph-left"),t=n[2].querySelector("span"),o.removeClass(t,"wj-glyph-left"),o.addClass(t,"wj-glyph-right"),t=n[3].querySelector("span"),o.removeClass(t,"wj-glyph-step-backward"),o.addClass(t,"wj-glyph-step-forward")))},t.controlTemplate='<div wj-part="sheet-container" class="wj-sheet" style="height:100%;position:relative"><div wj-part="sheet-page" class="wj-btn-group wj-sheet-page"><button type="button" class="wj-btn wj-btn-default"><span class="wj-sheet-icon wj-glyph-step-backward"></span></button><button type="button" class="wj-btn wj-btn-default"><span class="wj-sheet-icon wj-glyph-left"></span></button><button type="button" class="wj-btn wj-btn-default"><span class="wj-sheet-icon wj-glyph-right"></span></button><button type="button" class="wj-btn wj-btn-default"><span class="wj-sheet-icon wj-glyph-step-forward"></span></button></div><div class="wj-sheet-tab" style="height:100%;overflow:hidden"><ul wj-part="container"></ul></div><div wj-part="new-sheet" class="wj-new-sheet"><span class="wj-sheet-icon wj-glyph-file"></span></div></div>',t}(o.Control);t._SheetTabs=$;var Y=function(){function e(e,t){this._column=e,this._ascending=t}return Object.defineProperty(e.prototype,"column",{get:function(){return this._column},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"ascending",{get:function(){return this._ascending},enumerable:!0,configurable:!0}),e}();t._UnboundSortDescription=Y;var Q=function(){function e(e){this._owner=e,this._sortDescriptions=new o.CollectionView,this._committedList=[new J(-1,!0)],this._sortDescriptions.newItemCreator=function(){return new J(-1,!0)}}return Object.defineProperty(e.prototype,"sortDescriptions",{get:function(){return this._sortDescriptions},set:function(e){this._sortDescriptions=e,this.commitSort()},enumerable:!0,configurable:!0}),e.prototype.addSortLevel=function(e,t){void 0===t&&(t=!0);var n=this._sortDescriptions.addNew();null!=e&&!isNaN(e)&&o.isInt(e)&&(n.columnIndex=e),n.ascending=t,this._sortDescriptions.commitNew()},e.prototype.deleteSortLevel=function(e){var t;(t=null!=e?this._getSortItem(e):this._sortDescriptions.currentItem)&&this._sortDescriptions.remove(t)},e.prototype.copySortLevel=function(){var e=this._sortDescriptions.currentItem;if(e){var t=this._sortDescriptions.addNew();t.columnIndex=parseInt(e.columnIndex),t.ascending=e.ascending,this._sortDescriptions.commitNew()}},e.prototype.editSortLevel=function(e,t){null!=e&&(this._sortDescriptions.currentItem.columnIndex=e),null!=t&&(this._sortDescriptions.currentItem.ascending=t)},e.prototype.moveSortLevel=function(e){var t=this._sortDescriptions.currentItem;if(t){var o=this._sortDescriptions.sourceCollection,n=o.indexOf(t),i=n+e;n>-1&&i>-1&&(o.splice(n,1),o.splice(i,0,t),this._sortDescriptions.refresh(),this._sortDescriptions.moveCurrentTo(t))}},e.prototype.checkSortItemExists=function(e){for(var t=0,o=this._sortDescriptions.itemCount;t<o;t++)if(+this._sortDescriptions.items[t].columnIndex===e)return t;return-1},e.prototype.commitSort=function(e){void 0===e&&(e=!0);var t,n,i,l,s,r,a,h,d,c,u,_,g,f=this._owner.itemsSource instanceof o.CollectionView,p={},w={};if(this._owner.selectedSheet&&0!==this._owner.columns.length){if(this._owner._needCopyToSheet=!1,r=this._owner.selectedSheet._unboundSortDesc,e&&this._owner.undoStack.stackSize>0&&(a=new D(this._owner)),this._sortDescriptions.itemCount>0?this._committedList=this._cloneSortList(this._sortDescriptions.items):this._committedList=[new J(-1,!0)],this._owner.collectionView){for(this._owner._isSorting=!0,this._owner.beginUpdate(),this._owner.collectionView.canSort=!0,(h=this._owner.editableCollectionView)&&h.currentEditItem&&-1!==h.items.indexOf(h.currentEditItem)&&!this._isEmpty(h.currentEditItem)&&h.commitEdit(),this._owner.collectionView.beginUpdate(),this._owner.selectedSheet.grid.collectionView.beginUpdate(),(i=this._owner.collectionView.sortDescriptions).clear(),d=this._owner.selection.clone(),u=this._owner.collectionView._view.slice(),s=0;s<u.length;s++)null!=(g=u[s]).index&&(s!==g.index&&this._owner._updateFormulaForReorderingRows(g.index+1,s+1,!0),this._owner._updateCellStyleForReorderingRows(s+1,g.index+1,p));for(Object.keys(p).length>0&&(this._owner.selectedSheet._styledCells=p),f?this._owner.itemsSource.sourceCollection=this._owner.selectedSheet._orgItemsSource.slice():(this._owner.autoGenerateColumns=!1,this._owner.selectedSheet.grid.collectionView.canSort=!0,c=this._owner.selectedSheet._filterDefinition,this._owner.itemsSource=this._owner.selectedSheet._orgItemsSource.slice(),this._synchColumn(),(l=this._owner.selectedSheet.grid.collectionView.sortDescriptions).clear()),this._owner.collectionView.sourceCollection.map(function(e,t){e.index=t}),this._owner.selection=d,navigator.userAgent.toLowerCase().indexOf("chrome")>-1&&(this._owner.collectionView.useStableSort=!0,f||(this._owner.selectedSheet.grid.collectionView.useStableSort=!0)),s=0;s<this._sortDescriptions.itemCount;s++)(t=this._sortDescriptions.items[s]).columnIndex>-1&&(n=new o.SortDescription(this._owner.columns[t.columnIndex].binding,t.ascending),i.push(n),f||(this._owner.collectionView.sortDescriptions.push(n),l.push(n)));for(this._owner.selectedSheet.selectionRanges.clear(),this._owner.collectionView.endUpdate(),this._owner.selectedSheet.grid.collectionView.endUpdate(),d=this._owner.selection.clone(),_=this._owner.collectionView._view.slice(),f?this._owner.itemsSource.sourceCollection=_:(this._owner.itemsSource=_,this._synchColumn(),c&&(this._owner.filter.filterDefinition=c),this._owner.selectedSheet.grid.collectionView.canSort=!1),s=0;s<_.length;s++)s!==(g=_[s]).index&&this._owner._updateFormulaForReorderingRows(g.index+1,s+1),this._owner._updateCellStyleForReorderingRows(g.index+1,s+1,w);this._owner.selectedSheet._styledCells=w,this._owner.selection=d,this._owner.collectionView.canSort=!1,this._owner.endUpdate(),this._owner._isSorting=!1}else for(r.clear(),s=0;s<this._sortDescriptions.itemCount;s++)(t=this._sortDescriptions.items[s]).columnIndex>-1&&r.push(new Y(this._owner.columns[t.columnIndex],t.ascending));a&&(a.saveNewState(),this._owner.undoStack._addAction(a)),this._owner._copiedRanges=null,this._owner._needCopyToSheet=!0}},e.prototype.cancelSort=function(){this._sortDescriptions.sourceCollection=this._committedList.slice()},e.prototype.clearSort=function(){this._sortDescriptions.sourceCollection=[],this.commitSort()},e.prototype._getColumnIndex=function(e){for(var t=0,o=this._owner.columns.length;t<o;t++)if(this._owner.columns[t].binding===e)return t;return-1},e.prototype._getSortItem=function(e){var t=this.checkSortItemExists(e);if(t>-1)return this._sortDescriptions.items[t]},e.prototype._cloneSortList=function(e){for(var t=[],o=0;o<e.length;o++)t[o]=e[o].clone();return t},e.prototype._updateSortSortDescription=function(e,t,o){void 0===o&&(o=!0);var n,i;for(n=this._sortDescriptions.items.length-1;n>=0;n--)i=this._sortDescriptions.items[n],o?i.columnIndex>e&&(i.columnIndex+=t):i.columnIndex>=e+t?i.columnIndex-=t:i.columnIndex>=e&&this._sortDescriptions.remove(i)},e.prototype._synchColumn=function(){var e,t,o;for(this._owner.columns.clear(),e=this._owner.rows[0]instanceof i._NewRowTemplate?this._owner.rows[1]:this._owner.rows[0],t=0;t<this._owner.selectedSheet.grid.columns.length;t++)(o=this._owner.selectedSheet.grid.columns[t]).isRequired=!1,this._owner.columns.push(o),e._ubv||(e._ubv={}),e._ubv[o._hash]=o.header},e.prototype._isEmpty=function(e){var t=Object.prototype.hasOwnProperty;if(null==e)return!0;if(e.length>0)return!1;if(0===e.length)return!0;for(var o in e)if(t.call(e,o))return!1;return!0},e}();t.SortManager=Q;var J=function(){function e(e,t){this._columnIndex=e,this._ascending=t}return Object.defineProperty(e.prototype,"columnIndex",{get:function(){return this._columnIndex},set:function(e){this._columnIndex=+e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"ascending",{get:function(){return this._ascending},set:function(e){this._ascending=e},enumerable:!0,configurable:!0}),e.prototype.clone=function(){return new e(this._columnIndex,this._ascending)},e}();t.ColumnSortDescription=J;var Z=function(){function e(e){this.MAX_STACK_SIZE=500,this._stack=[],this._pointer=-1,this._resizingTriggered=!1,this.undoStackChanged=new o.Event;var t=this;t._owner=e,t._owner.prepareCellForEdit.addHandler(t._initCellEditAction,t),t._owner.cellEditEnded.addHandler(function(e,o){t._pendingAction&&(!o.data||46!==o.data.keyCode&&8!==o.data.keyCode)&&t._pendingAction instanceof R&&!t._pendingAction.isPaste&&t._afterProcessCellEditAction(t)},t),t._owner.pasting.addHandler(t._initCellEditActionForPasting,t),t._owner.pastingCell.addHandler(function(e,o){t._pendingAction&&(t._pendingAction instanceof R?t._pendingAction.updateForPasting(o.range):t._pendingAction instanceof A&&t._pendingAction.updateForPasting(o.range))},t),t._owner.pasted.addHandler(function(){t._pendingAction&&(t._pendingAction instanceof R&&t._pendingAction.isPaste?t._afterProcessCellEditAction(t):t._pendingAction instanceof A&&(t._pendingAction.saveNewState(),t._addAction(t._pendingAction),t._pendingAction=null))},t),t._owner.resizingColumn.addHandler(function(e,o){0!==t.stackSize&&t._owner.selectedSheet&&(t._resizingTriggered||(t._pendingAction=new v(t._owner,o.panel,o.col),t._resizingTriggered=!0))},t),t._owner.resizedColumn.addHandler(function(e,o){t._pendingAction instanceof v&&t._pendingAction.saveNewState()&&t._addAction(t._pendingAction),t._pendingAction=null,t._resizingTriggered=!1},t),t._owner.resizingRow.addHandler(function(e,o){0!==t.stackSize&&t._owner.selectedSheet&&(t._resizingTriggered||(t._pendingAction=new T(t._owner,o.panel,o.row),t._resizingTriggered=!0))},t),t._owner.resizedRow.addHandler(function(e,o){t._pendingAction instanceof T&&t._pendingAction.saveNewState()&&t._addAction(t._pendingAction),t._pendingAction=null,t._resizingTriggered=!1},t),t._owner.draggingRowColumn.addHandler(function(e,o){0!==t.stackSize&&t._owner.selectedSheet&&o.isShiftKey&&(o.isDraggingRows?t._pendingAction=new k(t._owner):t._pendingAction=new x(t._owner))},t),t._owner.droppingRowColumn.addHandler(function(){t._pendingAction&&t._pendingAction.saveNewState()&&t._addAction(t._pendingAction),t._pendingAction=null},t)}return Object.defineProperty(e.prototype,"stackSize",{get:function(){return null==this._stackSize?this.MAX_STACK_SIZE:this._stackSize},set:function(e){o.isNumber(e)&&(e<0?this._stackSize=0:e>this.MAX_STACK_SIZE?this._stackSize=this.MAX_STACK_SIZE:this._stackSize=Math.floor(e))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"canUndo",{get:function(){return this._pointer>-1&&this._pointer<this._stack.length},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"canRedo",{get:function(){return this._pointer+1>-1&&this._pointer+1<this._stack.length},enumerable:!0,configurable:!0}),e.prototype.onUndoStackChanged=function(){this.undoStackChanged.raise(this)},e.prototype.undo=function(){var e;this.canUndo&&(e=this._stack[this._pointer],this._beforeUndoRedo(e),e.undo(),this._pointer--,this.onUndoStackChanged())},e.prototype.redo=function(){var e;this.canRedo&&(this._pointer++,e=this._stack[this._pointer],this._beforeUndoRedo(e),e.redo(),this.onUndoStackChanged())},e.prototype._addAction=function(e){this._stack.length>0&&this._stack.length>this._pointer+1&&this._stack.splice(this._pointer+1,this._stack.length-this._pointer-1),this._stack.length>=this.stackSize&&this._stack.splice(0,this._stack.length-this.stackSize+1),this._pointer=this._stack.length,this._stack.push(e),this.onUndoStackChanged()},e.prototype._pop=function(){var e;return this._pointer<0?null:(e=this._stack[this._pointer],this._pointer--,e)},e.prototype.clear=function(){this._stack.length=0},e.prototype._initCellEditAction=function(e,t){0!==this.stackSize&&this._owner.selectedSheet&&(this._pendingAction=new R(this._owner,t.range))},e.prototype._initCellEditActionForPasting=function(){0!==this.stackSize&&this._owner.selectedSheet&&(this._owner._isCutting?this._pendingAction=new A(this._owner):(this._pendingAction=new R(this._owner),this._pendingAction.markIsPaste()))},e.prototype._afterProcessCellEditAction=function(e){e._pendingAction&&(e._pendingAction instanceof R&&e._pendingAction.saveNewState()&&e._addAction(this._pendingAction),e._pendingAction=null)},e.prototype._beforeUndoRedo=function(e){this._owner.selectedSheetIndex=e.sheetIndex},e}();t.UndoStack=Z;var ee=function(){function e(e,t,o,n,i){if(this._showHeaderRow=!0,this._showTotalRow=!1,this._showBandedColumns=!1,this._showBandedRows=!0,this._alterFirstColumn=!1,this._alterLastColumn=!1,this._orgHeaderCellsContent=[],!t.isValid)throw"The range of this table is invalid.";this._name=e,this._range=t.clone(),this._style=o,null!=n&&n.length>0&&this._pushTableColumns(n),null!=i&&(null!=i.showHeaderRow&&(this._showHeaderRow=i.showHeaderRow),null!=i.showTotalRow&&(this._showTotalRow=i.showTotalRow),null!=i.showBandedColumns&&(this._showBandedColumns=i.showBandedColumns),null!=i.showBandedRows&&(this._showBandedRows=i.showBandedRows),null!=i.alterFirstColumn&&(this._alterFirstColumn=i.alterFirstColumn),null!=i.alterLastColumn&&(this._alterLastColumn=i.alterLastColumn))}return Object.defineProperty(e.prototype,"name",{get:function(){return this._name},set:function(e){var t,o;if(null==e||""===e)throw"The name of the Table should not be empty.";this._name.toLowerCase()!==e.toLowerCase()&&(o=this._name,this._name=e,this._owner&&(!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new F(this._owner,this)),this._owner._updateFormulasWithNameUpdating(o,e,!0),t&&(t.saveNewState(),this._owner.undoStack._addAction(t),t=null)))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"sheet",{get:function(){return this._sheet},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"style",{get:function(){return this._style},set:function(e){var t;e.name!==this._style.name&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new F(this._owner,this)),this._style=e,this._owner&&(t&&(t.saveNewState(),this._owner.undoStack._addAction(t),t=null),this._owner.refresh()))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"showHeaderRow",{get:function(){return this._showHeaderRow},set:function(e){var t,o;if(e!==this._showHeaderRow&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new F(this._owner,this)),o=this._showHeaderRow,this._showHeaderRow=e,this._owner))try{this._owner.beginUpdate(),this._adjustTableRangeWithHeaderRow(),t&&(t.saveNewState(),this._owner.undoStack._addAction(t))}catch(e){throw this._showHeaderRow=o,e}finally{t=null,this._owner.endUpdate()}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"showTotalRow",{get:function(){return this._showTotalRow},set:function(e){var t,o;if(e!==this._showTotalRow&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new F(this._owner,this)),o=this._showTotalRow,this._showTotalRow=e,this._owner))try{this._owner.beginUpdate(),this._adjustTableRangeWithTotalRow(),t&&(t.saveNewState(),this._owner.undoStack._addAction(t))}catch(e){throw this._showTotalRow=o,e}finally{t=null,this._owner.endUpdate()}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"showBandedColumns",{get:function(){return this._showBandedColumns},set:function(e){var t;e!==this._showBandedColumns&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new F(this._owner,this)),this._showBandedColumns=e,this._owner&&(t&&(t.saveNewState(),this._owner.undoStack._addAction(t),t=null),this._owner.refresh()))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"showBandedRows",{get:function(){return this._showBandedRows},set:function(e){var t;e!==this._showBandedRows&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new F(this._owner,this)),this._showBandedRows=e,this._owner&&(t&&(t.saveNewState(),this._owner.undoStack._addAction(t),t=null),this._owner.refresh()))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"alterFirstColumn",{get:function(){return this._alterFirstColumn},set:function(e){var t;e!==this._alterFirstColumn&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new F(this._owner,this)),this._alterFirstColumn=e,this._owner&&(t&&(t.saveNewState(),this._owner.undoStack._addAction(t),t=null),this._owner.refresh()))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"alterLastColumn",{get:function(){return this._alterLastColumn},set:function(e){var t;e!==this._alterLastColumn&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new F(this._owner,this)),this._alterLastColumn=e,this._owner&&(t&&(t.saveNewState(),this._owner.undoStack._addAction(t),t=null),this._owner.refresh()))},enumerable:!0,configurable:!0}),e.prototype.getRange=function(e,t){void 0===e&&(e=ne.All);var o;switch(e){case ne.Data:o=this._getDataRange();break;case ne.Header:o=this._getHeaderRange();break;case ne.Footer:o=this._getFooterRange();break;default:o=this._range.clone()}if(null!=t&&o){var n=this._getColumnIndex(t);if(null==n)return null;o.col=o.col2=o.leftCol+n}return o},e.prototype.getColumns=function(){return this._columns?this._columns.slice():[]},e.prototype.insertRows=function(e,t,n){void 0===n&&(n=!0);var l,s,r,a,h,d=this.getRange(),c=!1;if(null==t&&(t=1),!o.isInt(t)||t<1)return!1;if(0===e&&this._showHeaderRow||e===this._range.rowSpan-1&&this._showTotalRow||e<0||e>=this._range.rowSpan)return!1;if(this._owner){if(this._owner.beginUpdate(),a=this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid,n){if(r=new i.CellRange(d.bottomRow+1,d.col,d.bottomRow+1,d.col2),this._sheet._canShiftCells(r)){if(l=this._sheet._needAddRowCountForInsertTableRows(t,d),a.collectionView){for(h=a.itemsSource instanceof o.CollectionView,a.collectionView.beginUpdate(),s=0;s<l;s++)h?a.itemsSource.sourceCollection.push({}):a.itemsSource.push({});a.collectionView.endUpdate()}else for(s=0;s<l;s++)a.rows.push(new i.Row);this._sheet._moveDownCells(t,r),c=!0}}else this._canInsertRowsWithoutShift(t)&&(c=!0);c&&(this._sheet._moveDownCellsWithinTable(e,t,d),this._updateTableRange(0,t,0,0)),this._owner.endUpdate()}else this._updateTableRange(0,t,0,0),c=!0;return c},e.prototype.deleteRows=function(e,t,n){void 0===n&&(n=!0);var l,s=!1,r=this.getRange();null==t&&(t=1),!o.isInt(t)||t<1||0===e&&this._showHeaderRow||e===this._range.rowSpan-1&&this._showTotalRow||e<0||e>=this._range.rowSpan||e+t>this._range.rowSpan-(this._showTotalRow?1:0)||(this._owner?(this._owner.beginUpdate(),n?(l=new i.CellRange(r.bottomRow+1,r.col,r.bottomRow+1,r.col2),this._sheet._canShiftCells(l)&&(s=!0)):s=!0,s&&(this._sheet._moveUpCellsWithinTable(e,t,r),n&&this._sheet._moveUpCells(t,l),this._updateTableRange(0,-t,0,0)),this._owner.endUpdate()):this._updateTableRange(0,-t,0,0))},e.prototype._addColumn=function(e,t){var o,n=this.getRange();if(e<=0||e>this._columns.length)throw"The column index is out of range.";t=this._getUniqueColumnName(e,t),(o=new te(t))._attach(this),this._columns.splice(e,0,o),this.showHeaderRow&&this._owner&&this._sheet&&(this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid).setCellData(n.topRow,n.leftCol+e,t)},e.prototype._updateCell=function(e,t,o){var n,i=e-this._range.topRow,l=t-this._range.leftCol;null!=this._style&&(n=this._getTableCellAppliedStyles(i,l),this._applyStylesForCell(n,o))},e.prototype._updateTableRange=function(e,t,o,n){this._range.row<=this._range.row2?(this._range.row+=e,this._range.row2+=t):(this._range.row2+=e,this._range.row+=t),this._range.col<=this._range.col2?(this._range.col+=o,this._range.col2+=n):(this._range.col2+=o,this._range.col+=n)},e.prototype._setTableRange=function(e,t){var o;if(this._range=e,null!=t)for(this._columns.splice(0,this._columns.length),o=0;o<t.length;o++)this._columns.push(t[o])},e.prototype._updateColumnName=function(e,t){var o=this._columns[e];t=this._getUniqueColumnName(null,t),o.name=t,this._showHeaderRow&&this._owner&&this._sheet&&(this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid).setCellData(this._range.topRow,this._range.leftCol+e,t)},e.prototype._updateColumnTotalRowContent=function(e,t){var o,n;null==t&&(t=this._columns.indexOf(e)),t<0||(e.totalRowFunction?n=null!=(o=this._getSubtotalFunction(e.totalRowFunction.toLowerCase()))?"=subtotal("+o+",["+e.name+"])":"="===e.totalRowFunction[0]?e.totalRowFunction:"="+e.totalRowFunction:0===t?(e.totalRowLabel||(e.totalRowLabel="Total"),n=e.totalRowLabel):n=e.totalRowLabel,this._owner&&this._sheet&&(this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid).setCellData(this._range.bottomRow,this._range.leftCol+t,n,!1))},e.prototype._attachSheet=function(e){var t=this.getRange();if(!(this._sheet&&this._owner||(this._sheet=e,this._owner=e._owner,null==this._owner))){if(this._owner._containsMergedCells(this._range,e))throw"Table does not allow the merged cell within the table.";null==this._style&&(this._style=this._owner.getBuiltInTableStyle("TableStyleMedium9")),null!=this._columns&&0!==this._columns.length||this._generateColumns(this._showHeaderRow);try{this._owner.beginUpdate(),this._showHeaderRow&&1===t.rowSpan&&this._adjustTableRangeWithHeaderRow(),this._showTotalRow&&this._updateTotalRow()}finally{this._owner.endUpdate()}}},e.prototype._detachSheet=function(){this._sheet=null,this._owner=null},e.prototype._pushTableColumns=function(e){var t,o;for(this._columns=[],o=0;o<e.length;o++)(t=e[o])._attach(this),this._columns.push(t)},e.prototype._generateColumns=function(e){var t,n,i,l,s,r=this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid;if(!this._range.isValid)throw"The range of the table is invalid.";this._columns=[];for(var a=0;a<this._range.columnSpan;a++)l=this._sheet.grid.columns[this._range.leftCol+a],s=this._range.topRow*this._sheet.grid.columns.length+this._range.leftCol+a,1===this._range.rowSpan?t=this._getUniqueColumnName(a+1):(t=this._sheet.grid.getCellData(this._range.topRow,this._range.leftCol+a,!1)||"",o.isString(t)&&"="===t[0]&&(t=this._owner.evaluate(t,"",this._sheet,!1)),i=this._sheet._styledCells[s],t=this._owner._formatEvaluatedResult(t,l,i?i.format:""),t=this._getUniqueColumnName(a+1,t.toString())),e&&this._range.rowSpan>1&&(this._orgHeaderCellsContent[a]=this._sheet.grid.getCellData(this._range.topRow,this._range.leftCol+a,!1),isNaN(+t)||l.format||i&&i.format||(i?i.format="@":this._sheet._styledCells[s]={format:"@"}),r.setCellData(this._range.topRow,this._range.leftCol+a,t,!1)),(n=new te(t))._attach(this),0===a?n._totalRowLabel="Total":a===this._range.columnSpan-1&&(n._totalRowFunction="Sum"),this._columns.push(n)},e.prototype._getTableCellAppliedStyles=function(e,t){var o,n={},i=!1,l=!1,s=0;return this._showHeaderRow&&(s=1),this._showHeaderRow&&0===e?i=!0:this._showTotalRow&&e===this._range.rowSpan-1&&(l=!0),this._extendStyle(n,this._style.wholeTableStyle,e,t,i,l),i||l||(!this._showBandedColumns||null==this._style.firstBandedColumnStyle&&null==this._style.secondBandedColumnStyle||(t%((o=this._style.firstBandedColumnStyle?null==this._style.firstBandedColumnStyle.size?1:this._style.firstBandedColumnStyle.size:1)+(this._style.secondBandedColumnStyle?null==this._style.secondBandedColumnStyle.size?1:this._style.secondBandedColumnStyle.size:1))>=o?this._style.secondBandedColumnStyle&&this._extendStyle(n,this._style.secondBandedRowStyle,e,t,i,l):this._style.firstBandedColumnStyle&&this._extendStyle(n,this._style.firstBandedColumnStyle,e,t,i,l)),!this._showBandedRows||null==this._style.firstBandedRowStyle&&null==this._style.secondBandedRowStyle||((e-s)%((o=this._style.firstBandedRowStyle?null==this._style.firstBandedRowStyle.size?1:this._style.firstBandedRowStyle.size:1)+(this._style.secondBandedRowStyle?null==this._style.secondBandedRowStyle.size?1:this._style.secondBandedRowStyle.size:1))>=o?this._style.secondBandedRowStyle&&this._extendStyle(n,this._style.secondBandedRowStyle,e,t,i,l):this._style.firstBandedRowStyle&&this._extendStyle(n,this._style.firstBandedRowStyle,e,t,i,l))),this._alterLastColumn&&t===this._range.columnSpan-1&&this._style.lastColumnStyle&&this._extendStyle(n,this._style.lastColumnStyle,e,t,i,l),this._alterFirstColumn&&0===t&&this._style.firstColumnStyle&&this._extendStyle(n,this._style.firstColumnStyle,e,t,i,l),i?(this._style.headerRowStyle&&this._extendStyle(n,this._style.headerRowStyle,e,t,i,l),t===this._range.columnSpan-1&&this._style.lastHeaderCellStyle&&this._extendStyle(n,this._style.lastHeaderCellStyle,e,t,i,l),0===t&&this._style.firstHeaderCellStyle&&this._extendStyle(n,this._style.firstHeaderCellStyle,e,t,i,l)):l&&(this._style.totalRowStyle&&this._extendStyle(n,this._style.totalRowStyle,e,t,i,l),t===this._range.columnSpan-1&&this._style.lastTotalCellStyle&&this._extendStyle(n,this._style.lastTotalCellStyle,e,t,i,l),0===t&&this._style.firstTotalCellStyle&&this._extendStyle(n,this._style.firstTotalCellStyle,e,t,i,l)),n},e.prototype._applyStylesForCell=function(e,t){var o,n=t.style;for(var i in e)(o=e[i])&&(n[i]=o)},e.prototype._extendStyle=function(e,t,o,n,i,l){var s;for(var r in t)null!==(s=t[r])&&(r.indexOf("borderTop")>-1?(0===o||l)&&(e[r]=s):r.indexOf("borderBottom")>-1?(o===this._range.rowSpan-1||i)&&(e[r]=s):r.indexOf("borderLeft")>-1?0===n&&(e[r]=s):r.indexOf("borderRight")>-1?n===this._range.columnSpan-1&&(e[r]=s):r.indexOf("borderHorizontal")>-1?o<this._range.rowSpan-1&&("borderHorizontalStyle"===r?e.borderBottomStyle=s:"borderHorizontalWidth"===r?e.borderBottomWidth=s:e.borderBottomColor=s):r.indexOf("borderVertical")>-1?n<this._range.columnSpan-1&&("borderVerticalStyle"===r?e.borderRightStyle=s:"borderVerticalWidth"===r?e.borderRightWidth=s:e.borderRightColor=s):e[r]=s)},e.prototype._getSubtotalFunction=function(e){switch(e){case"average":return"101";case"countnums":return"102";case"count":return"103";case"max":return"104";case"min":return"105";case"stddev":return"107";case"sum":return"109";case"var":return"110"}return null},e.prototype._checkColumnNameExist=function(e){var t,o=this.getColumns();for(t=0;t<o.length;t++)if(o[t].name.toLowerCase()===e.toLowerCase())return!0;return!1},e.prototype._adjustTableRangeWithHeaderRow=function(){var e,t,n,l,s=this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid;if(this._showHeaderRow){if(this._sheet._needMoveDownTable(this)){if(n=this.getRange(),l=new i.CellRange(n.bottomRow+1,n.col,n.bottomRow+1,n.col2),!this._sheet._canShiftCells(l))throw"The operation is not allowed.  The operation is attempting to shift the cells in a table or a merged cell on the current sheet.";1===this._sheet._needAddRowCountForInsertTableRows(1,n)&&(s.collectionView?(s.collectionView.beginUpdate(),s.itemsSource instanceof o.CollectionView?s.itemsSource.sourceCollection.push({}):s.itemsSource.push({}),s.collectionView.endUpdate()):s.rows.push(new i.Row)),this._sheet._moveDownCells(1,l),this._sheet._moveDownTable(this)}for(this._range.row<=this._range.row2?this._range.row-=1:this._range.row2-=1,e=0;e<this._columns.length;e++)t=this._columns[e],this._orgHeaderCellsContent[e]=s.getCellData(this._range.topRow,this._range.leftCol+e,!1),s.setCellData(this._range.topRow,this._range.leftCol+e,t.name)}else{for(e=this._range.leftCol;e<=this._range.rightCol;e++)s.setCellData(this._range.topRow,e,"");this._range.row<=this._range.row2?this._range.row+=1:this._range.row2+=1}},e.prototype._adjustTableRangeWithTotalRow=function(){var e,t,n,l=this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid;if(t=this.getRange(),n=new i.CellRange(t.bottomRow+1,t.col,t.bottomRow+1,t.col2),this._showTotalRow){if(this._sheet._canShiftCells(n))1===this._sheet._needAddRowCountForInsertTableRows(1,t)&&(l.collectionView?(l.collectionView.beginUpdate(),l.itemsSource instanceof o.CollectionView?l.itemsSource.sourceCollection.push({}):l.itemsSource.push({}),l.collectionView.endUpdate()):l.rows.push(new i.Row)),this._sheet._moveDownCells(1,n),this._owner._updateAffectedFormula(this._range.bottomRow+1,1,!0,!0);else if(!this._beneathRowIsEmpty())throw"The operation is not allowed.  The operation is attempting to shift the cells in a table or a merged cell on the current sheet.";this._range.row<=this._range.row2?this._range.row2+=1:this._range.row+=1,this._updateTotalRow()}else{for(e=this._range.leftCol;e<=this._range.rightCol;e++)l.setCellData(this._range.bottomRow,e,"");this._sheet._canShiftCells(n)&&(this._sheet._moveUpCells(1,n),this._owner._updateAffectedFormula(this._range.bottomRow+1,1,!1,!0)),this._range.row<=this._range.row2?this._range.row2-=1:this._range.row-=1}},e.prototype._updateTotalRow=function(){var e;if(this.showTotalRow)for(var t=0;t<this._columns.length;t++)e=this._columns[t],this._updateColumnTotalRowContent(e,t)},e.prototype._getUniqueColumnName=function(e,t){var o,n=1;if(t||(t="Column"+e),this._checkColumnNameExist(t)){for(o=t+n;this._checkColumnNameExist(o);)o=t+ ++n;t=o}return t},e.prototype._moveColumns=function(e,t){if(this._columns){var o=this._columns[e];this._columns.splice(e,1),t<0&&(t=this._columns.length),this._columns.splice(t,0,o)}},e.prototype._canInsertRowsWithoutShift=function(e){var t,o,n,i,l,s=this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid;if(this._range.bottomRow+e>=s.rows.length)return!1;for(t=1;t<=e;t++)for(o=this._range.bottomRow+t,n=this._range.leftCol;n<=this._range.rightCol;n++)if(i=s.getCellData(o,n,!1),l=this._sheet.getCellStyle(o,n),null!=i&&""!==i||null!=l)return!1;return!0},e.prototype._beneathRowIsEmpty=function(){var e,t,o,n=this._range.bottomRow+1,i=this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid;if(n>=i.rows.length)return!1;for(e=this._range.leftCol;e<=this._range.rightCol;e++){if(null!=(t=i.getCellData(this._range.bottomRow+1,e,!1))&&""!==t)return!1;if(null!=this._sheet.getCellStyle(this._range.bottomRow+1,e))return!1;if(null!=this._sheet.findTable(n,e))return null;if(o=n*i.columns.length+e,null!=this._sheet._mergedRanges[o])return!1}return!0},e.prototype._getDataRange=function(){var e=this._range.topRow,t=this._range.bottomRow;return this._showHeaderRow&&(e+=1),this._showTotalRow&&(t-=1),new i.CellRange(e,this._range.leftCol,t,this._range.rightCol)},e.prototype._getHeaderRange=function(){return this._showHeaderRow?new i.CellRange(this._range.topRow,this._range.leftCol,this._range.topRow,this._range.rightCol):null},e.prototype._getFooterRange=function(){return this._showTotalRow?new i.CellRange(this._range.bottomRow,this._range.leftCol,this._range.bottomRow,this._range.rightCol):null},e.prototype._getColumnIndex=function(e){var t,n,i;if(o.isInt(e)&&e>=0&&e<this._columns.length)t=e;else{e instanceof te?n=e.name.toLowerCase():o.isString(e)&&""!==e&&(n=e.toLowerCase()),i=this.getColumns();for(var l=0;l<i.length;l++)if(i[l].name.toLowerCase()===n){t=l;break}}return t},e}();t.Table=ee;var te=function(){function e(e,t,o,n){void 0===n&&(n=!0),this._name=e,this._totalRowLabel=t,this._totalRowFunction=o,null!=n&&(this._showFilterButton=n)}return Object.defineProperty(e.prototype,"table",{get:function(){return this._table},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"name",{get:function(){return this._name},set:function(e){e!==this._name&&(this._name=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"totalRowLabel",{get:function(){return this._totalRowLabel},set:function(e){e!==this._totalRowLabel&&(this._totalRowLabel=e,this._updateTableTotalInfo())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"totalRowFunction",{get:function(){return this._totalRowFunction},set:function(e){e!==this._totalRowFunction&&(this._totalRowFunction=e,this._updateTableTotalInfo())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"showFilterButton",{get:function(){return this._showFilterButton},set:function(e){this._showFilterButton!==e&&(this._showFilterButton=e)},enumerable:!0,configurable:!0}),e.prototype._attach=function(e){this._table=e},e.prototype._updateTableTotalInfo=function(){this._table&&this._table.showTotalRow&&(this._table._updateColumnTotalRowContent(this),this._table._owner&&this._table._owner.refresh())},e}();t.TableColumn=te;var oe=function(){function e(e,t){void 0===t&&(t=!1),this._name=e,this._isBuiltIn=t}return Object.defineProperty(e.prototype,"name",{get:function(){return this._name},set:function(e){e!==this._name&&(this._name=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"wholeTableStyle",{get:function(){return this._wholeTableStyle},set:function(e){this._wholeTableStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"firstBandedColumnStyle",{get:function(){return this._firstBandedColumnStyle},set:function(e){this._firstBandedColumnStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"secondBandedColumnStyle",{get:function(){return this._secondBandedColumnStyle},set:function(e){this._secondBandedColumnStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"firstBandedRowStyle",{get:function(){return this._firstBandedRowStyle},set:function(e){this._firstBandedRowStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"secondBandedRowStyle",{get:function(){return this._secondBandedRowStyle},set:function(e){this._secondBandedRowStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"firstColumnStyle",{get:function(){return this._firstColumnStyle},set:function(e){this._firstColumnStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"lastColumnStyle",{get:function(){return this._lastColumnStyle},set:function(e){this._lastColumnStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"headerRowStyle",{get:function(){return this._headerRowStyle},set:function(e){this._headerRowStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"totalRowStyle",{get:function(){return this._totalRowStyle},set:function(e){this._totalRowStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"firstHeaderCellStyle",{get:function(){return this._firstHeaderCellStyle},set:function(e){this._firstHeaderCellStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"lastHeaderCellStyle",{get:function(){return this._lastHeaderCellStyle},set:function(e){this._lastHeaderCellStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"firstTotalCellStyle",{get:function(){return this._firstTotalCellStyle},set:function(e){this._firstTotalCellStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"lastTotalCellStyle",{get:function(){return this._lastTotalCellStyle},set:function(e){this._lastTotalCellStyle=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isBuiltIn",{get:function(){return this._isBuiltIn},enumerable:!0,configurable:!0}),e}();t.TableStyle=oe;var ne;!function(e){e[e.All=0]="All",e[e.Data=1]="Data",e[e.Header=2]="Header",e[e.Footer=3]="Footer"}(ne=t.TableSection||(t.TableSection={}));var ie=function(e){function t(t){return e.call(this,t)||this}return __extends(t,e),t.prototype.apply=function(e){var t,o=this.column.grid;return!(o instanceof O)||(!this.showValues||!Object.keys(this.showValues).length||(o.rows[e]instanceof i._NewRowTemplate||(t=this.dataMap||this.column.dataMap,e=t?t.getDisplayValue(o.getCellValue(e,this.column.index)):o.getCellValue(e,this.column.index,!0),void 0!=this.showValues[e])))},t}(r.ValueFilter);t.FlexSheetValueFilter=ie;var le=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.updateEditor=function(){var t,o,n,l,s,r,a,h,d,c=this.filter.column,u=c.grid,_=c.index,g=[],f={};if(this.filter.uniqueValues||null!=u.itemsSource&&null!=u.childItemsPath)e.prototype.updateEditor.call(this);else{for(m=0;m<u.rows.length;m++)s=this.filter.apply(m),l=this.filter.showValues,this.filter.showValues=null,r=u.filter._filter(m),this.filter.showValues=l,(!(o=u.getMergedRange(u.cells,m,_))||m===o.topRow&&_===o.leftCol)&&((t=u.rows[m])instanceof G||t instanceof i.GroupRow||t instanceof i._NewRowTemplate||!(t.visible||!s&&r)||(n=u.getCellValue(m,_),a=this.filter.dataMap?this.filter.dataMap.getDisplayValue(n):u.getCellValue(m,_,!0),n=""===n?null:n,h=u.getCellData(m,_,!0),f[a]||(f[a]=!0,d=h&&"="===h[0]?m+"_"+_:"",g.push({value:n,text:a,cellRef:d}))));var p=this.filter.showValues;if(p&&0!=Object.keys(p).length){for(var w in p)for(m=0;m<g.length;m++)if(p[w]&&""!==g[m].cellRef&&g[m].cellRef===p[w].cellRef)p[g[m].text]={show:!0,cellRef:g[m].cellRef},g[m].show=!0,delete p[w];else if(g[m].text==w){g[m].show=!0;break}}else for(var m=0;m<g.length;m++)g[m].show=!0;this._lbValues.isContentHtml=c.isContentHtml,this._cmbFilter.text=this.filter.filterText,this._filterText=this._cmbFilter.text.toLowerCase(),this._view.pageSize=this.filter.maxValues,this._view.sourceCollection=g,this._view.moveCurrentToPosition(-1)}},t.prototype.updateFilter=function(){var e=null,t=this._view.items;if(this._filterText||this._cbSelectAll.indeterminate){e={};for(var o=0;o<t.length;o++){var n=t[o];n.show&&(e[n.text]={show:!0,cellRef:n.cellRef})}}this._filter.showValues=e,this._filter.filterText=this._filterText},t}(r.ValueFilterEditor);t.FlexSheetValueFilterEditor=le;var se=function(e){function t(t){return e.call(this,t)||this}return __extends(t,e),t.prototype.apply=function(e){var t,n,l,s,r=this.column,a=r.grid,h=this.condition1,d=this.condition2;if(!(a instanceof O))return!0;if(!this.isActive)return!0;if(a.rows[e]instanceof i._NewRowTemplate)return!0;""===(t=a.getCellValue(e,r.index))&&r.dataType!==o.DataType.String&&(t=null),n=l=t,(s=this.dataMap||r.dataMap)?n=l=t=s.getDisplayValue(t):o.isDate(t)?(o.isString(h.value)||o.isString(d.value))&&(n=l=t=a.getCellValue(e,r.index,!0)):o.isNumber(t)&&(n=l=t=o.Globalize.parseFloat(a.getCellValue(e,r.index,!0)),0!==t||r.dataType||(h.isActive&&""===h.value&&(n=t.toString()),d.isActive&&""===d.value&&(l=l.toString())));var c=h.apply(n),u=d.apply(l);return h.isActive&&d.isActive?this.and?c&&u:c||u:h.isActive?c:!d.isActive||u},t}(r.ConditionFilter);t.FlexSheetConditionFilter=se;var re=function(e){function t(t,o){var n=e.call(this,t,o)||this;return n._valueFilter=new ie(o),n._conditionFilter=new se(o),n}return __extends(t,e),t}(r.ColumnFilter);t.FlexSheetColumnFilter=re;var ae=function(e){function t(t,o,n){void 0===n&&(n=!0);var i,l,s=e.call(this,t,o,n)||this,r=s;return n&&(s._divSort.style.display=""),i=s.cloneElement(s._btnAsc),l=s.cloneElement(s._btnDsc),s._btnAsc.parentNode.replaceChild(i,s._btnAsc),s._btnDsc.parentNode.replaceChild(l,s._btnDsc),i.addEventListener("click",function(e){r._sortBtnClick(e,!0)}),l.addEventListener("click",function(e){r._sortBtnClick(e,!1)}),s}return __extends(t,e),t.prototype._showFilter=function(t){t==r.FilterType.Value&&null==this._edtVal&&(this._edtVal=new le(this._divEdtVal,this.filter.valueFilter)),e.prototype._showFilter.call(this,t)},t.prototype._sortBtnClick=function(e,t){var o,n,i=this.filter.column,l=i.grid.sortManager;e.preventDefault(),e.stopPropagation(),(o=l.checkSortItemExists(i.index))>-1?(l.sortDescriptions.moveCurrentToPosition(o),l.sortDescriptions.currentItem.ascending=t,n=-o):(l.addSortLevel(i.index,t),n=-(l.sortDescriptions.items.length-1)),l.moveSortLevel(n),l.commitSort(),this.updateEditor(),this.onButtonClicked()},t.prototype.cloneElement=function(e){for(var t=e.cloneNode();e.firstChild;)t.appendChild(e.lastChild);return t},t}(r.ColumnFilterEditor);t.FlexSheetColumnFilterEditor=ae;var he=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),Object.defineProperty(t.prototype,"filterDefinition",{get:function(){for(var e={filters:[]},t=0;t<this._filters.length;t++){var o=this._filters[t];if(o&&o.column)if(o.conditionFilter.isActive){var n=o.conditionFilter;e.filters.push({columnIndex:o.column.index,type:"condition",condition1:{operator:n.condition1.operator,value:n.condition1.value},and:n.and,condition2:{operator:n.condition2.operator,value:n.condition2.value}})}else if(o.valueFilter.isActive){var i=o.valueFilter;e.filters.push({columnIndex:o.column.index,type:"value",filterText:i.filterText,showValues:i.showValues})}}return JSON.stringify(e)},set:function(e){var t=JSON.parse(o.asString(e));this.clear();for(var n=0;n<t.filters.length;n++){var i=t.filters[n],l=this.grid.columns[i.columnIndex],s=this.getColumnFilter(l,!0);if(s)switch(i.type){case"condition":var r=s.conditionFilter;r.condition1.value=l.dataType==o.DataType.Date?o.changeType(i.condition1.value,l.dataType,null):i.condition1.value,r.condition1.operator=i.condition1.operator,r.and=i.and,r.condition2.value=l.dataType==o.DataType.Date?o.changeType(i.condition2.value,l.dataType,null):i.condition2.value,r.condition2.operator=i.condition2.operator;break;case"value":var a=s.valueFilter;a.filterText=i.filterText,a.showValues=i.showValues}}this.apply()},enumerable:!0,configurable:!0}),t.prototype.apply=function(){var e=this;e.grid.deferUpdate(function(){for(var t,n,l,s=-1,r=0;r<e.grid.rows.length;r++)if(!((t=e.grid.rows[r])instanceof G||r<=s))if(s=-1,n=e._filter(r),t instanceof i.GroupRow){if(l=t.getCellRange(),null==t.dataItem||t.dataItem instanceof o.CollectionViewGroup)t.visible=e._checkGroupVisible(l);else if(t.visible=n,s=l.bottomRow,l.isValid)for(var a=l.topRow;a<=l.bottomRow;a++)e.grid.rows[a].visible=n}else t.visible=n;e.grid._isCopying||e.grid._isUndoing||e.grid._isSorting||e.onFilterApplied()})},t.prototype.editColumnFilter=function(e,t){var n=this,l=n.grid;n.closeEditor(),e=n._asColumn(e);var s=document.createElement("div"),r=n.getColumnFilter(e),a=new ae(s,r,n.showSortButtons);o.addClass(s,"wj-dropdown-panel"),n._divEdt=s,n._edtCol=e;var h=new i.CellRangeEventArgs(l.cells,new i.CellRange(-1,e.index));if(n.onFilterChanging(h),h.cancel)return n._divEdt=null,void(n._edtCol=null);h.cancel=!0,l.undoStack.stackSize>0&&(n._undoAcion=new V(l)),l.rightToLeft&&(s.dir="rtl"),a.filterChanged.addHandler(function(){h.cancel=!1,n._filterChanged=!0,setTimeout(function(){h.cancel||(n.apply(),n._undoAcion&&(n._undoAcion.saveNewState(),l.undoStack._addAction(n._undoAcion),n._undoAcion=null))})}),a.buttonClicked.addHandler(function(){n.closeEditor(),l.focus(),n.onFilterChanged(h)}),a.lostFocus.addHandler(function(){setTimeout(function(){var e=o.Control.getControl(n._divEdt);e&&!e.containsFocus()&&n.closeEditor()},10)}),l._edtHdl._commitRowEdits(),l.scrollIntoView(-1,e.index,!0);var d=n.grid.columnHeaders,c=t?t.row:d.rows.length-1,u=t?t.col:e.index,_=d.getCellBoundingRect(c,u),g=document.elementFromPoint(_.left+_.width/2,_.top+_.height/2);(g=o.closest(g,".wj-cell"))?o.showPopup(s,g,!1,!1,!1):o.showPopup(s,_),n._setAriaExpanded(g,!0),n._setAriaExpanded(l.cells.getCellElement(-1,u),!0);for(var f=a.hostElement.querySelectorAll("input"),p=0;p<f.length;p++){var w=f[p];if(w.offsetHeight>0&&w.tabIndex>-1&&!w.disabled){w.focus();break}}a.containsFocus()||a.focus()},t.prototype.closeEditor=function(){this._undoAcion&&!this._filterChanged&&(this._undoAcion=null),e.prototype.closeEditor.call(this)},t.prototype.getColumnFilter=function(e,t){if(void 0===t&&(t=!0),o.isString(e)?e=this.grid.columns.getColumn(e):o.isNumber(e)&&(e=this.grid.columns[e]),!e)return null;e=o.asType(e,i.Column);for(var n=0;n<this._filters.length;n++)if(this._filters[n].column==e)return this._filters[n];if(t){var l=new re(this,e);return this._filters.push(l),l}return null},t.prototype._checkGroupVisible=function(e){for(var t,o=!0,n=e.topRow+1;n<=e.bottomRow;n++)if(t=this.grid.rows[n])if(t instanceof i.GroupRow)o=this._checkGroupVisible(t.getCellRange());else if(o=this._filter(n))break;return o},t}(r.FlexGridFilter);t.FlexSheetFilter=he});