From e8ac0e22784f9dbb18965d172e1d2fef34c64bb9 Mon Sep 17 00:00:00 2001 From: mengshukeji Date: Wed, 16 Dec 2020 13:30:11 +0800 Subject: [PATCH] style(formula.js): style 1.VSCODE format formula.js 2.Update FAQ --- docs/guide/FAQ.md | 6 + docs/zh/guide/FAQ.md | 6 + src/global/formula.js | 2174 ++++++++++++++++++++--------------------- src/index.html | 2 +- 4 files changed, 1100 insertions(+), 1088 deletions(-) diff --git a/docs/guide/FAQ.md b/docs/guide/FAQ.md index eca2ef3..fbdb8b5 100644 --- a/docs/guide/FAQ.md +++ b/docs/guide/FAQ.md @@ -261,4 +261,10 @@ In this case, after Luckysheet is modified in real time, the changes can be seen **A** The custom attributes directly assigned to the cell object will be filtered. To make the custom attributes take effect, you need to edit the code to remove the filter attributes. +------------ + +## **Q** How to enter text starting with `'='`? For example, `=currentDate('YYYY-MM-DD')`, it will remove the function by default, how to prohibit the function? + +**A** Just add a single quotation mark in front of it, and it will be forcibly recognized as a string, which is consistent with excel. For example: `'=currentDate('YYYY-MM-DD')` + ------------ \ No newline at end of file diff --git a/docs/zh/guide/FAQ.md b/docs/zh/guide/FAQ.md index d82d56a..58c0f38 100644 --- a/docs/zh/guide/FAQ.md +++ b/docs/zh/guide/FAQ.md @@ -262,4 +262,10 @@ Luckysheet教程里采用的CDN链接是 [jsdelivr](https://www.jsdelivr.com/pac **A** 直接赋值到单元格对象上的自定义属性会被过滤,要想使得自定义属性生效,需要二开去除过滤属性的代码。 +------------ + +## **Q** 如何输入以`'='`开头的文本?例如`=currentDate('YYYY-MM-DD')`,它默认会去掉函数,函数怎么禁止? + +**A** 前面加一个单引号就行,会强制识别为字符串,和excel表现一致的。比如:`'=currentDate('YYYY-MM-DD')` + ------------ \ No newline at end of file diff --git a/src/global/formula.js b/src/global/formula.js index 40befb2..4f5cd9f 100644 --- a/src/global/formula.js +++ b/src/global/formula.js @@ -6,13 +6,13 @@ import sheetmanage from '../controllers/sheetmanage'; import menuButton from '../controllers/menuButton'; import server from '../controllers/server'; import luckysheetFreezen from '../controllers/freezen'; -import {checkProtectionLocked,checkProtectionCellHidden} from '../controllers/protection'; +import { checkProtectionLocked, checkProtectionCellHidden } from '../controllers/protection'; import dataVerificationCtrl from '../controllers/dataVerificationCtrl'; import { seletedHighlistByindex, luckysheet_count_show } from '../controllers/select'; import { isRealNum, isRealNull, valueIsError, isEditMode } from './validate'; import { isdatetime, isdatatype } from './datecontroll'; -import { getCellTextSplitArr,getCellTextInfo } from '../global/getRowlen'; -import { getcellvalue,getcellFormula,getInlineStringNoStyle, getOrigincell } from './getdata'; +import { getCellTextSplitArr, getCellTextInfo } from '../global/getRowlen'; +import { getcellvalue, getcellFormula, getInlineStringNoStyle, getOrigincell } from './getdata'; import { setcellvalue } from './setdata'; import { genarate, valueShowEs } from './format'; import editor from './editor'; @@ -20,10 +20,10 @@ import tooltip from './tooltip'; import { rowLocation, colLocation, colLocationByIndex, mouseposition } from './location'; import { luckysheetRangeLast } from './cursorPos'; import { jfrefreshgrid } from './refresh'; -import { isInlineStringCell,convertSpanToShareString } from '../controllers/inlineString'; +import { isInlineStringCell, convertSpanToShareString } from '../controllers/inlineString'; // import luckysheet_function from '../function/luckysheet_function'; // import functionlist from '../function/functionlist'; -import { luckysheet_compareWith, luckysheet_getarraydata, luckysheet_getcelldata, luckysheet_parseData, luckysheet_getValue, luckysheet_indirect_check, luckysheet_indirect_check_return, luckysheet_offset_check,luckysheet_calcADPMM,luckysheet_getSpecialReference } from '../function/func'; +import { luckysheet_compareWith, luckysheet_getarraydata, luckysheet_getcelldata, luckysheet_parseData, luckysheet_getValue, luckysheet_indirect_check, luckysheet_indirect_check_return, luckysheet_offset_check, luckysheet_calcADPMM, luckysheet_getSpecialReference } from '../function/func'; import Store from '../store'; import locale from '../locale/locale'; import json from './json'; @@ -40,68 +40,68 @@ const luckysheetformula = { nl: "#NULL!", //交叉运算符(空格)使用不正确 sp: "#SPILL!" //数组范围有其它值 }, - errorInfo: function(err) { + errorInfo: function (err) { return err; }, - errorParamCheck: function(thisp, data, i) { + errorParamCheck: function (thisp, data, i) { let type, require; let _locale = locale(); let locale_formulaMore = _locale.formulaMore; - if(i < thisp.length){ + if (i < thisp.length) { type = thisp[i].type; require = thisp[i].require; } - else{ + else { type = thisp[thisp.length - 1].type; require = thisp[thisp.length - 1].require; } - if(require == "o" && (data == null || data == "")){ + if (require == "o" && (data == null || data == "")) { return [true, locale_formulaMore.tipSuccessText]; } - if(type.indexOf("all") > -1){ + if (type.indexOf("all") > -1) { return [true, locale_formulaMore.tipSuccessText]; } - else{ - if(type.indexOf("range") > -1 && (getObjType(data) == "object" || getObjType(data) == "array")){ + else { + if (type.indexOf("range") > -1 && (getObjType(data) == "object" || getObjType(data) == "array")) { return [true, locale_formulaMore.tipSuccessText]; } - if(type.indexOf("number") > -1 && (isRealNum(data) || getObjType(data) == "boolean")){ + if (type.indexOf("number") > -1 && (isRealNum(data) || getObjType(data) == "boolean")) { return [true, locale_formulaMore.tipSuccessText]; } - - if(type.indexOf("string") > -1 && getObjType(data) == "string"){ + + if (type.indexOf("string") > -1 && getObjType(data) == "string") { return [true, locale_formulaMore.tipSuccessText]; } - if(type.indexOf("date") > -1 && isdatetime(data)){ + if (type.indexOf("date") > -1 && isdatetime(data)) { return [true, locale_formulaMore.tipSuccessText]; } return [false, locale_formulaMore.tipParamErrorText]; } }, - getPureValueByData: function(data){ - if(data.length == 0){ + getPureValueByData: function (data) { + if (data.length == 0) { return []; } let output = []; - if(getObjType(data) == "array"){ - if(getObjType(data[0]) == "array"){ - for(let r = 0; r < data.length; r++){ + if (getObjType(data) == "array") { + if (getObjType(data[0]) == "array") { + for (let r = 0; r < data.length; r++) { let row = []; - for(let c = 0; c < data[0].length; c++){ + for (let c = 0; c < data[0].length; c++) { let cell = data[r][c]; - if(getObjType(cell) == "object"){ + if (getObjType(cell) == "object") { row.push(cell.v); } - else{ + else { row.push(cell); } } @@ -109,14 +109,14 @@ const luckysheetformula = { output.push(row); } } - else{ - for(let i = 0; i < data.length; i++){ + else { + for (let i = 0; i < data.length; i++) { let cell = data[i]; - if(getObjType(cell) == "object"){ + if (getObjType(cell) == "object") { output.push(cell.v); } - else{ + else { output.push(cell); } } @@ -125,10 +125,10 @@ const luckysheetformula = { else { let cell = data; - if(getObjType(cell) == "object"){ + if (getObjType(cell) == "object") { output.push(cell.v); } - else{ + else { output.push(cell); } } @@ -136,41 +136,41 @@ const luckysheetformula = { return output; }, //sparklines添加 - readCellDataToOneArray: function(rangeValue){ + readCellDataToOneArray: function (rangeValue) { let _this = this; - if(rangeValue == null){ + if (rangeValue == null) { return []; } - if(getObjType(rangeValue) != "object"){ + if (getObjType(rangeValue) != "object") { return [rangeValue]; } let dataformat = []; let data = []; - if(rangeValue != null && rangeValue.data != null){ + if (rangeValue != null && rangeValue.data != null) { data = rangeValue.data; } - else if(rangeValue != null && !isRealNull(rangeValue.v)){ + else if (rangeValue != null && !isRealNull(rangeValue.v)) { return [rangeValue.v]; } - else{ + else { return []; } //适配excel的动态数组格式,{1,2,3,4,5}或者{{1,2,3},{4,5,6},{7,8,9}} - if(getObjType(data) == "array"){ + if (getObjType(data) == "array") { data = _this.getPureValueByData(data); } - else if(getObjType(data) == "object"){ + else if (getObjType(data) == "object") { data = data.v; return [data]; } - else{ - if(/\{.*?\}/.test(data)){ + else { + if (/\{.*?\}/.test(data)) { data = data.replace(/\{/g, "[").replace(/\}/g, "]"); } @@ -179,12 +179,12 @@ const luckysheetformula = { //把二维数组转换为一维数组,sparklines要求数据格式为一维数组 //let dataformat = []; - if(getObjType(data[0]) == "array"){ - for(let i = 0; i < data.length; i++){ + if (getObjType(data[0]) == "array") { + for (let i = 0; i < data.length; i++) { dataformat = dataformat.concat(data[i]); } } - else{ + else { dataformat = data; } @@ -192,71 +192,71 @@ const luckysheetformula = { }, //sparklines添加 //获得函数里某个参数的值,使用此函数需要在函数中执行luckysheet_getValue方法 - getValueByFuncData: function(value, arg){ - if(value == null){ + getValueByFuncData: function (value, arg) { + if (value == null) { return null; } let _this = this; - - if(getObjType(value) == "array"){ - if(arg == "avg"){ + + if (getObjType(value) == "array") { + if (arg == "avg") { return luckysheet_function.AVERAGE.f.apply(luckysheet_function.AVERAGE, value); } - else if(arg == "sum"){ + else if (arg == "sum") { return luckysheet_function.SUM.f.apply(luckysheet_function.SUM, value); } - else{ - if(getObjType(value[0]) == "object"){ + else { + if (getObjType(value[0]) == "object") { return luckysheet.mask.getValueByFormat(value[0]); } - else{ + else { return value[0]; } } } - else if(getObjType(value) == "object"){ + else if (getObjType(value) == "object") { return luckysheet.mask.getValueByFormat(value); } - else{ + else { return value; } }, //sparklines添加 - sparklinesColorMap:function(args, len){ + sparklinesColorMap: function (args, len) { let _this = this; let colorLists = null; - - if(len == null){ + + if (len == null) { len = 5; } let index = 0; - - if(args.length > len){ - for(let i = len; i < args.length; i++){ + + if (args.length > len) { + for (let i = len; i < args.length; i++) { let colorMap = args[i]; let colorListArray = _this.readCellDataToOneArray(colorMap); - for(let a = 0; a < colorListArray.length; a++){ + for (let a = 0; a < colorListArray.length; a++) { let ca = colorListArray[a]; - if(ca.indexOf(":") > -1){ - if(!colorLists){ + if (ca.indexOf(":") > -1) { + if (!colorLists) { colorLists = {}; } let calist = ca.split(":"); - if(calist.length == 2){ + if (calist.length == 2) { colorLists[calist[0]] = calist[1]; } - else if(calist.length > 1){ + else if (calist.length > 1) { colorLists[calist[0] + ":" + calist[1]] = calist[2]; } } - else{ - if(!colorLists){ + else { + if (!colorLists) { colorLists = []; } @@ -271,7 +271,7 @@ const luckysheetformula = { return colorLists; }, //sparklines添加 - colorList: ["#2ec7c9", "#fc5c5c", "#5ab1ef", "#ffb980", "#d87a80", "#8d98b3", "#e5cf0d", "#97b552", "#95706d","#dc69aa","#07a2a4","#9a7fd1","#588dd5","#f5994e","#c05050","#59678c","#c9ab00","#7eb00a","#6f5553","#c14089"], + colorList: ["#2ec7c9", "#fc5c5c", "#5ab1ef", "#ffb980", "#d87a80", "#8d98b3", "#e5cf0d", "#97b552", "#95706d", "#dc69aa", "#07a2a4", "#9a7fd1", "#588dd5", "#f5994e", "#c05050", "#59678c", "#c9ab00", "#7eb00a", "#6f5553", "#c14089"], classlist: { "province": { 11: "北京", @@ -312,7 +312,7 @@ const luckysheetformula = { } }, oldvalue: null, - dontupdate: function() { + dontupdate: function () { let _this = this; Store.luckysheetCellUpdate.length = 0; //clear array $("#luckysheet-functionbox-cell, #luckysheet-rich-text-editor").html(_this.oldvalue); @@ -321,13 +321,13 @@ const luckysheetformula = { sheetmanage.changeSheetExec(_this.rangetosheet); } }, - fucntionboxshow: function(r, c) { + fucntionboxshow: function (r, c) { - if(!checkProtectionCellHidden(r, c, Store.currentSheetIndex)){ + if (!checkProtectionCellHidden(r, c, Store.currentSheetIndex)) { $("#luckysheet-functionbox-cell").html(""); return; } - + let _this = this; let d = Store.flowdata; @@ -336,13 +336,13 @@ const luckysheetformula = { if (d[r] != null && d[r][c] != null) { let cell = $.extend(true, {}, d[r][c]); - if(isInlineStringCell(cell)){ + if (isInlineStringCell(cell)) { value = getInlineStringNoStyle(r, c); } - else if(cell.f != null){ + else if (cell.f != null) { value = getcellvalue(r, c, d, "f"); } - else{ + else { value = valueShowEs(r, c, d); } } @@ -351,14 +351,14 @@ const luckysheetformula = { $("#luckysheet-functionbox-cell").html(value); }, //获得某个单元格或区域的偏移一定距离后的单元格( Sheet1!B6:C8 格式) - cellOffset: function(range,rows,cols,height,width){// 参数:range or cell , rows,cols,height,width + cellOffset: function (range, rows, cols, height, width) {// 参数:range or cell , rows,cols,height,width let startCell = range.startCell; let rowl = range.rowl; let coll = range.coll; let startCellRow = parseInt(startCell.replace(/[^0-9]/g, "")); let startCellCol = ABCatNum(startCell.replace(/[^A-Za-z]/g, "")); - let row = [],col = [],offsetRange; + let row = [], col = [], offsetRange; row[0] = startCellRow + rows; col[0] = startCellCol + cols; @@ -371,72 +371,72 @@ const luckysheetformula = { let cellF = col[0] + row[0]; let cellL = col[1] + row[1]; - if(cellF == cellL){ - offsetRange = range.sheetName + "!"+ cellF; + if (cellF == cellL) { + offsetRange = range.sheetName + "!" + cellF; } - else{ - offsetRange = range.sheetName + "!"+ cellF + ":" + cellL; + else { + offsetRange = range.sheetName + "!" + cellF + ":" + cellL; } return offsetRange; }, - parseDatetoNum: function(date){ //函数中获取到时间格式或者数字形式统一转化为数字进行运算 + parseDatetoNum: function (date) { //函数中获取到时间格式或者数字形式统一转化为数字进行运算 let _this = this; - if(typeof(date) == "object" && typeof date.v == "number"){ + if (typeof (date) == "object" && typeof date.v == "number") { date = date.v; } - else if(isdatatype(date) == "num"){ + else if (isdatatype(date) == "num") { date = parseFloat(date); } - else if(isdatatype(date) == "date"){ + else if (isdatatype(date) == "date") { date = genarate(date)[2]; } - else{ + else { return _this.error.v; } return date; }, //获取一维数组 - getRangeArray: function(range){ + getRangeArray: function (range) { let rangeNow = []; let fmt = "General"; - if(range.length == 1){ //一行 - for(let c = 0; c < range[0].length; c++){ - if(range[0][c] != null && range[0][c].v){ + if (range.length == 1) { //一行 + for (let c = 0; c < range[0].length; c++) { + if (range[0][c] != null && range[0][c].v) { rangeNow.push(range[0][c].v); let f = range[0][c].ct.fa; fmt = (fmt == "General") ? f : fmt; } - else{ + else { //若单元格为null或为空,此处推入null(待考虑是否使用"null") rangeNow.push(null); } } } - else if(range[0].length == 1){ //一列 - for(let r = 0; r < range.length; r++){ - if(range[r][0] != null && range[r][0].v){ + else if (range[0].length == 1) { //一列 + for (let r = 0; r < range.length; r++) { + if (range[r][0] != null && range[r][0].v) { rangeNow.push(range[r][0].v); let f = range[r][0].ct.fa; fmt = (fmt == "General") ? f : fmt; } - else{ + else { rangeNow.push(null); } } } - else{ - for(let r = 0; r < range.length; r++){ - for(let c = 0; c < range[r].length; c++){ - if(range[r][c] != null && range[r][c].v){ + else { + for (let r = 0; r < range.length; r++) { + for (let c = 0; c < range[r].length; c++) { + if (range[r][c] != null && range[r][c].v) { rangeNow.push(range[r][c].v); let f = range[r][c].ct.fa; fmt = (fmt == "General") ? f : fmt; } - else{ + else { rangeNow.push(null); } } @@ -444,59 +444,59 @@ const luckysheetformula = { } range = rangeNow; - + return [range, fmt]; }, //获取二维数组:qksheet格式[[{v,m,ct}] ==> [1] - getRangeArrayTwo: function(range){ + getRangeArrayTwo: function (range) { let data = $.extend(true, [], range); - if(data.length == 1){ //一行 - for(let c = 0; c < data[0].length; c++){ - if(data[0][c] instanceof Object){ - if(data[0][c] != null && data[0][c] instanceof Object && !!data[0][c].m){ + if (data.length == 1) { //一行 + for (let c = 0; c < data[0].length; c++) { + if (data[0][c] instanceof Object) { + if (data[0][c] != null && data[0][c] instanceof Object && !!data[0][c].m) { data[0][c] = data[0][c].m; } - else{ - if(data[0][c] != null && data[0][c] instanceof Object && !!data[0][c].v){ + else { + if (data[0][c] != null && data[0][c] instanceof Object && !!data[0][c].v) { data[0][c] = data[0][c].v; } - else{ + else { data[0][c] = null; } } } } } - else if(data[0].length == 1){ //一列 - for(let r = 0; r < data.length; r++){ - if(data[r][0] instanceof Object){ - if(data[r][0] != null && data[r][0] instanceof Object && !!data[r][0].m){ + else if (data[0].length == 1) { //一列 + for (let r = 0; r < data.length; r++) { + if (data[r][0] instanceof Object) { + if (data[r][0] != null && data[r][0] instanceof Object && !!data[r][0].m) { data[r][0] = data[r][0].m; } - else{ - if(data[r][0] != null && data[r][0] instanceof Object && !!data[r][0].v){ + else { + if (data[r][0] != null && data[r][0] instanceof Object && !!data[r][0].v) { data[r][0] = data[r][0].v; } - else{ + else { data[r][0] = null; } } } } } - else{ - for(let r = 0; r < data.length; r++){ - for(let c = 0; c < data[r].length; c++){ - if(data[r][c] instanceof Object){ - if(data[r][c] != null && data[r][c] instanceof Object && !!data[r][c].m){ + else { + for (let r = 0; r < data.length; r++) { + for (let c = 0; c < data[r].length; c++) { + if (data[r][c] instanceof Object) { + if (data[r][c] != null && data[r][c] instanceof Object && !!data[r][c].m) { data[r][c] = data[r][c].m; } - else{ - if(data[r][c] != null && data[r][c] instanceof Object && !!data[r][c].v){ + else { + if (data[r][c] != null && data[r][c] instanceof Object && !!data[r][c].v) { data[r][c] = data[r][c].v; } - else{ + else { data[r][c] = null; } } @@ -507,83 +507,83 @@ const luckysheetformula = { return data; }, - isWildcard: function(a, b){ //正则匹配通配符: * ? ~* ~?,a目标参数,b通配符 + isWildcard: function (a, b) { //正则匹配通配符: * ? ~* ~?,a目标参数,b通配符 let _this = this; a = a.toString(); b = b.toString(); - - if(_this.isCompareOperator(b).flag){ + + if (_this.isCompareOperator(b).flag) { b = _this.isCompareOperator(b).num; } let str = ""; - for(let i = 0; i < b.length; i++){ + for (let i = 0; i < b.length; i++) { let v = b.charAt(i); - - if(v == "*" ){ + + if (v == "*") { str += ".*"; } - else if(v == "?"){ + else if (v == "?") { str += "."; } - else if(v == "~"){ - if(b.charAt(i+1) == "*"){ + else if (v == "~") { + if (b.charAt(i + 1) == "*") { str += "\\*"; i++; } - else if(b.charAt(i+1) == "?"){ + else if (b.charAt(i + 1) == "?") { str += "\\?"; i++; } - else{ + else { str += "~"; } } - else{ + else { str += v; } } - + let reg = new RegExp("^" + str + "$", "g"); return !!a.match(reg); }, - isCompareOperator: function(str){ //判断前一个或者两个字符是否是比较运算符 + isCompareOperator: function (str) { //判断前一个或者两个字符是否是比较运算符 str = str.toString(); let ope = ""; //存放比较运算符 let num = ""; //截取比较运算符之后的数字用于实际比较 - let strOne = str.substr(0,1); - let strTwo = str.substr(1,1); + let strOne = str.substr(0, 1); + let strTwo = str.substr(1, 1); let flag = false; let ret; - if(strOne == ">"){ - if(strTwo == "="){ - ope = str.substr(0,2); + if (strOne == ">") { + if (strTwo == "=") { + ope = str.substr(0, 2); num = str.substr(2); flag = true; } - else if(strTwo != "="){ - ope = str.substr(0,1); + else if (strTwo != "=") { + ope = str.substr(0, 1); num = str.substr(1); flag = true; } } - else if(strOne == "<"){ - if(strTwo == "=" || strTwo == ">"){ - ope = str.substr(0,2); + else if (strOne == "<") { + if (strTwo == "=" || strTwo == ">") { + ope = str.substr(0, 2); num = str.substr(2); flag = true; } - else if(strTwo != "=" && strTwo != ">"){ - ope = str.substr(0,1); + else if (strTwo != "=" && strTwo != ">") { + ope = str.substr(0, 1); num = str.substr(1); flag = true; } } - else if(strOne == "=" && strTwo != "="){ - ope = str.substr(0,1); + else if (strOne == "=" && strTwo != "=") { + ope = str.substr(0, 1); num = str.substr(1); flag = true; } @@ -592,70 +592,70 @@ const luckysheetformula = { return ret; }, - acompareb: function(a, b){ //a 与 b比较,b可为含比较符,通配符 + acompareb: function (a, b) { //a 与 b比较,b可为含比较符,通配符 let _this = this; let flag = false; - if(isRealNum(b)){ + if (isRealNum(b)) { flag = luckysheet_compareWith(a, "==", b); } - else if(typeof(b) == "string"){ //条件输入字符串,如:">233" - if(b.indexOf("*") != -1 || b.indexOf("?") != -1){ // 正则匹配:输入通配符:"黑*","白?",以及"白?黑*~*" + else if (typeof (b) == "string") { //条件输入字符串,如:">233" + if (b.indexOf("*") != -1 || b.indexOf("?") != -1) { // 正则匹配:输入通配符:"黑*","白?",以及"白?黑*~*" //通配符函数 return _this.isWildcard(a, b); } - else if(_this.isCompareOperator(b).flag){ //"黑糖" + else if (_this.isCompareOperator(b).flag) { //"黑糖" let ope = _this.isCompareOperator(b).ope; let num = _this.isCompareOperator(b).num; flag = luckysheet_compareWith(a, ope, num); } - else{ + else { flag = luckysheet_compareWith(a, "==", b); } } return flag; }, - compareParams: function(fp, sp, sym){ //比较两个字符串或者数字的大小,支持比较对象,暂不支持数组 + compareParams: function (fp, sp, sym) { //比较两个字符串或者数字的大小,支持比较对象,暂不支持数组 let flag = false; //判断a和b的数据类型 let classNameA = toString.call(fp), classNameB = toString.call(sp); - - if(sym == ">" && fp > sp){ + + if (sym == ">" && fp > sp) { flag = true; } - else if(sym == ">=" && fp >= sp){ + else if (sym == ">=" && fp >= sp) { flag = true; } - else if(sym == "<" && fp < sp){ + else if (sym == "<" && fp < sp) { flag = true; } - else if(sym == "<=" && fp <= sp){ + else if (sym == "<=" && fp <= sp) { flag = true; } - else if(sym == "=" && fp == sp){ + else if (sym == "=" && fp == sp) { flag = true; } - else if(sym == "<>" && fp != sp){ + else if (sym == "<>" && fp != sp) { flag = true; } //对象类型比较相等 - if(classNameA == '[object Object]' && classNameB == '[object Object]'){ + if (classNameA == '[object Object]' && classNameB == '[object Object]') { //获取a和b的属性长度 let propsA = Object.getOwnPropertyNames(fp), propsB = Object.getOwnPropertyNames(sp); - if(propsA.length != propsB.length){ + if (propsA.length != propsB.length) { return false; } - for(let i = 0; i < propsA.length; i++){ - let propName=propsA[i]; + for (let i = 0; i < propsA.length; i++) { + let propName = propsA[i]; //如果对应属性对应值不相等,则返回false - if(fp[propName] !== sp[propName]){ + if (fp[propName] !== sp[propName]) { return false; } } @@ -664,29 +664,29 @@ const luckysheetformula = { } //数组类型 - if(classNameA == '[object Array]' && classNameB == '[object Array]'){ - if(fp.toString() == sp.toString()){ + if (classNameA == '[object Array]' && classNameB == '[object Array]') { + if (fp.toString() == sp.toString()) { return true; } return false; } - + return flag; }, - parseDecimal: function(num){ + parseDecimal: function (num) { num = parseFloat(num); let d = parseInt(num, 10); - - if(d == 0){ + + if (d == 0) { return num; } num = num % d; return num; }, - getcellrange: function(txt, formulaIndex) { - if(txt==null || txt.length==0){ + getcellrange: function (txt, formulaIndex) { + if (txt == null || txt.length == 0) { return; } @@ -694,11 +694,11 @@ const luckysheetformula = { rangetxt = "", sheetIndex = null, sheetdata = null; - + let luckysheetfile = getluckysheetfile(); if (txt.indexOf("!") > -1) { - if(txt in this.cellTextToIndexList){ + if (txt in this.cellTextToIndexList) { return this.cellTextToIndexList[txt]; } @@ -707,8 +707,8 @@ const luckysheetformula = { rangetxt = val[1]; sheettxt = sheettxt.replace(/\\'/g, "'"); - if(sheettxt.substr(0,1)=="'" && sheettxt.substr(sheettxt.length-1,1)=="'"){ - sheettxt = sheettxt.substring(1,sheettxt.length-1); + if (sheettxt.substr(0, 1) == "'" && sheettxt.substr(sheettxt.length - 1, 1) == "'") { + sheettxt = sheettxt.substring(1, sheettxt.length - 1); } for (let i in luckysheetfile) { if (sheettxt == luckysheetfile[i].name) { @@ -717,22 +717,22 @@ const luckysheetformula = { break; } } - } + } else { let i = formulaIndex; - if(i==null){ + if (i == null) { i = Store.currentSheetIndex; } - if(txt+"_" + i in this.cellTextToIndexList){ - return this.cellTextToIndexList[txt+"_" + i]; - } + if (txt + "_" + i in this.cellTextToIndexList) { + return this.cellTextToIndexList[txt + "_" + i]; + } let index = getSheetIndex(i); sheettxt = luckysheetfile[index].name; sheetIndex = luckysheetfile[index].index; sheetdata = Store.flowdata; rangetxt = txt; } - + if (rangetxt.indexOf(":") == -1) { let row = parseInt(rangetxt.replace(/[^0-9]/g, "")) - 1; let col = ABCatNum(rangetxt.replace(/[^A-Za-z]/g, "")); @@ -743,16 +743,16 @@ const luckysheetformula = { "column": [col, col], "sheetIndex": sheetIndex }; - this.addToCellIndexList(txt,item); + this.addToCellIndexList(txt, item); return item; } else { return null; } - } + } else { rangetxt = rangetxt.split(":"); - let row = [],col = []; + let row = [], col = []; row[0] = parseInt(rangetxt[0].replace(/[^0-9]/g, "")) - 1; row[1] = parseInt(rangetxt[1].replace(/[^0-9]/g, "")) - 1; if (isNaN(row[0])) { @@ -781,18 +781,18 @@ const luckysheetformula = { "column": col, "sheetIndex": sheetIndex }; - this.addToCellIndexList(txt,item); + this.addToCellIndexList(txt, item); return item; } }, rangeHightlightHTML: '
', - createRangeHightlight: function() { + createRangeHightlight: function () { let _this = this; let $span = $("#luckysheet-rich-text-editor").find("span.luckysheet-formula-functionrange-cell"); $("#luckysheet-formula-functionrange .luckysheet-formula-functionrange-highlight").remove(); - $span.each(function() { + $span.each(function () { let rangeindex = $(this).attr("rangeindex"), range = $(this).text(); @@ -805,17 +805,17 @@ const luckysheetformula = { if (cellrange == null) { - } + } else if (cellrange.sheetIndex == Store.currentSheetIndex || (cellrange.sheetIndex == -1 && _this.rangetosheet == Store.currentSheetIndex)) { $("#" + rangeid).data("range", cellrange) - .find(".luckysheet-copy") - .css({ "background": luckyColor[rangeindex] }) - .end() - .find(".luckysheet-highlight") - .css({ "background": luckyColor[rangeindex] }) - .end() - .find(".luckysheet-selection-copy-hc") - .css({ "background": luckyColor[rangeindex] }); + .find(".luckysheet-copy") + .css({ "background": luckyColor[rangeindex] }) + .end() + .find(".luckysheet-highlight") + .css({ "background": luckyColor[rangeindex] }) + .end() + .find(".luckysheet-selection-copy-hc") + .css({ "background": luckyColor[rangeindex] }); seletedHighlistByindex(rangeid, cellrange.row[0], cellrange.row[1], cellrange.column[0], cellrange.column[1]); } @@ -825,7 +825,7 @@ const luckysheetformula = { }, searchHTML: '
', helpHTML: '
SUM ( A2:A100, 101 )
${helpExample}
SUM ( A2:A100, 101 )
${helpAbstract}
${helpAbstract}
${param}
', - getrangeseleciton: function() { + getrangeseleciton: function () { let currSelection = window.getSelection(); let anchor = $(currSelection.anchorNode); let anchorOffset = currSelection.anchorOffset; @@ -839,12 +839,12 @@ const luckysheetformula = { txt = $.trim(ahr.text()); lasttxt = txt.substr(txt.length - 1, 1); return ahr; - } + } else { lasttxt = txt.substr(anchorOffset - 1, 1); return anchor.parent(); } - } + } else if (anchor.is("#luckysheet-rich-text-editor") || anchor.is("#luckysheet-functionbox-cell")) { let txt = $.trim(anchor.find("span").last().text()); @@ -852,11 +852,11 @@ const luckysheetformula = { let ahr = anchor.find("span"); txt = $.trim(ahr.eq(ahr.length - 2).text()); return ahr; - } + } else { return anchor.find("span").last(); } - } + } else if (anchor.parent().is("#luckysheet-rich-text-editor") || anchor.parent().is("#luckysheet-functionbox-cell") || anchorOffset == 0) { if (anchorOffset == 0) { anchor = anchor.parent(); @@ -871,7 +871,7 @@ const luckysheetformula = { return null; }, - searchFunctionPosition: function($menu, $editor, x, y, isparam) { + searchFunctionPosition: function ($menu, $editor, x, y, isparam) { let winH = $(window).height(), winW = $(window).width(); let menuW = $menu.outerWidth(), @@ -884,7 +884,7 @@ const luckysheetformula = { let left = x; if (x + menuW > winW) { left = x - menuW + $editor.outerWidth(); - } + } else { left = x; } @@ -892,7 +892,7 @@ const luckysheetformula = { let top = y; if (y + menuH > winH) { top = y - menuH; - } + } else { top = y + $editor.outerHeight(); if (!isparam) { @@ -913,14 +913,14 @@ const luckysheetformula = { }).show(); }, searchFunctionCell: null, - searchFunction: function($editer) { + searchFunction: function ($editer) { let _this = this; let functionlist = Store.functionlist; let $cell = _this.getrangeseleciton(); _this.searchFunctionCell = $cell; - + if ($cell == null || $editer == null) { return; @@ -928,16 +928,16 @@ const luckysheetformula = { let inputContent = $editer.text(); let searchtxt = $cell.text().toUpperCase(); let reg = /^[a-zA-Z]|[a-zA-Z_]+$/; - - if (!reg.test(searchtxt) || inputContent.substr(0, 1)!="=") { + + if (!reg.test(searchtxt) || inputContent.substr(0, 1) != "=") { return; } let result = { - "f": [], - "s": [], - "t": [] - }, + "f": [], + "s": [], + "t": [] + }, result_i = 0; for (let i = 0; i < functionlist.length; i++) { @@ -947,11 +947,11 @@ const luckysheetformula = { if (n == searchtxt) { result.f.unshift(item); result_i++; - } + } else if (n.substr(0, searchtxt.length) == searchtxt) { result.s.unshift(item); result_i++; - } + } else if (n.indexOf(searchtxt) > -1) { result.t.unshift(item); result_i++; @@ -975,7 +975,7 @@ const luckysheetformula = { offset = $c.offset(); _this.searchFunctionPosition($("#luckysheet-formula-search-c"), $c, offset.left, offset.top); }, - searchFunctionEnter: function($obj) { + searchFunctionEnter: function ($obj) { let _this = this; let functxt = $obj.data("func"); @@ -984,17 +984,17 @@ const luckysheetformula = { $("#luckysheet-formula-search-c").hide(); _this.helpFunctionExe(_this.searchFunctionCell.closest("div"), _this.searchFunctionCell.next()); }, - searchFunctionHTML: function(list) { + searchFunctionHTML: function (list) { let _this = this; if ($("#luckysheet-formula-search-c").length == 0) { $("body").append(_this.searchHTML); - $("#luckysheet-formula-search-c").on("mouseover", ".luckysheet-formula-search-item", function() { + $("#luckysheet-formula-search-c").on("mouseover", ".luckysheet-formula-search-item", function () { $("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item").removeClass("luckysheet-formula-search-item-active"); $(this).addClass("luckysheet-formula-search-item-active"); - }).on("mouseout", ".luckysheet-formula-search-item", function() { + }).on("mouseout", ".luckysheet-formula-search-item", function () { - }).on("click", ".luckysheet-formula-search-item", function() { + }).on("click", ".luckysheet-formula-search-item", function () { if (_this.searchFunctionCell == null) { return; } @@ -1004,7 +1004,7 @@ const luckysheetformula = { let itemHTML = '
${n}
${a}
'; let retHTML = ""; - + for (let i = 0; i < list.length; i++) { let item = list[i]; @@ -1014,7 +1014,7 @@ const luckysheetformula = { "n": item.n, "a": item.a }); - } + } else { retHTML += replaceHtml(itemHTML, { "class": "", @@ -1027,7 +1027,7 @@ const luckysheetformula = { return retHTML; }, functionlistPosition: {}, - helpFunction: function($editer, funcname, paramIndex) { + helpFunction: function ($editer, funcname, paramIndex) { let _this = this; let functionlist = Store.functionlist; @@ -1041,11 +1041,11 @@ const luckysheetformula = { $("#luckysheet-formula-help-c .luckysheet-arguments-help-function-name").html($func.n); $("#luckysheet-formula-help-c .luckysheet-arguments-help-parameter-content").html($func.d); - + let helpformula = '${name} ( ${param} )'; let helpformulaItem = '${param}'; let helpformulaArg = '
${param}
${content}
'; - + //"n": "AVERAGE", //"t": "1", //"d": "返回数据集的算术平均值,对文本忽略不计。", @@ -1064,11 +1064,11 @@ const luckysheetformula = { if (paramitem.repeat == "y") { name += ", ..."; - nameli += '...-'+locale_formulaMore.allowRepeatText+''; + nameli += '...-' + locale_formulaMore.allowRepeatText + ''; } if (paramitem.require == "o") { name = "[" + name + "]"; - nameli += '-['+locale_formulaMore.allowOptionText+']'; + nameli += '-[' + locale_formulaMore.allowOptionText + ']'; } fht += '' + name + ', '; @@ -1081,15 +1081,15 @@ const luckysheetformula = { fht = fht.substr(0, fht.length - 2); ahf = ahf.substr(0, ahf.length - 2); - + $("#luckysheet-formula-help-c .luckysheet-formula-help-title .luckysheet-arguments-parameter-holder").html(fht); //介绍 $("#luckysheet-formula-help-c .luckysheet-arguments-help-formula .luckysheet-arguments-parameter-holder").html(ahf); //示例 $("#luckysheet-formula-help-c .luckysheet-formula-help-content-param").html(fhcp); //参数 - - if(paramIndex == null){ + + if (paramIndex == null) { $("#luckysheet-formula-help-c .luckysheet-formula-help-title-formula .luckysheet-arguments-help-function-name").css("font-weight", "bold"); } - else{ + else { $("#luckysheet-formula-help-c .luckysheet-formula-help-title-formula .luckysheet-arguments-help-function-name").css("font-weight", "normal"); let index = paramIndex >= $func.p.length ? $func.p.length - 1 : paramIndex; $("#luckysheet-formula-help-c .luckysheet-formula-help-title .luckysheet-arguments-parameter-holder .luckysheet-arguments-help-parameter").removeClass("luckysheet-arguments-help-parameter-active"); @@ -1104,24 +1104,24 @@ const luckysheetformula = { offset = $c.offset(); _this.searchFunctionPosition($("#luckysheet-formula-help-c"), $c, offset.left, offset.top, true); }, - helpFunctionExe: function($editer, currSelection) { + helpFunctionExe: function ($editer, currSelection) { let _this = this; let functionlist = Store.functionlist; let _locale = locale(); let locale_formulaMore = _locale.formulaMore; if ($("#luckysheet-formula-help-c").length == 0) { - $("body").after(replaceHtml(_this.helpHTML,{ - helpClose:locale_formulaMore.helpClose, - helpCollapse:locale_formulaMore.helpCollapse, - helpExample:locale_formulaMore.helpExample, - helpAbstract:locale_formulaMore.helpAbstract, + $("body").after(replaceHtml(_this.helpHTML, { + helpClose: locale_formulaMore.helpClose, + helpCollapse: locale_formulaMore.helpCollapse, + helpExample: locale_formulaMore.helpExample, + helpAbstract: locale_formulaMore.helpAbstract, })); - $("#luckysheet-formula-help-c .luckysheet-formula-help-close").click(function() { + $("#luckysheet-formula-help-c .luckysheet-formula-help-close").click(function () { $("#luckysheet-formula-help-c").hide(); }); - $("#luckysheet-formula-help-c .luckysheet-formula-help-collapse").click(function() { + $("#luckysheet-formula-help-c .luckysheet-formula-help-collapse").click(function () { let $content = $("#luckysheet-formula-help-c .luckysheet-formula-help-content"); - $content.slideToggle(100, function() { + $content.slideToggle(100, function () { let $c = _this.rangeResizeTo.parent(), offset = $c.offset(); _this.searchFunctionPosition($("#luckysheet-formula-help-c"), $c, offset.left, offset.top, true); @@ -1129,7 +1129,7 @@ const luckysheetformula = { if ($content.is(":hidden")) { $(this).html(''); - } + } else { $(this).html(''); } @@ -1140,12 +1140,12 @@ const luckysheetformula = { } } - if(!currSelection){ + if (!currSelection) { return; } let $prev = currSelection, - funcLen = $editer.length, + funcLen = $editer.length, $span = $editer.find("span"), currentIndex = currSelection.index(), i = currentIndex; @@ -1154,58 +1154,58 @@ const luckysheetformula = { return; } - let funcName = null, paramindex= null; + let funcName = null, paramindex = null; - if($span.eq(i).is(".luckysheet-formula-text-func")){ + if ($span.eq(i).is(".luckysheet-formula-text-func")) { funcName = $span.eq(i).text(); } - else{ + else { let $cur = null, exceptIndex = [-1, -1]; while (--i > 0) { $cur = $span.eq(i); - - if($cur.is(".luckysheet-formula-text-func") || $.trim($cur.text()).toUpperCase() in _this.functionlistPosition){ + + if ($cur.is(".luckysheet-formula-text-func") || $.trim($cur.text()).toUpperCase() in _this.functionlistPosition) { funcName = $cur.text(); paramindex = null; let endstate = true; - - for(let a = i; a <= currentIndex; a++){ - if(!paramindex){ + + for (let a = i; a <= currentIndex; a++) { + if (!paramindex) { paramindex = 0; } - if(a >= exceptIndex[0] && a <= exceptIndex[1]){ + if (a >= exceptIndex[0] && a <= exceptIndex[1]) { continue; } $cur = $span.eq(a); - if($cur.is(".luckysheet-formula-text-rpar")){ - exceptIndex = [i , a]; + if ($cur.is(".luckysheet-formula-text-rpar")) { + exceptIndex = [i, a]; funcName = null; endstate = false; break; } - if($cur.is(".luckysheet-formula-text-comma")){ + if ($cur.is(".luckysheet-formula-text-comma")) { paramindex++; } } - if(endstate){ + if (endstate) { break; } } } } - if(funcName == null){ + if (funcName == null) { return; } - + _this.helpFunction($editer, funcName, paramindex); }, - rangeHightlightselected: function($editer, kcode) { + rangeHightlightselected: function ($editer, kcode) { let _this = this; let currSelection = _this.getrangeseleciton(); @@ -1213,42 +1213,42 @@ const luckysheetformula = { $("#luckysheet-formula-functionrange .luckysheet-formula-functionrange-highlight .luckysheet-selection-copy-hc").css("opacity", "0.03"); $("#luckysheet-formula-search-c, #luckysheet-formula-help-c").hide(); _this.helpFunctionExe($editer, currSelection); - + // console.log(currSelection, $(currSelection).closest(".luckysheet-formula-functionrange-cell").length); if ($(currSelection).closest(".luckysheet-formula-functionrange-cell").length == 0) { _this.searchFunction($editer); return; } - + let $anchorOffset = $(currSelection).closest(".luckysheet-formula-functionrange-cell"); let rangeindex = $anchorOffset.attr("rangeindex"); let rangeid = "luckysheet-formula-functionrange-highlight-" + rangeindex; - + $("#" + rangeid).find(".luckysheet-selection-copy-hc").css({ "opacity": "0.13" }); }, - updatecell: function(r, c, value, isRefresh=true) { + updatecell: function (r, c, value, isRefresh = true) { let _this = this; let $input = $("#luckysheet-rich-text-editor"); let inputText = $input.text(), inputHtml = $input.html(); - + if (_this.rangetosheet != null && _this.rangetosheet != Store.currentSheetIndex) { sheetmanage.changeSheetExec(_this.rangetosheet); } - if(!checkProtectionLocked(r, c, Store.currentSheetIndex)){ + if (!checkProtectionLocked(r, c, Store.currentSheetIndex)) { return; } //数据验证 输入数据无效时禁止输入 - if(dataVerificationCtrl.dataVerification != null){ + if (dataVerificationCtrl.dataVerification != null) { let dvItem = dataVerificationCtrl.dataVerification[r + '_' + c]; - - if(dvItem != null && dvItem.prohibitInput && !dataVerificationCtrl.validateCellData(inputText, dvItem)){ + + if (dvItem != null && dvItem.prohibitInput && !dataVerificationCtrl.validateCellData(inputText, dvItem)) { let failureText = dataVerificationCtrl.getFailureText(dvItem); tooltip.info(failureText, ''); _this.cancelNormalSelected(); @@ -1262,14 +1262,14 @@ const luckysheetformula = { const oldValue = JSON.stringify(curv); let isPrevInline = isInlineStringCell(curv); - let isCurInline = (inputText.slice(0, 1) != "=" && inputHtml.substr(0,5) == " cellWidth){ // let strArr = [];//文本截断数组 // strArr = getCellTextSplitArr(strValue, strArr, cellWidth, offlinecanvas); - + // let computeRowlen = oneLineTextHeight * strArr.length + 4; // //比较计算高度和当前高度取最大高度 // if(computeRowlen > currentRowLen){ // currentRowLen = computeRowlen; // } // } - - if(currentRowLen > defaultrowlen){ + + if (currentRowLen > defaultrowlen) { cfg["rowlen"][r] = currentRowLen; RowlChange = true; } @@ -1600,7 +1600,7 @@ const luckysheetformula = { //动态数组 let dynamicArray = null; - if(!!dynamicArrayItem){ + if (!!dynamicArrayItem) { // let file = Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)]; dynamicArray = $.extend(true, [], this.insertUpdateDynamicArray(dynamicArrayItem)); // dynamicArray.push(dynamicArrayItem); @@ -1610,8 +1610,8 @@ const luckysheetformula = { let allParam = { "dynamicArray": dynamicArray } - - if(RowlChange){ + + if (RowlChange) { allParam = { "cfg": cfg, "dynamicArray": dynamicArray, @@ -1624,78 +1624,78 @@ const luckysheetformula = { method.createHookFunction("cellUpdated", r, c, JSON.parse(oldValue), Store.flowdata[r][c], isRefresh); }, 0); - if(isRefresh){ + if (isRefresh) { jfrefreshgrid(d, [{ "row": [r, r], "column": [c, c] }], allParam, isRunExecFunction); // Store.luckysheetCellUpdate.length = 0; //clear array _this.execFunctionGlobalData = null; //销毁 } - else{ + else { return { - data:d, - allParam:allParam + data: d, + allParam: allParam }; } }, - cancelNormalSelected: function() { + cancelNormalSelected: function () { let _this = this; _this.canceFunctionrangeSelected(); - + $("#luckysheet-formula-functionrange .luckysheet-formula-functionrange-highlight").remove(); $("#luckysheet-input-box").removeAttr("style"); $("#luckysheet-input-box-index").hide(); $("#luckysheet-wa-functionbox-cancel, #luckysheet-wa-functionbox-confirm").removeClass("luckysheet-wa-calculate-active"); - + _this.rangestart = false; _this.rangedrag_column_start = false; _this.rangedrag_row_start = false; }, - canceFunctionrangeSelected: function() { + canceFunctionrangeSelected: function () { $("#luckysheet-formula-functionrange-select").hide(); $("#luckysheet-row-count-show, #luckysheet-column-count-show").hide(); // $("#luckysheet-cols-h-selected, #luckysheet-rows-h-selected").hide(); $("#luckysheet-formula-search-c, #luckysheet-formula-help-c").hide(); }, - iscellformat: function(txt) { + iscellformat: function (txt) { let re_abc = /[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ][123456789]/; }, - iscelldata: function(txt) { //判断是否为单元格格式 + iscelldata: function (txt) { //判断是否为单元格格式 let val = txt.split("!"), rangetxt; if (val.length > 1) { rangetxt = val[1]; - } + } else { rangetxt = val[0]; } let reg_cell = /^(([a-zA-Z]+)|([$][a-zA-Z]+))(([0-9]+)|([$][0-9]+))$/g; //增加正则判断单元格为字母+数字的格式:如 A1:B3 let reg_cellRange = /^(((([a-zA-Z]+)|([$][a-zA-Z]+))(([0-9]+)|([$][0-9]+)))|((([a-zA-Z]+)|([$][a-zA-Z]+))))$/g; //增加正则判断单元格为字母+数字或字母的格式:如 A1:B3,A:A - + if (rangetxt.indexOf(":") == -1) { let row = parseInt(rangetxt.replace(/[^0-9]/g, "")) - 1; let col = ABCatNum(rangetxt.replace(/[^A-Za-z]/g, "")); - + if (!isNaN(row) && !isNaN(col) && rangetxt.toString().match(reg_cell)) { return true; - } + } else if (!isNaN(row)) { return false; - } + } else if (!isNaN(col)) { return false; - } + } else { return false; } - } + } else { reg_cellRange = /^(((([a-zA-Z]+)|([$][a-zA-Z]+))(([0-9]+)|([$][0-9]+)))|((([a-zA-Z]+)|([$][a-zA-Z]+)))|((([0-9]+)|([$][0-9]+s))))$/g; rangetxt = rangetxt.split(":"); - let row = [],col = []; + let row = [], col = []; row[0] = parseInt(rangetxt[0].replace(/[^0-9]/g, "")) - 1; row[1] = parseInt(rangetxt[1].replace(/[^0-9]/g, "")) - 1; if (row[0] > row[1]) { @@ -1708,17 +1708,17 @@ const luckysheetformula = { return false; } - if(rangetxt[0].toString().match(reg_cellRange) && rangetxt[1].toString().match(reg_cellRange)){ + if (rangetxt[0].toString().match(reg_cellRange) && rangetxt[1].toString().match(reg_cellRange)) { return true; } - else{ + else { return false; } } }, operator: '==|!=|<>|<=|>=|=|+|-|>|<|/|*|%|&|^', operatorjson: null, - functionCopy: function(txt, mode, step) { + functionCopy: function (txt, mode, step) { let _this = this; if (_this.operatorjson == null) { @@ -1749,7 +1749,7 @@ const luckysheetformula = { str = "", function_str = "", ispassby = true; - + let matchConfig = { "bracket": 0, "comma": 0, @@ -1765,13 +1765,13 @@ const luckysheetformula = { if (str.length > 0) { function_str += str + "("; - } + } else { function_str += "("; } str = ""; - } + } else if (s == ")" && matchConfig.dquote == 0) { matchConfig.bracket -= 1; function_str += _this.functionCopy(str, mode, step) + ")"; @@ -1782,25 +1782,25 @@ const luckysheetformula = { function_str += str + '"'; matchConfig.dquote -= 1; str = ""; - } + } else { matchConfig.dquote += 1; str += '"'; } - } + } else if (s == ',' && matchConfig.dquote == 0) { function_str += _this.functionCopy(str, mode, step) + ','; str = ""; - } + } else if (s == '&' && matchConfig.dquote == 0) { if (str.length > 0) { function_str += _this.functionCopy(str, mode, step) + "&"; str = ""; - } + } else { function_str += "&"; } - } + } else if (s in _this.operatorjson && matchConfig.dquote == 0) { let s_next = ""; @@ -1808,40 +1808,40 @@ const luckysheetformula = { s_next = funcstack[i + 1]; } - let p = i - 1, + let p = i - 1, s_pre = null; - if(p >= 0){ + if (p >= 0) { do { s_pre = funcstack[p--]; } - while (p>=0 && s_pre ==" ") + while (p >= 0 && s_pre == " ") } if ((s + s_next) in _this.operatorjson) { if (str.length > 0) { function_str += _this.functionCopy(str, mode, step) + s + s_next; str = ""; - } + } else { function_str += s + s_next; } i++; } - else if(!(/[^0-9]/.test(s_next)) && s=="-" && (s_pre=="(" || s_pre == null || s_pre == "," || s_pre == " " || s_pre in _this.operatorjson ) ){ + else if (!(/[^0-9]/.test(s_next)) && s == "-" && (s_pre == "(" || s_pre == null || s_pre == "," || s_pre == " " || s_pre in _this.operatorjson)) { str += s; } else { if (str.length > 0) { function_str += _this.functionCopy(str, mode, step) + s; str = ""; - } + } else { function_str += s; } } - } + } else { str += s; } @@ -1850,28 +1850,28 @@ const luckysheetformula = { if (_this.iscelldata($.trim(str))) { if (mode == "down") { function_str += _this.downparam($.trim(str), step); - } + } else if (mode == "up") { function_str += _this.upparam($.trim(str), step); - } + } else if (mode == "left") { function_str += _this.leftparam($.trim(str), step); - } + } else if (mode == "right") { function_str += _this.rightparam($.trim(str), step); } - } + } else { function_str += $.trim(str); } } - + i++; } return function_str; }, - isfreezonFuc: function(txt) { + isfreezonFuc: function (txt) { let row = txt.replace(/[^0-9]/g, ""); let col = txt.replace(/[^A-Za-z]/g, ""); let row$ = txt.substr(txt.indexOf(row) - 1, 1); @@ -1887,7 +1887,7 @@ const luckysheetformula = { return ret; }, - setfreezonFuceExe: function(rangetxt) { + setfreezonFuceExe: function (rangetxt) { let row = parseInt(rangetxt.replace(/[^0-9]/g, "")); let col = ABCatNum(rangetxt.replace(/[^A-Za-z]/g, "")); let $row = "$", @@ -1895,18 +1895,18 @@ const luckysheetformula = { if (!isNaN(row) && !isNaN(col)) { return $col + chatatABC(col) + $row + (row); - } + } else if (!isNaN(row)) { return $row + (row); - } + } else if (!isNaN(col)) { return $col + chatatABC(col); - } + } else { return rangetxt; } }, - setfreezonFuc: function(event) { + setfreezonFuc: function (event) { let _this = this; let obj = _this.getrangeseleciton(); @@ -1918,11 +1918,11 @@ const luckysheetformula = { pos = window.getSelection().anchorOffset; let val = txt.split("!"), rangetxt, prefix = ""; - + if (val.length > 1) { rangetxt = val[1]; prefix = val[0] + "!"; - } + } else { rangetxt = val[0]; } @@ -1930,19 +1930,19 @@ const luckysheetformula = { let newtxt = "", newpos = ""; let rangetxtIndex = rangetxt.indexOf(":"); - + if (rangetxtIndex == -1) { newtxt = prefix + _this.setfreezonFuceExe(rangetxt); newpos = newtxt.length; - } + } else { rangetxt = rangetxt.split(":"); - + if (pos > rangetxtIndex) { let ret = prefix + rangetxt[0] + ":" + _this.setfreezonFuceExe(rangetxt[1]); newtxt = ret; newpos = ret.length; - } + } else { let firsttxt = prefix + _this.setfreezonFuceExe(rangetxt[0]); let ret = firsttxt + ":" + rangetxt[1]; @@ -1954,16 +1954,16 @@ const luckysheetformula = { obj.text(prefix + newtxt); _this.setCaretPosition(obj.get(0), 0, newpos); }, - updateparam: function(orient, txt, step) { + updateparam: function (orient, txt, step) { let _this = this; let val = txt.split("!"), rangetxt, prefix = ""; - + if (val.length > 1) { rangetxt = val[1]; prefix = val[0] + "!"; - } + } else { rangetxt = val[0]; } @@ -1974,37 +1974,37 @@ const luckysheetformula = { let freezonFuc = _this.isfreezonFuc(rangetxt); let $row = freezonFuc[0] ? "$" : "", $col = freezonFuc[1] ? "$" : ""; - + if (orient == "u" && !freezonFuc[0]) { row -= step; - } + } else if (orient == "r" && !freezonFuc[1]) { col += step; - } + } else if (orient == "l" && !freezonFuc[1]) { col -= step; - } + } else if (orient == "d" && !freezonFuc[0]) { row += step; } - if(row[0] < 0 || col[0] < 0){ + if (row[0] < 0 || col[0] < 0) { return _this.error.r; } - + if (!isNaN(row) && !isNaN(col)) { return prefix + $col + chatatABC(col) + $row + (row); - } + } else if (!isNaN(row)) { return prefix + $row + (row); - } + } else if (!isNaN(col)) { return prefix + $col + chatatABC(col); - } + } else { return txt; } - } + } else { rangetxt = rangetxt.split(":"); let row = [], @@ -2015,7 +2015,7 @@ const luckysheetformula = { if (row[0] > row[1]) { return txt; } - + col[0] = ABCatNum(rangetxt[0].replace(/[^A-Za-z]/g, "")); col[1] = ABCatNum(rangetxt[1].replace(/[^A-Za-z]/g, "")); if (col[0] > col[1]) { @@ -2028,7 +2028,7 @@ const luckysheetformula = { $col0 = freezonFuc0[1] ? "$" : ""; let $row1 = freezonFuc1[0] ? "$" : "", $col1 = freezonFuc1[1] ? "$" : ""; - + if (orient == "u") { if (!freezonFuc0[0]) { row[0] -= step; @@ -2037,7 +2037,7 @@ const luckysheetformula = { if (!freezonFuc1[0]) { row[1] -= step; } - } + } else if (orient == "r") { if (!freezonFuc0[1]) { col[0] += step; @@ -2046,7 +2046,7 @@ const luckysheetformula = { if (!freezonFuc1[1]) { col[1] += step; } - } + } else if (orient == "l") { if (!freezonFuc0[1]) { col[0] -= step; @@ -2055,8 +2055,8 @@ const luckysheetformula = { if (!freezonFuc1[1]) { col[1] -= step; } - } - else if(orient=="d") { + } + else if (orient == "d") { if (!freezonFuc0[0]) { row[0] += step; } @@ -2066,34 +2066,34 @@ const luckysheetformula = { } } - if(row[0] < 0 || col[0] < 0){ + if (row[0] < 0 || col[0] < 0) { return _this.error.r; } if (isNaN(col[0]) && isNaN(col[1])) { return prefix + $row0 + (row[0]) + ":" + $row1 + (row[1]); - } + } else if (isNaN(row[0]) && isNaN(row[1])) { return prefix + $col0 + chatatABC(col[0]) + ":" + $col1 + chatatABC(col[1]); - } + } else { return prefix + $col0 + chatatABC(col[0]) + $row0 + (row[0]) + ":" + $col1 + chatatABC(col[1]) + $row1 + (row[1]); } } }, - downparam: function(txt, step) { + downparam: function (txt, step) { return this.updateparam("d", txt, step); }, - upparam: function(txt, step) { + upparam: function (txt, step) { return this.updateparam("u", txt, step); }, - leftparam: function(txt, step) { + leftparam: function (txt, step) { return this.updateparam("l", txt, step); }, - rightparam: function(txt, step) { + rightparam: function (txt, step) { return this.updateparam("r", txt, step); }, - functionStrChange: function(txt, type, rc, orient, stindex, step) { + functionStrChange: function (txt, type, rc, orient, stindex, step) { let _this = this; if (_this.operatorjson == null) { @@ -2116,7 +2116,7 @@ const luckysheetformula = { str = "", function_str = "", ispassby = true; - + let matchConfig = { "bracket": 0, //括号 "comma": 0, //逗号 @@ -2132,13 +2132,13 @@ const luckysheetformula = { if (str.length > 0) { function_str += str + "("; - } + } else { function_str += "("; } str = ""; - } + } else if (s == ")" && matchConfig.dquote == 0) { matchConfig.bracket -= 1; function_str += _this.functionStrChange(str, type, rc, orient, stindex, step) + ")"; @@ -2149,25 +2149,25 @@ const luckysheetformula = { function_str += str + '"'; matchConfig.dquote -= 1; str = ""; - } + } else { matchConfig.dquote += 1; str += '"'; } - } + } else if (s == ',' && matchConfig.dquote == 0) { function_str += _this.functionStrChange(str, type, rc, orient, stindex, step) + ','; str = ""; - } + } else if (s == '&' && matchConfig.dquote == 0) { if (str.length > 0) { function_str += _this.functionStrChange(str, type, rc, orient, stindex, step) + "&"; str = ""; - } + } else { function_str += "&"; } - } + } else if (s in _this.operatorjson && matchConfig.dquote == 0) { let s_next = ""; @@ -2175,40 +2175,40 @@ const luckysheetformula = { s_next = funcstack[i + 1]; } - let p = i - 1, + let p = i - 1, s_pre = null;; - - if(p >= 0){ + + if (p >= 0) { do { s_pre = funcstack[p--]; } - while (p>=0 && s_pre ==" ") + while (p >= 0 && s_pre == " ") } if ((s + s_next) in _this.operatorjson) { if (str.length > 0) { function_str += _this.functionStrChange(str, type, rc, orient, stindex, step) + s + s_next; str = ""; - } + } else { function_str += s + s_next; } i++; } - else if(!(/[^0-9]/.test(s_next)) && s=="-" && (s_pre=="(" || s_pre == null || s_pre == "," || s_pre == " " || s_pre in _this.operatorjson ) ){ + else if (!(/[^0-9]/.test(s_next)) && s == "-" && (s_pre == "(" || s_pre == null || s_pre == "," || s_pre == " " || s_pre in _this.operatorjson)) { str += s; } else { if (str.length > 0) { function_str += _this.functionStrChange(str, type, rc, orient, stindex, step) + s; str = ""; - } + } else { function_str += s; } } - } + } else { str += s; } @@ -2216,27 +2216,27 @@ const luckysheetformula = { if (i == funcstack.length - 1) { if (_this.iscelldata($.trim(str))) { function_str += _this.functionStrChange_range($.trim(str), type, rc, orient, stindex, step); - } + } else { function_str += $.trim(str); } } - + i++; } return function_str; }, - functionStrChange_range: function(txt, type, rc, orient, stindex, step){ + functionStrChange_range: function (txt, type, rc, orient, stindex, step) { let _this = this; let val = txt.split("!"), rangetxt, prefix = ""; - + if (val.length > 1) { rangetxt = val[1]; prefix = val[0] + "!"; - } + } else { rangetxt = val[0]; } @@ -2247,21 +2247,21 @@ const luckysheetformula = { if (rangetxt.indexOf(":") == -1) { r1 = r2 = parseInt(rangetxt.replace(/[^0-9]/g, "")) - 1; c1 = c2 = ABCatNum(rangetxt.replace(/[^A-Za-z]/g, "")); - + let freezonFuc = _this.isfreezonFuc(rangetxt); - + $row0 = $row1 = freezonFuc[0] ? "$" : "", - $col0 = $col1 = freezonFuc[1] ? "$" : ""; - } + $col0 = $col1 = freezonFuc[1] ? "$" : ""; + } else { rangetxt = rangetxt.split(":"); - + r1 = parseInt(rangetxt[0].replace(/[^0-9]/g, "")) - 1; r2 = parseInt(rangetxt[1].replace(/[^0-9]/g, "")) - 1; if (r1 > r2) { return txt; } - + c1 = ABCatNum(rangetxt[0].replace(/[^A-Za-z]/g, "")); c2 = ABCatNum(rangetxt[1].replace(/[^A-Za-z]/g, "")); if (c1 > c2) { @@ -2277,158 +2277,158 @@ const luckysheetformula = { $col1 = freezonFuc1[1] ? "$" : ""; } - if(type == "del"){ - if(rc == "row"){ - if(r1 >= stindex && r2 <= stindex + step - 1){ + if (type == "del") { + if (rc == "row") { + if (r1 >= stindex && r2 <= stindex + step - 1) { return _this.error.r; } - - if(r1 > stindex + step - 1){ + + if (r1 > stindex + step - 1) { r1 -= step; } - else if(r1 >= stindex){ + else if (r1 >= stindex) { r1 = stindex; } - if(r2 > stindex + step - 1){ + if (r2 > stindex + step - 1) { r2 -= step; } - else if(r2 >= stindex){ + else if (r2 >= stindex) { r2 = stindex - 1; } - if(r1 < 0){ + if (r1 < 0) { r1 = 0; } - if(r2 < r1){ + if (r2 < r1) { r2 = r1; } } - else if(rc == "col"){ - if(c1 >= stindex && c2 <= stindex + step - 1){ + else if (rc == "col") { + if (c1 >= stindex && c2 <= stindex + step - 1) { return _this.error.r; } - - if(c1 > stindex + step - 1){ + + if (c1 > stindex + step - 1) { c1 -= step; } - else if(c1 >= stindex){ + else if (c1 >= stindex) { c1 = stindex; } - if(c2 > stindex + step - 1){ + if (c2 > stindex + step - 1) { c2 -= step; } - else if(c2 >= stindex){ + else if (c2 >= stindex) { c2 = stindex - 1; } - if(c1 < 0){ + if (c1 < 0) { c1 = 0; } - if(c2 < c1){ + if (c2 < c1) { c2 = c1; } } - if(r1 == r2 && c1 == c2){ + if (r1 == r2 && c1 == c2) { if (!isNaN(r1) && !isNaN(c1)) { return prefix + $col0 + chatatABC(c1) + $row0 + (r1 + 1); - } + } else if (!isNaN(r1)) { return prefix + $row0 + (r1 + 1); - } + } else if (!isNaN(c1)) { return prefix + $col0 + chatatABC(c1); - } + } else { return txt; } } - else{ + else { if (isNaN(c1) && isNaN(c2)) { return prefix + $row0 + (r1 + 1) + ":" + $row1 + (r2 + 1); - } + } else if (isNaN(r1) && isNaN(r2)) { return prefix + $col0 + chatatABC(c1) + ":" + $col1 + chatatABC(c2); - } + } else { return prefix + $col0 + chatatABC(c1) + $row0 + (r1 + 1) + ":" + $col1 + chatatABC(c2) + $row1 + (r2 + 1); } } } - else if(type == "add"){ - if(rc == "row"){ - if(orient == "lefttop"){ - if(r1 >= stindex){ + else if (type == "add") { + if (rc == "row") { + if (orient == "lefttop") { + if (r1 >= stindex) { r1 += step; } - - if(r2 >= stindex){ + + if (r2 >= stindex) { r2 += step; } } - else if(orient == "rightbottom"){ - if(r1 > stindex){ + else if (orient == "rightbottom") { + if (r1 > stindex) { r1 += step; } - if(r2 > stindex){ + if (r2 > stindex) { r2 += step; } } } - else if(rc == "col"){ - if(orient == "lefttop"){ - if(c1 >= stindex){ + else if (rc == "col") { + if (orient == "lefttop") { + if (c1 >= stindex) { c1 += step; } - - if(c2 >= stindex){ + + if (c2 >= stindex) { c2 += step; } } - else if(orient == "rightbottom"){ - if(c1 > stindex){ + else if (orient == "rightbottom") { + if (c1 > stindex) { c1 += step; } - if(c2 > stindex){ + if (c2 > stindex) { c2 += step; } } } - if(r1 == r2 && c1 == c2){ + if (r1 == r2 && c1 == c2) { if (!isNaN(r1) && !isNaN(c1)) { return prefix + $col0 + chatatABC(c1) + $row0 + (r1 + 1); - } + } else if (!isNaN(r1)) { return prefix + $row0 + (r1 + 1); - } + } else if (!isNaN(c1)) { return prefix + $col0 + chatatABC(c1); - } + } else { return txt; } } - else{ + else { if (isNaN(c1) && isNaN(c2)) { return prefix + $row0 + (r1 + 1) + ":" + $row1 + (r2 + 1); - } + } else if (isNaN(r1) && isNaN(r2)) { return prefix + $col0 + chatatABC(c1) + ":" + $col1 + chatatABC(c2); - } + } else { return prefix + $col0 + chatatABC(c1) + $row0 + (r1 + 1) + ":" + $col1 + chatatABC(c2) + $row1 + (r2 + 1); } } } }, - israngeseleciton: function(istooltip) { + israngeseleciton: function (istooltip) { let _this = this; if (_this.operatorjson == null) { @@ -2459,7 +2459,7 @@ const luckysheetformula = { txt = $.trim(ahr.text()); lasttxt = txt.substr(txt.length - 1, 1); _this.rangeSetValueTo = ahr; - } + } else { lasttxt = txt.substr(anchorOffset - 1, 1); _this.rangeSetValueTo = anchor.parent(); @@ -2468,7 +2468,7 @@ const luckysheetformula = { if ((istooltip && (lasttxt == "(" || lasttxt == ",")) || (!istooltip && (lasttxt == "(" || lasttxt == "," || lasttxt == "=" || lasttxt in _this.operatorjson || lasttxt == "&"))) { return true; } - } + } else if (anchor.is("#luckysheet-rich-text-editor") || anchor.is("#luckysheet-functionbox-cell")) { let txt = $.trim(anchor.find("span").last().text()), lasttxt; @@ -2486,7 +2486,7 @@ const luckysheetformula = { if ((istooltip && (lasttxt == "(" || lasttxt == ",")) || (!istooltip && (lasttxt == "(" || lasttxt == "," || lasttxt == "=" || lasttxt in _this.operatorjson || lasttxt == "&"))) { return true; } - } + } else if (anchor.parent().is("#luckysheet-rich-text-editor") || anchor.parent().is("#luckysheet-functionbox-cell") || anchorOffset == 0) { if (anchorOffset == 0) { anchor = anchor.parent(); @@ -2511,94 +2511,94 @@ const luckysheetformula = { rangetosheet: null, rangeSetValueTo: null, func_selectedrange: {}, //函数选区范围 - rangeSetValue: function(selected, obj) { + rangeSetValue: function (selected, obj) { let _this = this; - let range="", rf = selected["row"][0], cf = selected["column"][0]; - if(Store.config["merge"] != null && (rf + "_" + cf) in Store.config["merge"]){ + let range = "", rf = selected["row"][0], cf = selected["column"][0]; + if (Store.config["merge"] != null && (rf + "_" + cf) in Store.config["merge"]) { range = getRangetxt(Store.currentSheetIndex, { - column:[cf, cf], - row:[rf, rf], + column: [cf, cf], + row: [rf, rf], }, _this.rangetosheet); } - else{ + else { range = getRangetxt(Store.currentSheetIndex, selected, _this.rangetosheet); } - + let $editor; if (_this.rangestart || _this.rangedrag_column_start || _this.rangedrag_row_start) { - if($("#luckysheet-search-formula-parm").is(":visible")||$("#luckysheet-search-formula-parm-select").is(":visible")){ + if ($("#luckysheet-search-formula-parm").is(":visible") || $("#luckysheet-search-formula-parm-select").is(":visible")) { //公式参数框选取范围 $editor = $("#luckysheet-rich-text-editor"); $("#luckysheet-search-formula-parm-select-input").val(range); $("#luckysheet-search-formula-parm .parmBox").eq(_this.data_parm_index).find(".txt input").val(range); - + //参数对应值显示 let txtdata = luckysheet_getcelldata(range).data; - if(txtdata instanceof Array){ + if (txtdata instanceof Array) { //参数为多个单元格选区 - let txtArr=[]; + let txtArr = []; - for(let i = 0; i < txtdata.length; i++){ - for(let j = 0; j < txtdata[i].length; j++){ - if(txtdata[i][j] == null){ + for (let i = 0; i < txtdata.length; i++) { + for (let j = 0; j < txtdata[i].length; j++) { + if (txtdata[i][j] == null) { txtArr.push(null); } - else{ + else { txtArr.push(txtdata[i][j].v); } } } - $("#luckysheet-search-formula-parm .parmBox").eq(_this.data_parm_index).find(".val").text(" = {"+ txtArr.join(",") +"}"); + $("#luckysheet-search-formula-parm .parmBox").eq(_this.data_parm_index).find(".val").text(" = {" + txtArr.join(",") + "}"); } - else{ + else { //参数为单个单元格选区 - $("#luckysheet-search-formula-parm .parmBox").eq(_this.data_parm_index).find(".val").text(" = {"+ txtdata.v +"}"); + $("#luckysheet-search-formula-parm .parmBox").eq(_this.data_parm_index).find(".val").text(" = {" + txtdata.v + "}"); } //计算结果显示 let isVal = true; //参数不为空 let parmValArr = []; //参数值集合 let lvi = -1; //最后一个有值的参数索引 - $("#luckysheet-search-formula-parm .parmBox").each(function(i, e){ + $("#luckysheet-search-formula-parm .parmBox").each(function (i, e) { let parmtxt = $(e).find(".txt input").val(); - if(parmtxt == "" && $(e).find(".txt input").attr("data_parm_require") == "m"){ + if (parmtxt == "" && $(e).find(".txt input").attr("data_parm_require") == "m") { isVal = false; } - if(parmtxt != ""){ + if (parmtxt != "") { lvi = i; } }) //单元格显示 let functionHtmlTxt; - if(lvi == -1){ - functionHtmlTxt = "=" + $("#luckysheet-search-formula-parm .luckysheet-modal-dialog-title-text").text() + "()"; + if (lvi == -1) { + functionHtmlTxt = "=" + $("#luckysheet-search-formula-parm .luckysheet-modal-dialog-title-text").text() + "()"; } - else if(lvi == 0){ - functionHtmlTxt = "=" + $("#luckysheet-search-formula-parm .luckysheet-modal-dialog-title-text").text() + "(" + $("#luckysheet-search-formula-parm .parmBox").eq(0).find(".txt input").val() + ")"; + else if (lvi == 0) { + functionHtmlTxt = "=" + $("#luckysheet-search-formula-parm .luckysheet-modal-dialog-title-text").text() + "(" + $("#luckysheet-search-formula-parm .parmBox").eq(0).find(".txt input").val() + ")"; } - else{ - for(let j = 0; j <= lvi; j++){ + else { + for (let j = 0; j <= lvi; j++) { parmValArr.push($("#luckysheet-search-formula-parm .parmBox").eq(j).find(".txt input").val()); } - functionHtmlTxt = "=" + $("#luckysheet-search-formula-parm .luckysheet-modal-dialog-title-text").text() + "(" + parmValArr.join(",") + ")"; + functionHtmlTxt = "=" + $("#luckysheet-search-formula-parm .luckysheet-modal-dialog-title-text").text() + "(" + parmValArr.join(",") + ")"; } let function_str = _this.functionHTMLGenerate(functionHtmlTxt); $("#luckysheet-rich-text-editor").html(function_str); $("#luckysheet-functionbox-cell").html($("#luckysheet-rich-text-editor").html()); - - if(isVal){ + + if (isVal) { //公式计算 let fp = $.trim(_this.functionParserExe($("#luckysheet-rich-text-editor").text())); let result = new Function("return " + fp)(); $("#luckysheet-search-formula-parm .result span").text(result); } } - else{ + else { let currSelection = window.getSelection(); let anchorOffset = currSelection.anchorNode; $editor = $(anchorOffset).closest("div"); @@ -2607,7 +2607,7 @@ const luckysheetformula = { _this.setCaretPosition($span.get(0), 0, range.length); } - } + } else { let function_str = '' + range + ''; let $t = $(function_str).insertAfter(_this.rangeSetValueTo); @@ -2620,18 +2620,18 @@ const luckysheetformula = { if ($editor.attr("id") == "luckysheet-rich-text-editor") { $("#luckysheet-functionbox-cell").html($("#luckysheet-rich-text-editor").html()); - } + } else { $("#luckysheet-rich-text-editor").html($("#luckysheet-functionbox-cell").html()); } }, - rangedrag: function(event) { + rangedrag: function (event) { let _this = this; let mouse = mouseposition(event.pageX, event.pageY); let x = mouse[0] + $("#luckysheet-cell-main").scrollLeft(); let y = mouse[1] + $("#luckysheet-cell-main").scrollTop(); - + let row_location = rowLocation(y), row = row_location[1], row_pre = row_location[0], @@ -2650,12 +2650,12 @@ const luckysheetformula = { top = row_pre; height = _this.func_selectedrange.top + _this.func_selectedrange.height - row_pre; rowseleted = [row_index, _this.func_selectedrange.row[1]]; - } + } else if (_this.func_selectedrange.top == row_pre) { top = row_pre; height = _this.func_selectedrange.top + _this.func_selectedrange.height - row_pre; rowseleted = [row_index, _this.func_selectedrange.row[0]]; - } + } else { top = _this.func_selectedrange.top; height = row - _this.func_selectedrange.top - 1; @@ -2670,12 +2670,12 @@ const luckysheetformula = { left = col_pre; width = _this.func_selectedrange.left + _this.func_selectedrange.width - col_pre; columnseleted = [col_index, _this.func_selectedrange.column[1]]; - } + } else if (_this.func_selectedrange.left == col_pre) { left = col_pre; width = _this.func_selectedrange.left + _this.func_selectedrange.width - col_pre; columnseleted = [col_index, _this.func_selectedrange.column[0]]; - } + } else { left = _this.func_selectedrange.left; width = col - _this.func_selectedrange.left - 1; @@ -2687,10 +2687,10 @@ const luckysheetformula = { columnseleted[0] = luckysheetFreezen.changeFreezenIndex(columnseleted[0], "v"); columnseleted[1] = luckysheetFreezen.changeFreezenIndex(columnseleted[1], "v"); - let changeparam = menuButton.mergeMoveMain(columnseleted, rowseleted, _this.func_selectedrange, top , height, left , width); - if(changeparam != null){ + let changeparam = menuButton.mergeMoveMain(columnseleted, rowseleted, _this.func_selectedrange, top, height, left, width); + if (changeparam != null) { columnseleted = changeparam[0]; - rowseleted= changeparam[1]; + rowseleted = changeparam[1]; top = changeparam[2]; height = changeparam[3]; left = changeparam[4]; @@ -2714,29 +2714,29 @@ const luckysheetformula = { "height": height }).show(); - if($("#luckysheet-ifFormulaGenerator-multiRange-dialog").is(":visible")){ + if ($("#luckysheet-ifFormulaGenerator-multiRange-dialog").is(":visible")) { //if公式生成器 选择范围 let range = getRangetxt(Store.currentSheetIndex, { "row": rowseleted, "column": columnseleted }, Store.currentSheetIndex); $("#luckysheet-ifFormulaGenerator-multiRange-dialog input").val(range); } - else{ + else { _this.rangeSetValue({ "row": rowseleted, "column": columnseleted - }); + }); } - + luckysheetFreezen.scrollFreezen(rowseleted, columnseleted); }, rangedrag_column_start: false, rangedrag_row_start: false, - rangedrag_column: function(event) { + rangedrag_column: function (event) { let _this = this; let mouse = mouseposition(event.pageX, event.pageY); let x = mouse[0] + $("#luckysheet-cell-main").scrollLeft(); let y = mouse[1] + $("#luckysheet-cell-main").scrollTop(); - + let visibledatarow = Store.visibledatarow; let row_index = visibledatarow.length - 1, row = visibledatarow[row_index], @@ -2755,12 +2755,12 @@ const luckysheetformula = { left = col_pre; width = _this.func_selectedrange.left + _this.func_selectedrange.width - col_pre; columnseleted = [col_index, _this.func_selectedrange.column[1]]; - } + } else if (_this.func_selectedrange.left == col_pre) { left = col_pre; width = _this.func_selectedrange.left + _this.func_selectedrange.width - col_pre; columnseleted = [col_index, _this.func_selectedrange.column[0]]; - } + } else { left = _this.func_selectedrange.left; width = col - _this.func_selectedrange.left - 1; @@ -2772,8 +2772,8 @@ const luckysheetformula = { columnseleted[0] = luckysheetFreezen.changeFreezenIndex(columnseleted[0], "v"); columnseleted[1] = luckysheetFreezen.changeFreezenIndex(columnseleted[1], "v"); - let changeparam = menuButton.mergeMoveMain(columnseleted, [0, row_index], _this.func_selectedrange, row_pre , row - row_pre - 1, left , width); - if(changeparam != null){ + let changeparam = menuButton.mergeMoveMain(columnseleted, [0, row_index], _this.func_selectedrange, row_pre, row - row_pre - 1, left, width); + if (changeparam != null) { columnseleted = changeparam[0]; // rowseleted= changeparam[1]; // top = changeparam[2]; @@ -2799,10 +2799,10 @@ const luckysheetformula = { "top": row_pre, "height": row - row_pre - 1 }).show(); - + luckysheetFreezen.scrollFreezen([0, row_index], columnseleted); }, - rangedrag_row: function(event) { + rangedrag_row: function (event) { let _this = this; let mouse = mouseposition(event.pageX, event.pageY); @@ -2818,7 +2818,7 @@ const luckysheetformula = { let col_index = visibledatacolumn.length - 1, col = visibledatacolumn[col_index], col_pre = 0; - + let top = 0, height = 0, rowseleted = []; @@ -2827,12 +2827,12 @@ const luckysheetformula = { top = row_pre; height = _this.func_selectedrange.top + _this.func_selectedrange.height - row_pre; rowseleted = [row_index, _this.func_selectedrange.row[1]]; - } + } else if (_this.func_selectedrange.top == row_pre) { top = row_pre; height = _this.func_selectedrange.top + _this.func_selectedrange.height - row_pre; rowseleted = [row_index, _this.func_selectedrange.row[0]]; - } + } else { top = _this.func_selectedrange.top; height = row - _this.func_selectedrange.top - 1; @@ -2845,9 +2845,9 @@ const luckysheetformula = { // columnseleted[1] = luckysheetFreezen.changeFreezenIndex(columnseleted[1], "v"); let changeparam = menuButton.mergeMoveMain([0, col_index], rowseleted, _this.func_selectedrange, top, height, col_pre, col - col_pre - 1); - if(changeparam != null){ + if (changeparam != null) { // columnseleted = changeparam[0]; - rowseleted= changeparam[1]; + rowseleted = changeparam[1]; top = changeparam[2]; height = changeparam[3]; // left = changeparam[4]; @@ -2874,7 +2874,7 @@ const luckysheetformula = { luckysheetFreezen.scrollFreezen(rowseleted, [0, col_index]); }, - rangedragged: function() {}, + rangedragged: function () { }, rangeResizeObj: null, rangeResize: null, rangeResizeIndex: null, @@ -2882,9 +2882,9 @@ const luckysheetformula = { rangeResizeWinH: null, rangeResizeWinW: null, rangeResizeTo: null, - rangeResizeDraging: function(event, luckysheetCurrentChartResizeObj, luckysheetCurrentChartResizeXy, luckysheetCurrentChartResize, luckysheetCurrentChartResizeWinW, luckysheetCurrentChartResizeWinH, ch_width, rh_height) { + rangeResizeDraging: function (event, luckysheetCurrentChartResizeObj, luckysheetCurrentChartResizeXy, luckysheetCurrentChartResize, luckysheetCurrentChartResizeWinW, luckysheetCurrentChartResizeWinH, ch_width, rh_height) { let _this = this; - + let scrollTop = $("#luckysheet-scrollbar-y").scrollTop(), scrollLeft = $("#luckysheet-scrollbar-x").scrollLeft(); let mouse = mouseposition(event.pageX, event.pageY); @@ -2918,11 +2918,11 @@ const luckysheetformula = { left = col_pre; width = luckysheetCurrentChartResizeXy[2] - leftchange; - + if (left > luckysheetCurrentChartResizeXy[2] + luckysheetCurrentChartResizeXy[4] - col + col_pre) { left = luckysheetCurrentChartResizeXy[2] + luckysheetCurrentChartResizeXy[4] - col + col_pre; width = luckysheetCurrentChartResizeXy[2] - (luckysheetCurrentChartResizeXy[2] + luckysheetCurrentChartResizeXy[4] - col + col_pre - luckysheetCurrentChartResizeXy[0]); - } + } else if (left <= 0) { left = 0; width = luckysheetCurrentChartResizeXy[2] + luckysheetCurrentChartResizeXy[0]; @@ -2935,10 +2935,10 @@ const luckysheetformula = { } width = luckysheetCurrentChartResizeXy[2] + col - luckysheetCurrentChartResizeXy[6]; - + if (width < col - col_pre - 1) { width = col - col_pre - 1; - } + } else if (width >= ch_width - left) { width = ch_width - left; } @@ -2951,11 +2951,11 @@ const luckysheetformula = { top = row_pre; height = luckysheetCurrentChartResizeXy[3] - topchange; - + if (top > luckysheetCurrentChartResizeXy[3] + luckysheetCurrentChartResizeXy[5] - row + row_pre) { top = luckysheetCurrentChartResizeXy[3] + luckysheetCurrentChartResizeXy[5] - row + row_pre; height = luckysheetCurrentChartResizeXy[3] - (luckysheetCurrentChartResizeXy[3] + luckysheetCurrentChartResizeXy[5] - row + row_pre - luckysheetCurrentChartResizeXy[1]); - } + } else if (top <= 0) { top = 0; height = luckysheetCurrentChartResizeXy[3] + luckysheetCurrentChartResizeXy[1]; @@ -2968,10 +2968,10 @@ const luckysheetformula = { } height = luckysheetCurrentChartResizeXy[3] + row - luckysheetCurrentChartResizeXy[7]; - + if (height < row - row_pre - 1) { height = row - row_pre - 1; - } + } else if (height >= rh_height - top) { height = rh_height - top; } @@ -2990,7 +2990,7 @@ const luckysheetformula = { luckysheetRangeLast(_this.rangeResizeTo[0]); luckysheetCurrentChartResizeObj.css(selected).data("range", range); }, - getSelectedFromRange: function(obj) { + getSelectedFromRange: function (obj) { let row_st = obj.top + 2, row_ed = obj.top + obj.height - 2; let col_st = obj.left + 2, @@ -3009,7 +3009,7 @@ const luckysheetformula = { return ret; }, - rangeResizeDragged: function(event, luckysheetCurrentChartResizeObj, luckysheetCurrentChartResizeXy, luckysheetCurrentChartResize, luckysheetCurrentChartResizeWinW, luckysheetCurrentChartResizeWinH) { + rangeResizeDragged: function (event, luckysheetCurrentChartResizeObj, luckysheetCurrentChartResizeXy, luckysheetCurrentChartResize, luckysheetCurrentChartResizeWinW, luckysheetCurrentChartResizeWinH) { let _this = this; _this.rangeResize = null; @@ -3020,9 +3020,9 @@ const luckysheetformula = { rangeMoveObj: null, rangeMoveIndex: null, rangeMoveRangedata: null, - rangeMoveDraging: function(event, luckysheet_cell_selected_move_index, luckysheet_select_save, obj, sheetBarHeight, statisticBarHeight) { + rangeMoveDraging: function (event, luckysheet_cell_selected_move_index, luckysheet_select_save, obj, sheetBarHeight, statisticBarHeight) { let _this = this; - + let mouse = mouseposition(event.pageX, event.pageY); let scrollLeft = $("#luckysheet-scrollbar-x").scrollLeft(); let scrollTop = $("#luckysheet-scrollbar-y").scrollTop(); @@ -3078,7 +3078,7 @@ const luckysheetformula = { _this.rangeMoveRangedata = range; obj.css(selected); }, - rangeMoveDragged: function(obj) { + rangeMoveDragged: function (obj) { let _this = this; _this.rangeMove = false; @@ -3086,7 +3086,7 @@ const luckysheetformula = { }, functionHTMLIndex: 0, functionRangeIndex: null, - findrangeindex: function(v, vp) { + findrangeindex: function (v, vp) { let _this = this; let re = //g; @@ -3103,38 +3103,38 @@ const luckysheetformula = { let vplen = vp_a.length, vlen = v_a.length; //不增加元素输入 - if(vplen == vlen){ + if (vplen == vlen) { let i = pfri[0]; let p = vp_a[i], n = v_a[i]; - - if(p == null){ - if(vp_a.length <= i){ + + if (p == null) { + if (vp_a.length <= i) { pfri = [vp_a.length - 1, vp_a.length - 1]; } - else if(v_a.length<=i){ + else if (v_a.length <= i) { pfri = [v_a.length - 1, v_a.length - 1]; } return pfri; } - else if(p.length == n.length){ - if(vp_a[i + 1] != null && v_a[i + 1] != null && vp_a[i + 1].length < v_a[i + 1].length){ + else if (p.length == n.length) { + if (vp_a[i + 1] != null && v_a[i + 1] != null && vp_a[i + 1].length < v_a[i + 1].length) { pfri[0] = pfri[0] + 1; pfri[1] = 1; } return pfri; } - else if(p.length > n.length){ - if(p != null && v_a[i + 1] != null && v_a[i + 1].substr(0,1) == '"' && (p.indexOf("{") > -1 || p.indexOf("}") > -1)){ + else if (p.length > n.length) { + if (p != null && v_a[i + 1] != null && v_a[i + 1].substr(0, 1) == '"' && (p.indexOf("{") > -1 || p.indexOf("}") > -1)) { pfri[0] = pfri[0] + 1; pfri[1] = 1; } return pfri; } - else if(p.length < n.length){ - if(pfri[1] > n.length){ + else if (p.length < n.length) { + if (pfri[1] > n.length) { pfri[1] = n.length; } @@ -3142,132 +3142,132 @@ const luckysheetformula = { } } //减少元素输入 - else if(vplen > vlen){ + else if (vplen > vlen) { let i = pfri[0]; let p = vp_a[i], n = v_a[i]; - if(n == null){ - if(v_a[i - 1].indexOf("{") > -1){ - pfri[0] = pfri[0] -1; + if (n == null) { + if (v_a[i - 1].indexOf("{") > -1) { + pfri[0] = pfri[0] - 1; let start = v_a[i - 1].search("{"); pfri[1] = pfri[1] + start; } - else{ + else { pfri[0] = 0; pfri[1] = 0; } } - else if(p.length == n.length){ - if(v_a[i + 1] != null && (v_a[i + 1].substr(0,1) == '"' || v_a[i + 1].substr(0,1) == '{' || v_a[i + 1].substr(0,1) == '}')){ + else if (p.length == n.length) { + if (v_a[i + 1] != null && (v_a[i + 1].substr(0, 1) == '"' || v_a[i + 1].substr(0, 1) == '{' || v_a[i + 1].substr(0, 1) == '}')) { pfri[0] = pfri[0] + 1; pfri[1] = 1; } - else if(p != null && p.length > 2 && p.substr(0,1) == '"' && p.substr(p.length - 1, 1) == '"' ){ + else if (p != null && p.length > 2 && p.substr(0, 1) == '"' && p.substr(p.length - 1, 1) == '"') { //pfri[1] = n.length-1; } - else if(v_a[i] != null && v_a[i] == '")'){ + else if (v_a[i] != null && v_a[i] == '")') { pfri[1] = 1; } - else if(v_a[i] != null && v_a[i] == '"}'){ + else if (v_a[i] != null && v_a[i] == '"}') { pfri[1] = 1; } - else if(v_a[i] != null && v_a[i] == '{)'){ + else if (v_a[i] != null && v_a[i] == '{)') { pfri[1] = 1; } - else{ + else { pfri[1] = n.length; } - + return pfri; } - else if(p.length > n.length){ - if(v_a[i + 1] != null && (v_a[i + 1].substr(0,1) == '"' || v_a[i + 1].substr(0,1) == '{' || v_a[i+1].substr(0,1) == '}')){ + else if (p.length > n.length) { + if (v_a[i + 1] != null && (v_a[i + 1].substr(0, 1) == '"' || v_a[i + 1].substr(0, 1) == '{' || v_a[i + 1].substr(0, 1) == '}')) { pfri[0] = pfri[0] + 1; pfri[1] = 1; } return pfri; } - else if(p.length < n.length){ + else if (p.length < n.length) { return pfri; } - + return pfri; } //增加元素输入 - else if(vplen < vlen){ + else if (vplen < vlen) { let i = pfri[0]; let p = vp_a[i], n = v_a[i]; - if(p == null){ + if (p == null) { pfri[0] = v_a.length - 1; - - if(n != null){ + + if (n != null) { pfri[1] = n.length; } - else{ + else { pfri[1] = 1; } } - else if(p.length == n.length){ - if(vp_a[i + 1] != null && (vp_a[i + 1].substr(0, 1) == '"' || vp_a[i + 1].substr(0, 1) == '{' || vp_a[i + 1].substr(0, 1) == '}') ){ + else if (p.length == n.length) { + if (vp_a[i + 1] != null && (vp_a[i + 1].substr(0, 1) == '"' || vp_a[i + 1].substr(0, 1) == '{' || vp_a[i + 1].substr(0, 1) == '}')) { pfri[1] = n.length; } - else if(v_a[i + 1] != null && v_a[i + 1].substr(0, 1) == '"' && ( v_a[i + 1].substr(0, 1) == '{' || v_a[i + 1].substr(0, 1) == '}') ){ + else if (v_a[i + 1] != null && v_a[i + 1].substr(0, 1) == '"' && (v_a[i + 1].substr(0, 1) == '{' || v_a[i + 1].substr(0, 1) == '}')) { pfri[0] = pfri[0] + 1; pfri[1] = 1; } - else if(n != null && n.substr(0, 1) == '"' && n.substr(n.length - 1, 1) == '"' && p.substr(0, 1) == '"' && p.substr(p.length - 1, 1) == ')'){ + else if (n != null && n.substr(0, 1) == '"' && n.substr(n.length - 1, 1) == '"' && p.substr(0, 1) == '"' && p.substr(p.length - 1, 1) == ')') { pfri[1] = n.length; } - else if(n != null && n.substr(0, 1) == '{' && n.substr(n.length - 1, 1) == '}' && p.substr(0, 1) == '{' && p.substr(p.length - 1, 1) == ')'){ + else if (n != null && n.substr(0, 1) == '{' && n.substr(n.length - 1, 1) == '}' && p.substr(0, 1) == '{' && p.substr(p.length - 1, 1) == ')') { pfri[1] = n.length; } - else{ + else { pfri[0] = pfri[0] + vlen - vplen; - if(v_a.length > vp_a.length){ + if (v_a.length > vp_a.length) { pfri[1] = v_a[i + 1].length; } - else{ + else { pfri[1] = 1; } } return pfri; } - else if(p.length > n.length){ - if(p != null && p.substr(0, 1) == '"'){ + else if (p.length > n.length) { + if (p != null && p.substr(0, 1) == '"') { pfri[1] = n.length; } - else if(v_a[i + 1] != null && /{.*?}/.test(v_a[i + 1])){ + else if (v_a[i + 1] != null && /{.*?}/.test(v_a[i + 1])) { pfri[0] = pfri[0] + 1; pfri[1] = v_a[i + 1].length; } - else if(p != null && v_a[i + 1].substr(0, 1) == '"' && (p.indexOf("{") > -1 || p.indexOf("}") > -1)){ + else if (p != null && v_a[i + 1].substr(0, 1) == '"' && (p.indexOf("{") > -1 || p.indexOf("}") > -1)) { pfri[0] = pfri[0] + 1; pfri[1] = 1; } - else if(p != null && (p.indexOf("{") > -1 || p.indexOf("}") > -1)){ + else if (p != null && (p.indexOf("{") > -1 || p.indexOf("}") > -1)) { } - else{ + else { pfri[0] = pfri[0] + vlen - vplen - 1; pfri[1] = v_a[i - 1].length; } return pfri; } - else if(p.length < n.length){ + else if (p.length < n.length) { return pfri; } - + return pfri; } return null; }, - setCaretPosition: function(textDom, children, pos) { - try{ + setCaretPosition: function (textDom, children, pos) { + try { let el = textDom; let range = document.createRange(); let sel = window.getSelection(); @@ -3277,33 +3277,33 @@ const luckysheetformula = { sel.addRange(range); el.focus(); } - catch(err) { + catch (err) { luckysheetRangeLast(this.rangeResizeTo[0]); } }, - functionRange: function(obj, v, vp) { + functionRange: function (obj, v, vp) { let _this = this; if (window.getSelection) { //ie11 10 9 ff safari let currSelection = window.getSelection(); let fri = _this.findrangeindex(v, vp); - + if (fri == null) { currSelection.selectAllChildren(obj.get(0)); currSelection.collapseToEnd(); - } + } else { _this.setCaretPosition(obj.find("span").get(fri[0]), 0, fri[1]); } - } + } else if (document.selection) { //ie10 9 8 7 6 5 _this.functionRangeIndex.moveToElementText(obj); //range定位到obj _this.functionRangeIndex.collapse(false); //光标移至最后 _this.functionRangeIndex.select(); } }, - functionInputHanddler: function($to, $input, kcode) { - if(isEditMode()){//此模式下禁用公式栏 + functionInputHanddler: function ($to, $input, kcode) { + if (isEditMode()) {//此模式下禁用公式栏 return; } @@ -3314,7 +3314,7 @@ const luckysheetformula = { let value1 = $editer.html(), value1txt = $editer.text(); - setTimeout(function() { + setTimeout(function () { let value = $editer.text(), valuetxt = value; @@ -3324,14 +3324,14 @@ const luckysheetformula = { if (window.getSelection) { // all browsers, except IE before version 9 let currSelection = window.getSelection(); - if($(currSelection.anchorNode).is("div")){ + if ($(currSelection.anchorNode).is("div")) { let editorlen = $("#luckysheet-rich-text-editor span").length; - _this.functionRangeIndex = [editorlen-1, $("#luckysheet-rich-text-editor").find("span").eq(editorlen-1).text().length]; + _this.functionRangeIndex = [editorlen - 1, $("#luckysheet-rich-text-editor").find("span").eq(editorlen - 1).text().length]; } - else{ + else { _this.functionRangeIndex = [$(currSelection.anchorNode).parent().index(), currSelection.anchorOffset]; } - } + } else { // Internet Explorer before version 9 let textRange = document.selection.createRange(); _this.functionRangeIndex = textRange; @@ -3341,7 +3341,7 @@ const luckysheetformula = { _this.functionRange($editer, value, value1); _this.canceFunctionrangeSelected(); - if(kcode != 46){//delete不执行此函数 + if (kcode != 46) {//delete不执行此函数 _this.createRangeHightlight(); } @@ -3349,11 +3349,11 @@ const luckysheetformula = { _this.rangestart = false; _this.rangedrag_column_start = false; _this.rangedrag_row_start = false; - + _this.rangeHightlightselected($editer, kcode); } - else if(value1txt.substr(0, 1) != "=" ){ + else if (value1txt.substr(0, 1) != "=") { //&& value1.indexOf("span")>-1 // $editer.html(value1); @@ -3373,20 +3373,20 @@ const luckysheetformula = { // $editer.html(value); // } // } - + // } // console.trace(); // console.log(value, $copy.attr("id")); - if($copy.attr("id")=="luckysheet-rich-text-editor"){ - if($copy.html().substr(0,5) == "=' + _this.functionHTML(txt); }, - functionHTML: function(txt) { + functionHTML: function (txt) { let _this = this; if (_this.operatorjson == null) { @@ -3438,29 +3438,29 @@ const luckysheetformula = { while (i < funcstack.length) { let s = funcstack[i]; - + if (s == "(" && matchConfig.dquote == 0 && matchConfig.braces == 0) { matchConfig.bracket += 1; - + if (str.length > 0) { function_str += '' + str + '('; - } + } else { function_str += '('; } str = ""; - } + } else if (s == ")" && matchConfig.dquote == 0 && matchConfig.braces == 0) { matchConfig.bracket -= 1; function_str += _this.functionHTML(str) + ')'; str = ""; } - else if(s=="{" && matchConfig.dquote == 0) { + else if (s == "{" && matchConfig.dquote == 0) { str += '{'; matchConfig.braces += 1; } - else if(s=="}" && matchConfig.dquote == 0) { + else if (s == "}" && matchConfig.dquote == 0) { str += '}'; matchConfig.braces -= 1; } @@ -3468,37 +3468,37 @@ const luckysheetformula = { if (matchConfig.dquote > 0) { if (str.length > 0) { function_str += str + '"'; - } + } else { function_str += '"'; } matchConfig.dquote -= 1; str = ""; - } + } else { matchConfig.dquote += 1; - + if (str.length > 0) { function_str += _this.functionHTML(str) + '"'; - } + } else { function_str += '"'; } - + str = ""; } - } + } else if (s == ',' && matchConfig.dquote == 0 && matchConfig.braces == 0) { //matchConfig.comma += 1; function_str += _this.functionHTML(str) + ','; str = ""; - } + } else if (s == '&' && matchConfig.dquote == 0 && matchConfig.braces == 0) { if (str.length > 0) { function_str += _this.functionHTML(str) + '' + '&' + '';; str = ""; - } + } else { function_str += '' + '&' + ''; } @@ -3509,38 +3509,38 @@ const luckysheetformula = { s_next = funcstack[i + 1]; } - let p = i-1, s_pre = null;; - if(p >= 0){ + let p = i - 1, s_pre = null;; + if (p >= 0) { do { s_pre = funcstack[p--]; } - while (p >= 0 && s_pre ==" ") + while (p >= 0 && s_pre == " ") } if ((s + s_next) in _this.operatorjson) { if (str.length > 0) { function_str += _this.functionHTML(str) + '' + s + s_next + ''; str = ""; - } + } else { function_str += '' + s + s_next + ''; } i++; - } - else if(!(/[^0-9]/.test(s_next)) && s=="-" && (s_pre=="(" || s_pre == null || s_pre == "," || s_pre == " " || s_pre in _this.operatorjson ) ){ + } + else if (!(/[^0-9]/.test(s_next)) && s == "-" && (s_pre == "(" || s_pre == null || s_pre == "," || s_pre == " " || s_pre in _this.operatorjson)) { str += s; } else { if (str.length > 0) { function_str += _this.functionHTML(str) + '' + s + ''; str = ""; - } + } else { function_str += '' + s + ''; } } - } + } else { str += s; } @@ -3550,31 +3550,31 @@ const luckysheetformula = { if (_this.iscelldata($.trim(str))) { function_str += '' + str + ''; _this.functionHTMLIndex++; - } + } else if (matchConfig.dquote > 0) { function_str += str + ''; - } + } else if (str.indexOf("") == -1 && str.length > 0) { let regx = /{.*?}/; - - if(regx.test($.trim(str))){ + + if (regx.test($.trim(str))) { let arraytxt = regx.exec(str)[0]; let arraystart = str.search(regx); let alltxt = ""; - - if(arraystart > 0){ + + if (arraystart > 0) { alltxt += '' + str.substr(0, arraystart) + ''; } - + alltxt += '' + arraytxt + ''; - if(arraystart + arraytxt.length < str.length){ + if (arraystart + arraytxt.length < str.length) { alltxt += '' + str.substr(arraystart + arraytxt.length, str.length) + ''; } function_str += alltxt; } - else{ + else { function_str += '' + str + ''; } } @@ -3585,13 +3585,13 @@ const luckysheetformula = { return function_str; }, - getfunctionParam: function(txt) { + getfunctionParam: function (txt) { let _this = this; if (_this.operatorjson == null) { let arr = _this.operator.split("|"), op = {}; - + for (let i = 0; i < arr.length; i++) { op[arr[i].toString()] = 1; } @@ -3622,49 +3622,49 @@ const luckysheetformula = { let s = funcstack[i]; if (s == "(" && matchConfig.dquote == 0) { - if (str.length > 0 && bracket.length==0) { + if (str.length > 0 && bracket.length == 0) { fn = str.toUpperCase(); bracket.push(1); str = ""; } - else if(bracket.length==0) { + else if (bracket.length == 0) { //function_str += "("; bracket.push(0); str = ""; } - else{ + else { bracket.push(0); str += s; } - } + } else if (s == ")" && matchConfig.dquote == 0) { let bt = bracket.pop(); - if(bracket.length == 0){ + if (bracket.length == 0) { param.push(str); str = ""; } - else{ + else { str += s; } } else if (s == '"') { str += '"'; - + if (matchConfig.dquote > 0) { matchConfig.dquote -= 1; str = ""; - } + } else { matchConfig.dquote += 1; } - } + } else if (s == ',' && matchConfig.dquote == 0) { - if(bracket.length <= 1){ + if (bracket.length <= 1) { param.push(str); str = ""; } - else{ + else { str += ","; } } @@ -3674,31 +3674,31 @@ const luckysheetformula = { s_next = funcstack[i + 1]; } - let p = i-1, s_pre = null;; - if(p >= 0){ + let p = i - 1, s_pre = null;; + if (p >= 0) { do { s_pre = funcstack[p--]; } - while (p >= 0 && s_pre ==" ") + while (p >= 0 && s_pre == " ") } - if(!(/[^0-9]/.test(s_next)) && s=="-" && (s_pre=="(" || s_pre == null || s_pre == "," || s_pre == " " || s_pre in _this.operatorjson ) ){ + if (!(/[^0-9]/.test(s_next)) && s == "-" && (s_pre == "(" || s_pre == null || s_pre == "," || s_pre == " " || s_pre in _this.operatorjson)) { if (matchConfig.dquote == 0) { str += $.trim(s); - } + } else { str += s; } } - else{ - function_str= ""; + else { + function_str = ""; str = ""; } - } + } else { if (matchConfig.dquote == 0) { str += $.trim(s); - } + } else { str += s; } @@ -3707,17 +3707,17 @@ const luckysheetformula = { i++; } - return {"fn": fn, "param": param}; + return { "fn": fn, "param": param }; }, - calPostfixExpression: function(cal){ - if(cal.length == 0){ + calPostfixExpression: function (cal) { + if (cal.length == 0) { return ""; } let stack = []; - for(let i = cal.length - 1; i >= 0; i--){ + for (let i = cal.length - 1; i >= 0; i--) { let c = cal[i]; - if(c in this.operatorjson){ + if (c in this.operatorjson) { let s2 = stack.pop(); let s1 = stack.pop(); @@ -3725,19 +3725,19 @@ const luckysheetformula = { stack.push(str); } - else{ + else { stack.push(c); } } - if(stack.length > 0){ + if (stack.length > 0) { return stack[0]; } - else{ + else { return ""; - } + } }, - checkBracketNum: function(fp){ + checkBracketNum: function (fp) { let bra_l = fp.match(/\(/g), bra_r = fp.match(/\)/g), bra_tl_txt = fp.match(/(['"])(?:(?!\1).)*?\1/g), @@ -3752,8 +3752,8 @@ const luckysheetformula = { } let bra_tl_len = 0, bra_tr_len = 0; - if(bra_tl_txt != null){ - for(let i = 0; i < bra_tl_txt.length; i++){ + if (bra_tl_txt != null) { + for (let i = 0; i < bra_tl_txt.length; i++) { let bra_tl = bra_tl_txt[i].match(/\(/g); if (bra_tl != null) { bra_tl_len += bra_tl.length; @@ -3761,8 +3761,8 @@ const luckysheetformula = { } } - if(bra_tr_txt != null){ - for(let i = 0; i < bra_tr_txt.length; i++){ + if (bra_tr_txt != null) { + for (let i = 0; i < bra_tr_txt.length; i++) { let bra_tr = bra_tr_txt[i].match(/\)/g); if (bra_tr != null) { bra_tr_len += bra_tr.length; @@ -3773,10 +3773,10 @@ const luckysheetformula = { bra_l_len -= bra_tl_len; bra_r_len -= bra_tr_len; - if(bra_l_len != bra_r_len){ + if (bra_l_len != bra_r_len) { return false; } - else{ + else { return true; } }, @@ -3788,7 +3788,7 @@ const luckysheetformula = { "+": 2, "-": 2 }, - functionParserExe:function(txt){ + functionParserExe: function (txt) { let _this = this; // let txt1 = txt.toUpperCase(); // return this.functionParser(txt, function(c){ @@ -3796,13 +3796,13 @@ const luckysheetformula = { // }); return this.functionParser(txt); }, - functionParser: function(txt, cellRangeFunction) { + functionParser: function (txt, cellRangeFunction) { let _this = this; if (_this.operatorjson == null) { let arr = _this.operator.split("|"), op = {}; - + for (let i = 0; i < arr.length; i++) { op[arr[i].toString()] = 1; } @@ -3810,7 +3810,7 @@ const luckysheetformula = { _this.operatorjson = op; } - if(txt==null){ + if (txt == null) { return ""; } @@ -3864,79 +3864,79 @@ const luckysheetformula = { if (s == "(" && matchConfig.dquote == 0 && matchConfig.braces == 0) { if (str.length > 0 && bracket.length == 0) { str = str.toUpperCase(); - if(str.indexOf(":")>-1){ + if (str.indexOf(":") > -1) { let funcArray = str.split(":"); - function_str += "luckysheet_getSpecialReference(true,'"+ $.trim(funcArray[0]).replace(/'/g, "\\'") +"', luckysheet_function." + funcArray[1] + ".f(#lucky#"; + function_str += "luckysheet_getSpecialReference(true,'" + $.trim(funcArray[0]).replace(/'/g, "\\'") + "', luckysheet_function." + funcArray[1] + ".f(#lucky#"; } - else{ + else { function_str += "luckysheet_function." + str + ".f("; } bracket.push(1); str = ""; } - else if(bracket.length == 0) { + else if (bracket.length == 0) { function_str += "("; bracket.push(0); str = ""; } - else{ + else { bracket.push(0); str += s; } - } + } else if (s == ")" && matchConfig.dquote == 0 && matchConfig.braces == 0) { let bt = bracket.pop(); - if(bracket.length == 0){ - let functionS = _this.functionParser(str,cellRangeFunction); - if(functionS.indexOf("#lucky#")>-1){ + if (bracket.length == 0) { + let functionS = _this.functionParser(str, cellRangeFunction); + if (functionS.indexOf("#lucky#") > -1) { functionS = functionS.replace(/#lucky#/g, "") + ")"; } function_str += functionS + ")"; str = ""; } - else{ + else { str += s; } } - else if(s == "{" && matchConfig.dquote == 0){ + else if (s == "{" && matchConfig.dquote == 0) { str += '{'; matchConfig.braces += 1; } - else if(s == "}" && matchConfig.dquote == 0){ + else if (s == "}" && matchConfig.dquote == 0) { str += '}'; matchConfig.braces -= 1; } else if (s == '"') { str += '"'; - + if (matchConfig.dquote > 0) { matchConfig.dquote -= 1; - } + } else { matchConfig.dquote += 1; } - } + } else if (s == "'") { str += "'"; - + if (matchConfig.squote > 0) { matchConfig.squote -= 1; - } + } else { matchConfig.squote += 1; } - } + } else if (s == ',' && matchConfig.dquote == 0 && matchConfig.braces == 0) { - if(bracket.length <= 1){ - let functionS = _this.functionParser(str,cellRangeFunction); - if(functionS.indexOf("#lucky#")>-1){ + if (bracket.length <= 1) { + let functionS = _this.functionParser(str, cellRangeFunction); + if (functionS.indexOf("#lucky#") > -1) { functionS = functionS.replace(/#lucky#/g, "") + ")"; } function_str += functionS + ","; str = ""; } - else{ + else { str += ","; } } @@ -3949,51 +3949,51 @@ const luckysheetformula = { } if ((s + s_next) in _this.operatorjson) { - if(bracket.length == 0){ - if($.trim(str).length > 0){ - cal2.unshift(_this.functionParser($.trim(str),cellRangeFunction)); + if (bracket.length == 0) { + if ($.trim(str).length > 0) { + cal2.unshift(_this.functionParser($.trim(str), cellRangeFunction)); } - else if($.trim(function_str).length > 0){ + else if ($.trim(function_str).length > 0) { cal2.unshift($.trim(function_str)); } - if(cal1[0] in _this.operatorjson){ + if (cal1[0] in _this.operatorjson) { let stackCeilPri = op[cal1[0]]; - while(cal1.length > 0 && stackCeilPri != null){ + while (cal1.length > 0 && stackCeilPri != null) { cal2.unshift(cal1.shift()); stackCeilPri = op[cal1[0]]; } } - cal1.unshift(s+s_next); - - function_str= ""; + cal1.unshift(s + s_next); + + function_str = ""; str = ""; - } + } else { str += s + s_next; } i++; - } + } else { - if(bracket.length == 0){ - if($.trim(str).length > 0){ - cal2.unshift(_this.functionParser($.trim(str),cellRangeFunction)); + if (bracket.length == 0) { + if ($.trim(str).length > 0) { + cal2.unshift(_this.functionParser($.trim(str), cellRangeFunction)); } - else if($.trim(function_str).length > 0){ + else if ($.trim(function_str).length > 0) { cal2.unshift($.trim(function_str)); } - if(cal1[0] in _this.operatorjson){ + if (cal1[0] in _this.operatorjson) { let stackCeilPri = op[cal1[0]]; stackCeilPri = stackCeilPri == null ? 1000 : stackCeilPri; - + let sPri = op[s]; sPri = sPri == null ? 1000 : sPri; - while(cal1.length > 0 && sPri >= stackCeilPri){ + while (cal1.length > 0 && sPri >= stackCeilPri) { cal2.unshift(cal1.shift()); stackCeilPri = op[cal1[0]]; @@ -4003,19 +4003,19 @@ const luckysheetformula = { cal1.unshift(s); - function_str= ""; + function_str = ""; str = ""; } - else{ + else { str += s; } } - } + } else { - if (matchConfig.dquote == 0 && matchConfig.squote==0) { + if (matchConfig.dquote == 0 && matchConfig.squote == 0) { // str += $.trim(s); str += s; //Do not use $.trim(s). When obtaining the worksheet name that contains spaces, you should keep the spaces - } + } else { str += s; } @@ -4024,63 +4024,63 @@ const luckysheetformula = { if (i == funcstack.length - 1) { let endstr = ""; let str_nb = $.trim(str).replace(/'/g, "\\'"); - if (_this.iscelldata(str_nb) && str_nb.substr(0,1)!=":") { + if (_this.iscelldata(str_nb) && str_nb.substr(0, 1) != ":") { - endstr = "luckysheet_getcelldata('" +str_nb + "')"; - if(typeof(cellRangeFunction)=="function"){ + endstr = "luckysheet_getcelldata('" + str_nb + "')"; + if (typeof (cellRangeFunction) == "function") { cellRangeFunction(str_nb); } } - else if(str_nb.substr(0,1)==":"){ + else if (str_nb.substr(0, 1) == ":") { str_nb = str_nb.substr(1); - if(_this.iscelldata(str_nb)){ - endstr = "luckysheet_getSpecialReference(false," + function_str +",'"+ str_nb +"')"; + if (_this.iscelldata(str_nb)) { + endstr = "luckysheet_getSpecialReference(false," + function_str + ",'" + str_nb + "')"; } } else { str = $.trim(str); - + let regx = /{.*?}/; - if(regx.test(str) && str.substr(0, 1) != '"' && str.substr(str.length - 1, 1) != '"'){ + if (regx.test(str) && str.substr(0, 1) != '"' && str.substr(str.length - 1, 1) != '"') { let arraytxt = regx.exec(str)[0]; let arraystart = str.search(regx); let alltxt = ""; - - if(arraystart > 0){ + + if (arraystart > 0) { endstr += str.substr(0, arraystart); } - + endstr += "luckysheet_getarraydata('" + arraytxt + "')"; - if(arraystart + arraytxt.length < str.length){ + if (arraystart + arraytxt.length < str.length) { endstr += str.substr(arraystart + arraytxt.length, str.length); } } - else{ + else { endstr = str; } } - if(endstr.length > 0){ + if (endstr.length > 0) { cal2.unshift(endstr); } - if(cal1.length > 0){ - if(function_str.length > 0){ + if (cal1.length > 0) { + if (function_str.length > 0) { cal2.unshift(function_str); function_str = ""; } - - while(cal1.length > 0){ + + while (cal1.length > 0) { cal2.unshift(cal1.shift()); - } + } } - if(cal2.length > 0){ + if (cal2.length > 0) { function_str = _this.calPostfixExpression(cal2); } - else{ + else { function_str += endstr; } } @@ -4090,8 +4090,8 @@ const luckysheetformula = { // console.log(function_str); return function_str; }, - insertUpdateDynamicArray: function(dynamicArrayItem) { - let r = dynamicArrayItem.r , c = dynamicArrayItem.c, index = dynamicArrayItem.index; + insertUpdateDynamicArray: function (dynamicArrayItem) { + let r = dynamicArrayItem.r, c = dynamicArrayItem.c, index = dynamicArrayItem.index; if (index == null) { index = Store.currentSheetIndex; } @@ -4116,7 +4116,7 @@ const luckysheetformula = { dynamicArray.push(dynamicArrayItem); return dynamicArray }, - addFunctionGroup: function(r, c, func, index) { + addFunctionGroup: function (r, c, func, index) { if (index == null) { index = Store.currentSheetIndex; } @@ -4141,57 +4141,57 @@ const luckysheetformula = { }); setluckysheetfile(luckysheetfile); }, - getAllFunctionGroup: function() { + getAllFunctionGroup: function () { let luckysheetfile = getluckysheetfile(); let ret = []; - for(let i=0;i|<=|>=|[,()=+-\/*%&^><]/g); - if(txtArray.length>0){ - for(let i=0;i 0) { + for (let i = 0; i < txtArray.length; i++) { let t = txtArray[i]; - if(t.length<=1){ + if (t.length <= 1) { continue; } - if(t.substr(0,1)=='"' && t.substr(t.length-1,1)=='"'){ + if (t.substr(0, 1) == '"' && t.substr(t.length - 1, 1) == '"') { continue; } @@ -4274,7 +4274,7 @@ const luckysheetformula = { } } }, - isFunctionRangeSimple1: function(txt, r, c, index,dynamicArray_compute) { + isFunctionRangeSimple1: function (txt, r, c, index, dynamicArray_compute) { let _this = this; if (_this.operatorjson == null) { @@ -4306,7 +4306,7 @@ const luckysheetformula = { } let luckysheetfile = getluckysheetfile(); - + while (i < funcstack.length) { let s = funcstack[i]; @@ -4316,23 +4316,23 @@ const luckysheetformula = { if (str.length > 0) { function_str += "luckysheet_function." + str.toUpperCase() + ".f("; - } + } else { function_str += "("; } str = ""; - } + } else if (s == ")" && matchConfig.dquote == 0) { matchConfig.bracket -= 1; - function_str += _this.isFunctionRangeSimple(str, r, c, index,dynamicArray_compute) + ")"; + function_str += _this.isFunctionRangeSimple(str, r, c, index, dynamicArray_compute) + ")"; str = ""; - } + } else if (s == ',' && matchConfig.dquote == 0) { //matchConfig.comma += 1; - function_str += _this.isFunctionRangeSimple(str, r, c, index,dynamicArray_compute) + ','; + function_str += _this.isFunctionRangeSimple(str, r, c, index, dynamicArray_compute) + ','; str = ""; - } + } else if (s in _this.operatorjson && matchConfig.dquote == 0) { let s_next = ""; @@ -4342,25 +4342,25 @@ const luckysheetformula = { if ((s + s_next) in _this.operatorjson) { if (str.length > 0) { - function_str += _this.isFunctionRangeSimple(str, r, c, index,dynamicArray_compute) + s + s_next; + function_str += _this.isFunctionRangeSimple(str, r, c, index, dynamicArray_compute) + s + s_next; str = ""; - } + } else { function_str += s + s_next; } i++; - } + } else { if (str.length > 0) { - function_str += _this.isFunctionRangeSimple(str, r, c, index,dynamicArray_compute) + s; + function_str += _this.isFunctionRangeSimple(str, r, c, index, dynamicArray_compute) + s; str = ""; - } + } else { function_str += s; } } - } + } else { str += s; } @@ -4369,7 +4369,7 @@ const luckysheetformula = { if (_this.iscelldata($.trim(str))) { _this.isFunctionRangeSaveChange(str, r, c, index, dynamicArray_compute); // if (r != null && c != null) { - + // let range = _this.getcellrange($.trim(str)); // let row = range.row, // col = range.column; @@ -4422,61 +4422,61 @@ const luckysheetformula = { //console.log(function_str); return function_str; }, - isFunctionRangeSelect:function(txt, r, c, index, dynamicArray_compute){ - if(txt==null || txt==""){ + isFunctionRangeSelect: function (txt, r, c, index, dynamicArray_compute) { + if (txt == null || txt == "") { return; } - if(index==null){ + if (index == null) { index = Store.currentSheetIndex; } - if(dynamicArray_compute==null){ + if (dynamicArray_compute == null) { dynamicArray_compute = {}; } let _this = this; let txt1 = txt.toUpperCase(); - let isOffsetFunc = txt1.indexOf("INDIRECT(")>-1 || txt1.indexOf("OFFSET(")>-1 || txt1.indexOf("INDEX(")>-1; - if(txt in this.formulaContainCellList){ + let isOffsetFunc = txt1.indexOf("INDIRECT(") > -1 || txt1.indexOf("OFFSET(") > -1 || txt1.indexOf("INDEX(") > -1; + if (txt in this.formulaContainCellList) { let cellList = this.formulaContainCellList[txt]; - if(isOffsetFunc){ + if (isOffsetFunc) { let isoff = cellList["__LuckyisOff__"]; - if(isoff==true){ - for(let cellStr in cellList){ - if(cellStr=="__LuckyisOff__"){ + if (isoff == true) { + for (let cellStr in cellList) { + if (cellStr == "__LuckyisOff__") { continue; } this.isFunctionRangeSaveChange(cellStr, r, c, index, dynamicArray_compute); } } - else{ - this.isFunctionRange(txt, r, c, index,dynamicArray_compute, function(str){ + else { + this.isFunctionRange(txt, r, c, index, dynamicArray_compute, function (str) { _this.addToCellList(txt, str); }); cellList["__LuckyisOff__"] = true; } } - else{ - - for(let cellStr in cellList){ - if(cellStr=="__LuckyisOff__"){ + else { + + for (let cellStr in cellList) { + if (cellStr == "__LuckyisOff__") { continue; } this.isFunctionRangeSaveChange(cellStr, r, c, index, dynamicArray_compute); } } - + return; } - if(isOffsetFunc){ - this.isFunctionRange(txt, r, c, index,dynamicArray_compute); + if (isOffsetFunc) { + this.isFunctionRange(txt, r, c, index, dynamicArray_compute); } - else{ - this.isFunctionRangeSimple(txt, r, c, index,dynamicArray_compute); + else { + this.isFunctionRangeSimple(txt, r, c, index, dynamicArray_compute); } }, - isFunctionRange: function (txt, r, c, index,dynamicArray_compute, cellRangeFunction) { + isFunctionRange: function (txt, r, c, index, dynamicArray_compute, cellRangeFunction) { let _this = this; if (_this.operatorjson == null) { @@ -4521,11 +4521,11 @@ const luckysheetformula = { if (s == "(" && matchConfig.dquote == 0 && matchConfig.braces == 0) { if (str.length > 0 && bracket.length == 0) { str = str.toUpperCase(); - if(str.indexOf(":")>-1){ + if (str.indexOf(":") > -1) { let funcArray = str.split(":"); - function_str += "luckysheet_getSpecialReference(true,'"+ $.trim(funcArray[0]).replace(/'/g, "\\'") +"', luckysheet_function." + funcArray[1] + ".f(#lucky#"; + function_str += "luckysheet_getSpecialReference(true,'" + $.trim(funcArray[0]).replace(/'/g, "\\'") + "', luckysheet_function." + funcArray[1] + ".f(#lucky#"; } - else{ + else { function_str += "luckysheet_function." + str + ".f("; } bracket.push(1); @@ -4548,8 +4548,8 @@ const luckysheetformula = { // function_str += _this.isFunctionRange(str,r,c, index,dynamicArray_compute,cellRangeFunction) + ")"; // str = ""; - let functionS = _this.isFunctionRange(str,r,c, index,dynamicArray_compute,cellRangeFunction); - if(functionS.indexOf("#lucky#")>-1){ + let functionS = _this.isFunctionRange(str, r, c, index, dynamicArray_compute, cellRangeFunction); + if (functionS.indexOf("#lucky#") > -1) { functionS = functionS.replace(/#lucky#/g, "") + ")"; } function_str += functionS + ")"; @@ -4579,21 +4579,21 @@ const luckysheetformula = { } else if (s == "'") { str += "'"; - + if (matchConfig.squote > 0) { matchConfig.squote -= 1; - } + } else { matchConfig.squote += 1; } - } + } else if (s == ',' && matchConfig.dquote == 0 && matchConfig.braces == 0) { if (bracket.length <= 1) { // function_str += _this.isFunctionRange(str, r, c, index,dynamicArray_compute,cellRangeFunction) + ","; // str = ""; - let functionS = _this.isFunctionRange(str, r, c, index,dynamicArray_compute,cellRangeFunction); - if(functionS.indexOf("#lucky#")>-1){ + let functionS = _this.isFunctionRange(str, r, c, index, dynamicArray_compute, cellRangeFunction); + if (functionS.indexOf("#lucky#") > -1) { functionS = functionS.replace(/#lucky#/g, "") + ")"; } function_str += functionS + ","; @@ -4614,7 +4614,7 @@ const luckysheetformula = { if ((s + s_next) in _this.operatorjson) { if (bracket.length == 0) { if ($.trim(str).length > 0) { - cal2.unshift(_this.isFunctionRange($.trim(str), r, c, index,dynamicArray_compute,cellRangeFunction)); + cal2.unshift(_this.isFunctionRange($.trim(str), r, c, index, dynamicArray_compute, cellRangeFunction)); } else if ($.trim(function_str).length > 0) { cal2.unshift($.trim(function_str)); @@ -4643,7 +4643,7 @@ const luckysheetformula = { else { if (bracket.length == 0) { if ($.trim(str).length > 0) { - cal2.unshift(_this.isFunctionRange($.trim(str), r, c, index,dynamicArray_compute,cellRangeFunction)); + cal2.unshift(_this.isFunctionRange($.trim(str), r, c, index, dynamicArray_compute, cellRangeFunction)); } else if ($.trim(function_str).length > 0) { cal2.unshift($.trim(function_str)); @@ -4675,7 +4675,7 @@ const luckysheetformula = { } } else { - if (matchConfig.dquote == 0 && matchConfig.squote==0) { + if (matchConfig.dquote == 0 && matchConfig.squote == 0) { str += $.trim(s); } @@ -4687,15 +4687,15 @@ const luckysheetformula = { if (i == funcstack.length - 1) { let endstr = ""; let str_nb = $.trim(str).replace(/'/g, "\\'"); - if (_this.iscelldata(str_nb) && str_nb.substr(0,1)!=":") { + if (_this.iscelldata(str_nb) && str_nb.substr(0, 1) != ":") { // endstr = "luckysheet_getcelldata('" + $.trim(str) + "')"; - endstr = "luckysheet_getcelldata('" +str_nb + "')"; + endstr = "luckysheet_getcelldata('" + str_nb + "')"; _this.isFunctionRangeSaveChange(str, r, c, index, dynamicArray_compute); } - else if(str_nb.substr(0,1)==":"){ + else if (str_nb.substr(0, 1) == ":") { str_nb = str_nb.substr(1); - if(_this.iscelldata(str_nb)){ - endstr = "luckysheet_getSpecialReference(false," + function_str +",'"+ str_nb +"')"; + if (_this.iscelldata(str_nb)) { + endstr = "luckysheet_getSpecialReference(false," + function_str + ",'" + str_nb + "')"; } } else { @@ -4748,21 +4748,21 @@ const luckysheetformula = { i++; } // console.log(function_str); - _this.checkSpecialFunctionRange(function_str, r, c, index, dynamicArray_compute,cellRangeFunction); + _this.checkSpecialFunctionRange(function_str, r, c, index, dynamicArray_compute, cellRangeFunction); return function_str; }, isFunctionRangeSaveChange: function (str, r, c, index, dynamicArray_compute) { let _this = this; if (r != null && c != null) { let range = _this.getcellrange($.trim(str), index); - if(range==null){ + if (range == null) { return; } let row = range.row, col = range.column, sheetIndex = range.sheetIndex; - if ((r + "_" + c) in dynamicArray_compute && (index==sheetIndex || index==null)) { + if ((r + "_" + c) in dynamicArray_compute && (index == sheetIndex || index == null)) { let isd_range = false; for (let d_r = row[0]; d_r <= row[1]; d_r++) { @@ -4781,7 +4781,7 @@ const luckysheetformula = { } } else { - if (r >= row[0] && r <= row[1] && c >= col[0] && c <= col[1] && (index==sheetIndex || index==null)) { + if (r >= row[0] && r <= row[1] && c >= col[0] && c <= col[1] && (index == sheetIndex || index == null)) { _this.isFunctionRangeSave = _this.isFunctionRangeSave || true; } else { @@ -4802,10 +4802,10 @@ const luckysheetformula = { // } } }, - checkSpecialFunctionRange: function (function_str, r, c, index, dynamicArray_compute,cellRangeFunction) { - - if(function_str.substr(0, 30) =="luckysheet_getSpecialReference" || function_str.substr(0, 20) == "luckysheet_function."){ - if(function_str.substr(0, 20) == "luckysheet_function."){ + checkSpecialFunctionRange: function (function_str, r, c, index, dynamicArray_compute, cellRangeFunction) { + + if (function_str.substr(0, 30) == "luckysheet_getSpecialReference" || function_str.substr(0, 20) == "luckysheet_function.") { + if (function_str.substr(0, 20) == "luckysheet_function.") { let funcName = function_str.split(".")[1]; if (funcName != null) { funcName = funcName.toUpperCase(); @@ -4817,25 +4817,25 @@ const luckysheetformula = { try { Store.calculateSheetIndex = index; let str = new Function("return " + function_str)(); - - if(str instanceof Object && str.startCell!=null){ + + if (str instanceof Object && str.startCell != null) { str = str.startCell; } let str_nb = $.trim(str); // console.log(function_str, tempFunc,str, this.iscelldata(str_nb),this.isFunctionRangeSave,r,c); if (this.iscelldata(str_nb)) { - if(typeof(cellRangeFunction)=="function"){ + if (typeof (cellRangeFunction) == "function") { cellRangeFunction(str_nb); } // this.isFunctionRangeSaveChange(str, r, c, index, dynamicArray_compute); // console.log(function_str, str, this.isFunctionRangeSave,r,c); } } - catch{ + catch { } } - + // if (function_str.substr(0, 20) == "luckysheet_function.") { // let funcName = function_str.split(".")[1]; // if (funcName != null) { @@ -4844,11 +4844,11 @@ const luckysheetformula = { // let tempFunc = "luckysheet_indirect_check" + function_str.substr(30, function_str.length); // //tempFunc = tempFunc.replace(/luckysheet_getcelldata/g, "luckysheet_indirect_check_return"); - + // try { // Store.calculateSheetIndex = index; // let str = eval(tempFunc); - + // if(str instanceof Object && str.data!=null){ // str = str.data.v; // } @@ -4865,8 +4865,8 @@ const luckysheetformula = { // catch{ // } - - + + // } // else if (funcName == "OFFSET") { // let tempFunc = "luckysheet_offset_check" + function_str.substr(28, function_str.length); @@ -4900,77 +4900,77 @@ const luckysheetformula = { execvertex: {}, execFunctionGroupData: null, execFunctionExist: null, - formulaContainSheetList:{}, - formulaContainCellList:{}, - cellTextToIndexList:{}, - addToCellList:function(formulaTxt, cellstring){ - if(formulaTxt==null || formulaTxt.length==0|| cellstring==null || cellstring.length==0){ + formulaContainSheetList: {}, + formulaContainCellList: {}, + cellTextToIndexList: {}, + addToCellList: function (formulaTxt, cellstring) { + if (formulaTxt == null || formulaTxt.length == 0 || cellstring == null || cellstring.length == 0) { return; } - if(this.formulaContainCellList==null){ + if (this.formulaContainCellList == null) { this.formulaContainCellList = {}; } // formulaTxt = formulaTxt.toUpperCase(); - if(this.formulaContainCellList[formulaTxt]==null){ + if (this.formulaContainCellList[formulaTxt] == null) { this.formulaContainCellList[formulaTxt] = {}; } this.formulaContainCellList[formulaTxt][cellstring] = 1; }, - addToCellIndexList:function(txt, infoObj){ - if(txt==null || txt.length==0|| infoObj==null){ + addToCellIndexList: function (txt, infoObj) { + if (txt == null || txt.length == 0 || infoObj == null) { return; } - if(this.cellTextToIndexList==null){ + if (this.cellTextToIndexList == null) { this.cellTextToIndexList = {}; } - if(txt.indexOf("!")>-1){ + if (txt.indexOf("!") > -1) { txt = txt.replace(/\\'/g, "'"); this.cellTextToIndexList[txt] = infoObj; } - else{ - this.cellTextToIndexList[txt+"_"+infoObj.sheetIndex] = infoObj; + else { + this.cellTextToIndexList[txt + "_" + infoObj.sheetIndex] = infoObj; } // console.log(this.cellTextToIndexList); }, - addToSheetIndexList:function(formulaTxt, sheetIndex, obIndex){ - if(formulaTxt==null || formulaTxt.length==0){ + addToSheetIndexList: function (formulaTxt, sheetIndex, obIndex) { + if (formulaTxt == null || formulaTxt.length == 0) { return; } - if(sheetIndex==null || sheetIndex.length==0){ + if (sheetIndex == null || sheetIndex.length == 0) { sheetIndex = Store.currentSheetIndex; } - if(obIndex==null || obIndex.length==0){ + if (obIndex == null || obIndex.length == 0) { obIndex = ""; } - if(this.formulaContainSheetList==null){ + if (this.formulaContainSheetList == null) { this.formulaContainSheetList = {}; } - if(this.formulaContainSheetList[formulaTxt]==null){ + if (this.formulaContainSheetList[formulaTxt] == null) { this.formulaContainSheetList[formulaTxt] = {}; } this.formulaContainSheetList[formulaTxt][sheetIndex] = obIndex; }, - execFunctionGlobalData:{}, - execFunctionGroupForce:function(isForce){ - if(isForce){ - this.execFunctionGroup(undefined, undefined, undefined, undefined, undefined,true); + execFunctionGlobalData: {}, + execFunctionGroupForce: function (isForce) { + if (isForce) { + this.execFunctionGroup(undefined, undefined, undefined, undefined, undefined, true); } - else{ + else { this.execFunctionGroup(); } }, - execFunctionGroup: function(origin_r, origin_c, value, index, data, isForce=false) { + execFunctionGroup: function (origin_r, origin_c, value, index, data, isForce = false) { let _this = this; - + if (data == null) { data = Store.flowdata; } @@ -4988,12 +4988,12 @@ const luckysheetformula = { window.luckysheet_getSpecialReference = luckysheet_getSpecialReference; } - if(_this.execFunctionGlobalData==null){ + if (_this.execFunctionGlobalData == null) { _this.execFunctionGlobalData = {}; } // let luckysheetfile = getluckysheetfile(); // let dynamicArray_compute = luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["dynamicArray_compute"] == null ? {} : luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["dynamicArray_compute"]; - + if (index == null) { index = Store.currentSheetIndex; } @@ -5001,10 +5001,10 @@ const luckysheetformula = { if (value != null) { //此处setcellvalue 中this.execFunctionGroupData会保存想要更新的值,本函数结尾不要设为null,以备后续函数使用 // setcellvalue(origin_r, origin_c, _this.execFunctionGroupData, value); - let cellCache = [[{v:null}]]; + let cellCache = [[{ v: null }]]; setcellvalue(0, 0, cellCache, value); - _this.execFunctionGlobalData[origin_r+"_"+origin_c+"_"+index] = cellCache[0][0]; - + _this.execFunctionGlobalData[origin_r + "_" + origin_c + "_" + index] = cellCache[0][0]; + } //{ "r": r, "c": c, "index": index, "func": func} @@ -5013,7 +5013,7 @@ const luckysheetformula = { let sheets = getluckysheetfile(); let sheetData = {}; - for(let i=0;i{ + amc.forEach((item) => { func(item.key, item.r, item.c, item.sheetIndex); }); } - else{ + else { let functionArr = []; - for(let r=range.row[0];r<=range.row[1];r++){ - for(let c=range.column[0];c<=range.column[1];c++){ + for (let r = range.row[0]; r <= range.row[1]; r++) { + for (let c = range.column[0]; c <= range.column[1]; c++) { let key = "r" + r + "c" + c + "i" + range.sheetIndex; func(key, r, c, range.sheetIndex); - if((formulaObjects && key in formulaObjects) || (updateValueOjects && key in updateValueOjects) ){ + if ((formulaObjects && key in formulaObjects) || (updateValueOjects && key in updateValueOjects)) { functionArr.push({ - key:key, - r:r, - c:c, - sheetIndex:range.sheetIndex + key: key, + r: r, + c: c, + sheetIndex: range.sheetIndex }); } } } - if(formulaObjects || updateValueOjects){ + if (formulaObjects || updateValueOjects) { arrayMatchCache[cacheKey] = functionArr; } } } } - let existsChildFormulaMatch = {}, ii=0; + let existsChildFormulaMatch = {}, ii = 0; //创建公式缓存及其范围的缓存 // console.time("1"); - for(let i=0;i-1 || txt1.indexOf("OFFSET(")>-1 || txt1.indexOf("INDEX(")>-1; + let isOffsetFunc = txt1.indexOf("INDIRECT(") > -1 || txt1.indexOf("OFFSET(") > -1 || txt1.indexOf("INDEX(") > -1; let formulaArray = []; - if(isOffsetFunc){ - this.isFunctionRange(calc_funcStr, null, null, formulaCell.index, null, function(str_nb){ + if (isOffsetFunc) { + this.isFunctionRange(calc_funcStr, null, null, formulaCell.index, null, function (str_nb) { let range = _this.getcellrange($.trim(str_nb), formulaCell.index); - if(range!=null){ + if (range != null) { formulaArray.push(range); } }); } - else if(!(calc_funcStr.substr(0,2)=='="' && calc_funcStr.substr(calc_funcStr.length-1,1)=='"')){ + else if (!(calc_funcStr.substr(0, 2) == '="' && calc_funcStr.substr(calc_funcStr.length - 1, 1) == '"')) { let formulaTextArray = calc_funcStr.split(/==|!=|<>|<=|>=|[,()=+-\/*%&^><]/g); - - for(let i=0;i{ + Object.keys(formulaObjects).forEach((key) => { let formulaObject = formulaObjects[key]; - arrayMatch(formulaObject.formulaArray, formulaObjects, updateValueOjects, function(childKey){ - if(childKey in formulaObjects){ + arrayMatch(formulaObject.formulaArray, formulaObjects, updateValueOjects, function (childKey) { + if (childKey in formulaObjects) { let childFormulaObject = formulaObjects[childKey]; formulaObject.chidren[childKey] = 1; childFormulaObject.parents[key] = 1; } // console.log(childKey,formulaObject.formulaArray); - if(!isForce && childKey in updateValueOjects){ + if (!isForce && childKey in updateValueOjects) { updateValueArray.push(formulaObject); } - }); + }); - if(isForce){ + if (isForce) { updateValueArray.push(formulaObject); } }); @@ -5177,39 +5177,39 @@ const luckysheetformula = { // updateValueArray.forEach((key)=>{ // let formulaObject = formulaObjects[key]; - + // }); - let stack = updateValueArray, existsFormulaRunList={}; - while(stack.length>0){ + let stack = updateValueArray, existsFormulaRunList = {}; + while (stack.length > 0) { let formulaObject = stack.pop(); - if(formulaObject==null || formulaObject.key in existsFormulaRunList){ + if (formulaObject == null || formulaObject.key in existsFormulaRunList) { continue; } - if(formulaObject.color == "b"){ + if (formulaObject.color == "b") { formulaRunList.push(formulaObject); existsFormulaRunList[formulaObject.key] = 1; continue; } let cacheStack = []; - Object.keys(formulaObject.parents).forEach((parentKey)=>{ + Object.keys(formulaObject.parents).forEach((parentKey) => { let parentFormulaObject = formulaObjects[parentKey]; - if(parentFormulaObject!=null){ + if (parentFormulaObject != null) { cacheStack.push(parentFormulaObject); } }); - + ii++; - if(cacheStack.length==0){ + if (cacheStack.length == 0) { formulaRunList.push(formulaObject); existsFormulaRunList[formulaObject.key] = 1; } - else{ + else { formulaObject.color = "b"; stack.push(formulaObject); stack = stack.concat(cacheStack); @@ -5222,14 +5222,14 @@ const luckysheetformula = { // console.timeEnd("3"); // console.time("4"); - for(let i=0;i 0) { let u = stack.shift(); - let excludeList = {}; + let excludeList = {}; _this.getChildrenVertex(u, vertex1, excludeList); // ii++; // console.log(JSON.stringify(excludeList)); for (let name in vertex1) { let item = vertex1[name]; - if(item==null){ + if (item == null) { continue; } - let ukey ="r" + u.r + "c" + u.c + "i" + u.index; + let ukey = "r" + u.r + "c" + u.c + "i" + u.index; // if ((u.r == item.r && u.c == item.c && u.index == item.index) ) { // continue; // } - if(name in excludeList){ + if (name in excludeList) { continue; } _this.isFunctionRangeSave = false; - - - let calc_funcStr = getcellFormula(item.r, item.c, item.index); + + + let calc_funcStr = getcellFormula(item.r, item.c, item.index); _this.isFunctionRangeSelect(calc_funcStr, u.r, u.c, u.index, dynamicArray_compute); // iii++; - + if (_this.isFunctionRangeSave) { if (!(name in _this.execvertex)) { // console.log(JSON.stringify(item), JSON.stringify(u), _this.isFunctionRangeSave); @@ -5438,7 +5438,7 @@ const luckysheetformula = { if (u.color == "w") { _this.functionDFS(u); - } + } else if (u.color == "b") { i++; } @@ -5449,19 +5449,19 @@ const luckysheetformula = { _this.execFunctionExist = null; }, //递归得到引用节点 - getChildrenVertex:function(u, vertex1, obj){ - let ukey ="r" + u.r + "c" + u.c + "i" + u.index; + getChildrenVertex: function (u, vertex1, obj) { + let ukey = "r" + u.r + "c" + u.c + "i" + u.index; obj[ukey] = 1; - if(u.chidren !=null){ - for(let key in u.chidren){ - if(vertex1[key] && !(key in obj) ){ + if (u.chidren != null) { + for (let key in u.chidren) { + if (vertex1[key] && !(key in obj)) { this.getChildrenVertex(vertex1[key], vertex1, obj); - } + } } } }, //深度优先算法,处理多级调用函数 - functionDFS: function(u) { + functionDFS: function (u) { let _this = this; u.color = "g"; u.times += 1; @@ -5475,7 +5475,7 @@ const luckysheetformula = { u.color = "b"; window.luckysheet_getcelldata_cache = null; - let calc_funcStr = getcellFormula(u.r, u.c, u.index); + let calc_funcStr = getcellFormula(u.r, u.c, u.index); let v = _this.execfunction(calc_funcStr, u.r, u.c, u.index); @@ -5496,7 +5496,7 @@ const luckysheetformula = { // window.luckysheetCurrentColumn = u.c; // window.luckysheetCurrentIndex = u.index; // window.luckysheetCurrentFunction = calc_funcStr; - + // let fp = $.trim(_this.functionParserExe(calc_funcStr)); // let sparklines = eval(fp); // spl = sparklines; @@ -5508,21 +5508,21 @@ const luckysheetformula = { "c": u.c, "v": v[1], "f": v[2], - "spe":v[3], + "spe": v[3], "index": u.index }); // _this.execFunctionGroupData[u.r][u.c] = value; - _this.execFunctionGlobalData[u.r+"_"+u.c+"_"+u.index] = { - v:v[1], - f:v[2] + _this.execFunctionGlobalData[u.r + "_" + u.c + "_" + u.index] = { + v: v[1], + f: v[2] }; }, groupValuesRefreshData: [], - groupValuesRefresh: function() { + groupValuesRefresh: function () { let _this = this; let luckysheetfile = getluckysheetfile(); - if(_this.groupValuesRefreshData.length > 0){ + if (_this.groupValuesRefreshData.length > 0) { for (let i = 0; i < _this.groupValuesRefreshData.length; i++) { let item = _this.groupValuesRefreshData[i]; @@ -5532,16 +5532,16 @@ const luckysheetformula = { let file = luckysheetfile[getSheetIndex(item.index)]; let data = file.data; - if(data==null){ + if (data == null) { continue; } let updateValue = {}; - if(item.spe!=null){ - if(item.spe.type=="sparklines"){ + if (item.spe != null) { + if (item.spe.type == "sparklines") { updateValue.spl = item.spe.data; } - else if(item.spe.type=="dynamicArrayItem"){ + else if (item.spe.type == "dynamicArrayItem") { file.dynamicArray = _this.insertUpdateDynamicArray(item.spe.data); } } @@ -5558,14 +5558,14 @@ const luckysheetformula = { _this.groupValuesRefreshData = []; } }, - delFunctionGroup: function(r, c, index) { + delFunctionGroup: function (r, c, index) { if (index == null) { index = Store.currentSheetIndex; } let luckysheetfile = getluckysheetfile(); let file = luckysheetfile[getSheetIndex(index)]; - + let calcChain = file.calcChain; if (calcChain != null) { for (let i = 0; i < calcChain.length; i++) { @@ -5585,7 +5585,7 @@ const luckysheetformula = { if (dynamicArray != null) { for (let i = 0; i < dynamicArray.length; i++) { let calc = dynamicArray[i]; - if (calc.r == r && calc.c == c && (calc.index==null || calc.index == index)) { + if (calc.r == r && calc.c == c && (calc.index == null || calc.index == index)) { dynamicArray.splice(i, 1); server.saveParam("ac", index, null, { "op": "del", @@ -5598,21 +5598,21 @@ const luckysheetformula = { setluckysheetfile(luckysheetfile); }, - execfunction: function(txt, r, c, index, isrefresh, notInsertFunc) { + execfunction: function (txt, r, c, index, isrefresh, notInsertFunc) { let _this = this; let _locale = locale(); let locale_formulaMore = _locale.formulaMore; // console.log(txt,r,c) - if(txt.indexOf(_this.error.r) > -1){ + if (txt.indexOf(_this.error.r) > -1) { return [false, _this.error.r, txt]; } if (!_this.checkBracketNum(txt)) { txt += ")"; - } - - if(index==null){ + } + + if (index == null) { index = Store.currentSheetIndex; } @@ -5620,12 +5620,12 @@ const luckysheetformula = { let fp = $.trim(_this.functionParserExe(txt)); console.log(fp) - if ((fp.substr(0, 20) == "luckysheet_function." || fp.substr(0, 22) == "luckysheet_compareWith") ) { + if ((fp.substr(0, 20) == "luckysheet_function." || fp.substr(0, 22) == "luckysheet_compareWith")) { _this.functionHTMLIndex = 0; } if (!_this.testFunction(txt, fp) || fp == "") { - tooltip.info("",locale_formulaMore.execfunctionError); + tooltip.info("", locale_formulaMore.execfunctionError); return [false, _this.error.n, txt]; } @@ -5640,24 +5640,24 @@ const luckysheetformula = { let sparklines = null; try { - if(fp.indexOf("luckysheet_getcelldata") > -1){ + if (fp.indexOf("luckysheet_getcelldata") > -1) { let funcg = fp.split("luckysheet_getcelldata('"); - for(let i = 1; i < funcg.length; i++){ + for (let i = 1; i < funcg.length; i++) { let funcgStr = funcg[i].split("')")[0]; let funcgRange = _this.getcellrange(funcgStr); - if(funcgRange.row[0] < 0 || funcgRange.column[0] < 0){ + if (funcgRange.row[0] < 0 || funcgRange.column[0] < 0) { return [true, _this.error.r, txt]; } - if(funcgRange.sheetIndex == Store.calculateSheetIndex && r >= funcgRange.row[0] && r <= funcgRange.row[1] && c >= funcgRange.column[0] && c <= funcgRange.column[1]){ - if(isEditMode()){ + if (funcgRange.sheetIndex == Store.calculateSheetIndex && r >= funcgRange.row[0] && r <= funcgRange.row[1] && c >= funcgRange.column[0] && c <= funcgRange.column[1]) { + if (isEditMode()) { alert(locale_formulaMore.execfunctionSelfError); } - else{ + else { tooltip.info("", locale_formulaMore.execfunctionSelfErrorResult); - + } return [false, 0, txt]; @@ -5668,29 +5668,29 @@ const luckysheetformula = { result = new Function("return " + fp)(); //加入sparklines的参数项目 - if(fp.indexOf("SPLINES") > -1){ + if (fp.indexOf("SPLINES") > -1) { sparklines = result; result = ""; } - } + } catch (e) { let err = e; //err错误提示处理 - console.log(e,fp); + console.log(e, fp); err = _this.errorInfo(err); result = [_this.error.n, err]; } //公式结果是对象,则表示只是选区。如果是单个单元格,则返回其值;如果是多个单元格,则返回 #VALUE!。 - if(getObjType(result) == "object" && result.startCell != null){ - if(getObjType(result.data) == "array"){ + if (getObjType(result) == "object" && result.startCell != null) { + if (getObjType(result.data) == "array") { result = _this.error.v; } - else{ - if(getObjType(result.data)=="object" && !isRealNull(result.data.v)){ + else { + if (getObjType(result.data) == "object" && !isRealNull(result.data.v)) { result = result.data.v; } - else if(!isRealNull(result.data)){ + else if (!isRealNull(result.data)) { result = result.data; } else { @@ -5702,23 +5702,23 @@ const luckysheetformula = { //公式结果是数组,分错误值 和 动态数组 两种情况 let dynamicArrayItem = null; - if(getObjType(result) == "array"){ - let isErr = false; + if (getObjType(result) == "array") { + let isErr = false; - if(getObjType(result[0]) != "array" && result.length == 2){ + if (getObjType(result[0]) != "array" && result.length == 2) { isErr = valueIsError(result[0]); } - if(!isErr){ - if(getObjType(result[0]) == "array" && result.length == 1 && result[0].length == 1){ + if (!isErr) { + if (getObjType(result[0]) == "array" && result.length == 1 && result[0].length == 1) { result = result[0][0]; } - else{ - dynamicArrayItem = {"r": r, "c": c, "f": txt, "index":index,"data": result}; + else { + dynamicArrayItem = { "r": r, "c": c, "f": txt, "index": index, "data": result }; result = ""; } } - else{ + else { result = result[0]; } } @@ -5733,27 +5733,27 @@ const luckysheetformula = { _this.execFunctionGroup(r, c, result, index); } - if(!notInsertFunc){ + if (!notInsertFunc) { _this.insertUpdateFunctionGroup(r, c, index); } } - if(!!sparklines){ - return [true, result, txt, {type: "sparklines", data: sparklines}]; + if (!!sparklines) { + return [true, result, txt, { type: "sparklines", data: sparklines }]; } - if(!!dynamicArrayItem){ - return [true, result, txt, {type: "dynamicArrayItem", data: dynamicArrayItem}]; + if (!!dynamicArrayItem) { + return [true, result, txt, { type: "dynamicArrayItem", data: dynamicArrayItem }]; } // console.log(result, txt); return [true, result, txt]; }, - testFunction: function(txt, fp) { + testFunction: function (txt, fp) { if (txt.substr(0, 1) == "=") { return true; - } + } else { return false; } diff --git a/src/index.html b/src/index.html index 7f2c8ca..d463da7 100644 --- a/src/index.html +++ b/src/index.html @@ -127,7 +127,7 @@ // console.info(data,sheetFile,ctx) }, updated:function(operate){ - console.info(operate) + // console.info(operate) }, cellUpdateBefore:function(r,c,value,isRefresh){ // console.info('cellUpdateBefore',r,c,value,isRefresh)