diff --git a/src/controllers/conditionformat.js b/src/controllers/conditionformat.js index 599babb..90f9e15 100644 --- a/src/controllers/conditionformat.js +++ b/src/controllers/conditionformat.js @@ -43,6 +43,10 @@ const conditionformat = { ${conditionformat_Text.ruleTypeItem5} +
+ + ${conditionformat_Text.ruleTypeItem6} +
`; }, textCellColorHtml: function(){ @@ -510,6 +514,19 @@ const conditionformat = { conditionName = "duplicateValue"; conditionValue.push(type1); } + else if(index == 5){ //公式 + conditionName = "formula"; + + //条件值 + let v = $("#luckysheet-newConditionRule-dialog #formulaConditionVal input").val().trim(); + + if(v == ""){ + _this.infoDialog("Condition value cannot be empty!", ""); + return; + } + + conditionValue.push(v); + } //格式颜色 let textcolor; @@ -882,6 +899,19 @@ const conditionformat = { conditionName = "duplicateValue"; conditionValue.push(type1); } + else if(index == 5){ //公式 + conditionName = "formula"; + + //条件值 + let v = $("#luckysheet-editorConditionRule-dialog #formulaConditionVal input").val().trim(); + console.log(v) + if(v == ""){ + _this.infoDialog("Condition value cannot be empty!", ""); + return; + } + + conditionValue.push(v); + } //格式颜色 let textcolor; @@ -1232,8 +1262,11 @@ const conditionformat = { $("#" + id).hide(); //入口 let source; + if(id == "luckysheet-conditionformat-dialog"){ - if($(this).siblings("input").attr("id") == "conditionVal"){ + let $id = $(this).siblings("input").attr("id"); + + if($id == "conditionVal"){ source = "0_1"; } else{ @@ -1241,7 +1274,12 @@ const conditionformat = { } } else if(id == "luckysheet-newConditionRule-dialog"){ - if($(this).parents(".range").attr("id") == "conditionVal"){ + let $id = $(this).parents(".range").attr("id"); + + if($id == "formulaConditionVal"){ + source = "1_0"; + } + else if($id == "conditionVal"){ source = "1_1"; } else{ @@ -1249,7 +1287,12 @@ const conditionformat = { } } else if(id == "luckysheet-editorConditionRule-dialog"){ - if($(this).parents(".range").attr("id") == "conditionVal"){ + let $id = $(this).parents(".range").attr("id"); + + if($id == "formulaConditionVal"){ + source = "2_0"; + } + else if($id == "conditionVal"){ source = "2_1"; } else{ @@ -1277,6 +1320,10 @@ const conditionformat = { $("#luckysheet-conditionformat-dialog").show(); $("#luckysheet-conditionformat-dialog #conditionVal2").val(v); } + else if(source == "1_0"){ + $("#luckysheet-newConditionRule-dialog").show(); + $("#luckysheet-newConditionRule-dialog #formulaConditionVal input").val(v); + } else if(source == "1_1"){ $("#luckysheet-newConditionRule-dialog").show(); $("#luckysheet-newConditionRule-dialog #conditionVal input").val(v); @@ -1285,6 +1332,10 @@ const conditionformat = { $("#luckysheet-newConditionRule-dialog").show(); $("#luckysheet-newConditionRule-dialog #conditionVal2 input").val(v); } + else if(source == "2_0"){ + $("#luckysheet-editorConditionRule-dialog").show(); + $("#luckysheet-editorConditionRule-dialog #formulaConditionVal input").val(v); + } else if(source == "2_1"){ $("#luckysheet-editorConditionRule-dialog").show(); $("#luckysheet-editorConditionRule-dialog #conditionVal input").val(v); @@ -1305,10 +1356,10 @@ const conditionformat = { if(source == "0_1" || source == "0_2"){ $("#luckysheet-conditionformat-dialog").show(); } - else if(source == "1_1" || source == "1_2"){ + else if(source == "1_0" || source == "1_1" || source == "1_2"){ $("#luckysheet-newConditionRule-dialog").show(); } - else if(source == "2_1" || source == "2_2"){ + else if(source == "2_0" || source == "2_1" || source == "2_2"){ $("#luckysheet-editorConditionRule-dialog").show(); } @@ -1909,6 +1960,13 @@ const conditionformat = { else if(conditionName == "SubAverage"){ return conditionformat_Text.belowAverage; } + else if(conditionName == "formula"){ + if(v.slice(0, 1) != '='){ + v = '=' + v; + } + + return conditionformat_Text.formula + ': ' + v; + } }, newConditionRuleDialog: function(source){ let _this = this; @@ -2011,6 +2069,9 @@ const conditionformat = { index = 4; type1 = rule["conditionValue"]; } + else if(conditionName == "formula"){ + index = 5; + } } //规则说明 @@ -2174,6 +2235,12 @@ const conditionformat = { $("#luckysheet-editorConditionRule-dialog #isPercent").attr("checked", "checked"); } } + else{ + if(conditionName == "formula"){ + let val1 = rule.conditionValue[0]; + $("#luckysheet-editorConditionRule-dialog #formulaConditionVal input").val(val1); + } + } $("#luckysheet-editorConditionRule-dialog #textcolorshow").spectrum("set", ruleFormat.textColor); $("#luckysheet-editorConditionRule-dialog #cellcolorshow").spectrum("set", ruleFormat.cellColor); @@ -2367,6 +2434,16 @@ const conditionformat = {
${conditionformat_Text.setFormat}:
${textCellColorHtml}`; break; + case 5: //使用公式确定要设置格式的单元格 + ruleExplainHtml = `
${conditionformat_Text.ruleTypeItem2_title}:
+
+
+ + +
+
+
${conditionformat_Text.setFormat}:
${textCellColorHtml}`; + break; } return ruleExplainHtml; @@ -3640,6 +3717,52 @@ const conditionformat = { } } } + else if(conditionName == "formula"){ + let str = cellrange[s].row[0], + edr = cellrange[s].row[1], + stc = cellrange[s].column[0], + edc = cellrange[s].column[1]; + + let formulaTxt = conditionValue0; + if(conditionValue0.toString().slice(0, 1) != '='){ + formulaTxt = '=' + conditionValue0; + } + + for(let r = str; r <= edr; r++){ + for(let c = stc; c <= edc; c++){ + let func = formulaTxt; + let offsetRow = r - str; + let offsetCol = c - stc; + + if(offsetRow > 0){ + func = "=" + formula.functionCopy(func, "down", offsetRow); + } + + if(offsetCol > 0){ + func = "=" + formula.functionCopy(func, "right", offsetCol); + } + + let funcV = formula.execfunction(func); + let v = funcV[1]; + + if(typeof v != 'boolean'){ + v = !!Number(v); + } + + if(!v){ + continue; + } + + if((r + "_" + c) in computeMap){ + computeMap[r + "_" + c]["textColor"] = textColor; + computeMap[r + "_" + c]["cellColor"] = cellColor; + } + else{ + computeMap[r + "_" + c] = { "textColor": textColor, "cellColor": cellColor }; + } + } + } + } } } } diff --git a/src/global/formula.js b/src/global/formula.js index e1a7b58..40befb2 100644 --- a/src/global/formula.js +++ b/src/global/formula.js @@ -1214,7 +1214,7 @@ const luckysheetformula = { $("#luckysheet-formula-search-c, #luckysheet-formula-help-c").hide(); _this.helpFunctionExe($editer, currSelection); - console.log(currSelection, $(currSelection).closest(".luckysheet-formula-functionrange-cell").length); + // console.log(currSelection, $(currSelection).closest(".luckysheet-formula-functionrange-cell").length); if ($(currSelection).closest(".luckysheet-formula-functionrange-cell").length == 0) { _this.searchFunction($editer); return; @@ -5619,7 +5619,7 @@ const luckysheetformula = { Store.calculateSheetIndex = index; let fp = $.trim(_this.functionParserExe(txt)); - + console.log(fp) if ((fp.substr(0, 20) == "luckysheet_function." || fp.substr(0, 22) == "luckysheet_compareWith") ) { _this.functionHTMLIndex = 0; } diff --git a/src/locale/en.js b/src/locale/en.js index 77fe87c..b98a194 100644 --- a/src/locale/en.js +++ b/src/locale/en.js @@ -9591,6 +9591,8 @@ export default { ruleTypeItem4: 'Format only values above or below the average', ruleTypeItem4_title: 'Is a value that satisfies the following conditions', ruleTypeItem5: 'Format only unique or repeated values', + ruleTypeItem6: 'Use formulas to determine which cells to format', + formula: 'Formula', textColor: 'Text color', cellColor: 'Cell color', confirm: 'Confirm', diff --git a/src/locale/es.js b/src/locale/es.js index 4ee78b2..0d5b8cf 100644 --- a/src/locale/es.js +++ b/src/locale/es.js @@ -9589,6 +9589,8 @@ export default { ruleTypeItem4: 'Aplicar formato solo a los valores superiores o inferiores al promedio', ruleTypeItem4_title: 'Es un valor que cumple las siguientes condiciones', ruleTypeItem5: 'Aplicar formato solo a valores únicos o repetidos', + ruleTypeItem6: 'Use fórmulas para determinar qué celdas formatear', + formula: 'fórmula', textColor: 'Color Texto', cellColor: 'Color Celda', confirm: 'Confirma', diff --git a/src/locale/zh.js b/src/locale/zh.js index 55270ea..65612e5 100644 --- a/src/locale/zh.js +++ b/src/locale/zh.js @@ -9833,6 +9833,8 @@ export default { ruleTypeItem4: '仅对高于或低于平均值的数值设置格式', ruleTypeItem4_title: '为满足以下条件的值', ruleTypeItem5: '仅对唯一值或重复值设置格式', + ruleTypeItem6: '使用公式确定要设置格式的单元格', + formula: '公式', textColor: '文本颜色', cellColor: '单元格颜色', confirm: '确定', diff --git a/src/locale/zh_tw.js b/src/locale/zh_tw.js index bec4596..55515bf 100644 --- a/src/locale/zh_tw.js +++ b/src/locale/zh_tw.js @@ -9826,6 +9826,8 @@ export default { ruleTypeItem4 : '僅對高於或低於平均值的數值設定格式', ruleTypeItem4_title : '為滿足以下條件的值', ruleTypeItem5 : '僅對唯一值或重複值設定格式', + ruleTypeItem6 : '使用公式確定要設置格式的單元格', + formula : '公式', textColor : '文字顏色', cellColor : '儲存格顏色', confirm : '確定',