From deb0ec0d41449caf22d6bfad4185be1847c45b68 Mon Sep 17 00:00:00 2001 From: "yaoxi.wang" Date: Tue, 20 Dec 2022 18:25:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20setRangeConditionalFormatDefault?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E6=94=AF=E6=8C=81=E6=AD=A3=E5=88=99=E8=A1=A8?= =?UTF-8?q?=E8=BE=BE=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/conditionformat.js | 27 +++++++++++++++++++++++++++ src/demoData/sheetConditionFormat.js | 13 +++++++++++++ src/global/api.js | 6 +++++- 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/controllers/conditionformat.js b/src/controllers/conditionformat.js index 90f9e1511..c4347b518 100644 --- a/src/controllers/conditionformat.js +++ b/src/controllers/conditionformat.js @@ -3717,6 +3717,33 @@ const conditionformat = { } } } + else if (conditionName == 'regExp') { // 支持正则 + let re = new RegExp(conditionValue0); // 外部传递过来的正则表达式 + for (let r = cellrange[s].row[0]; r <= cellrange[s].row[1]; r++) { + for (let c = cellrange[s].column[0]; c <= cellrange[s].column[1]; c++) { + if (d[r] == null || d[r][c] == null) { + continue; + } + + //单元格值 + let cell = d[r][c]; + + if (getObjType(cell) != "object" || isRealNull(cell.v)) { + continue; + } + + // 符合条件 + if (re.test(cell.v)) { + if ((r + "_" + c) in computeMap) { + computeMap[r + "_" + c]["textColor"] = textColor; + computeMap[r + "_" + c]["cellColor"] = cellColor; + } else { + computeMap[r + "_" + c] = {"textColor": textColor, "cellColor": cellColor}; + } + } + } + } + } else if(conditionName == "formula"){ let str = cellrange[s].row[0], edr = cellrange[s].row[1], diff --git a/src/demoData/sheetConditionFormat.js b/src/demoData/sheetConditionFormat.js index e91f9b810..64083e008 100644 --- a/src/demoData/sheetConditionFormat.js +++ b/src/demoData/sheetConditionFormat.js @@ -6450,6 +6450,19 @@ window.sheetConditionFormat = { "conditionName": "occurrenceDate", "conditionRange": [], "conditionValue": ["2020/07/23 - 2020/07/29"] + },{ + "type": "default", + "cellrange": [{ + "row": [0, 30], + "column": [0, 0] + }], + "format": { + "textColor": "#000000", + "cellColor": "#ff0000" + }, + "conditionName": "regExp", + "conditionRange": [], + "conditionValue": [/^\d{1,}\.\d{1,}$/] }, { "type": "colorGradation", "cellrange": [{ diff --git a/src/global/api.js b/src/global/api.js index 60d0c9d11..3523c834d 100644 --- a/src/global/api.js +++ b/src/global/api.js @@ -3657,7 +3657,8 @@ export function setRangeConditionalFormatDefault(conditionName, conditionValue, 'last10', 'last10%', 'AboveAverage', - 'SubAverage' + 'SubAverage', + 'regExp', ]; if(!conditionName || !conditionNameValues.includes(conditionName)){ @@ -3868,6 +3869,9 @@ export function setRangeConditionalFormatDefault(conditionName, conditionValue, else if(conditionName == 'AboveAverage' || conditionName == 'SubAverage'){ conditionValue2.push(conditionName); } + else if(conditionName == 'regExp') { + conditionValue2.push(...conditionValue); + } if(!format.hasOwnProperty("textColor") || !format.hasOwnProperty("cellColor")){ return tooltip.info('The format parameter is invalid.', '');