Skip to content

Commit

Permalink
feat: setRangeConditionalFormatDefault方法支持正则表达式
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxi.wang committed Dec 22, 2022
1 parent 3de403a commit deb0ec0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/controllers/conditionformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
13 changes: 13 additions & 0 deletions src/demoData/sheetConditionFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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": [{
Expand Down
6 changes: 5 additions & 1 deletion src/global/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3657,7 +3657,8 @@ export function setRangeConditionalFormatDefault(conditionName, conditionValue,
'last10',
'last10%',
'AboveAverage',
'SubAverage'
'SubAverage',
'regExp',
];

if(!conditionName || !conditionNameValues.includes(conditionName)){
Expand Down Expand Up @@ -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.', '');
Expand Down

0 comments on commit deb0ec0

Please sign in to comment.