本帖最后由 高阳0910 于 2022-11-2 15:17 编辑
今天有尝试改了一下。
修改了设置单元格 必须输入手机号的 数据验证。
reExFunction.js
import * as GC from '@grapecity/spread-sheets'
function RegExFunction (reg) {
if (reg.substring(0, 1) === '/') {
reg = reg.substring(1, reg.length)
}
if (reg.substring(reg.length - 1, reg.length) === '/') {
reg = reg.substring(0, reg.length - 1)
}
this.reg = reg;
}
RegExFunction.prototype = new GC.Spread.Sheets.ConditionalFormatting.Condition();
RegExFunction.prototype.evaluate = function (evaluator, baseRow, baseColumn, actualObj) {
debugger
var reg = new RegExp(this.reg);
if (reg.test(actualObj)) {
return true;
} else {
return false;
}
};
export default RegExFunction
设置单元格的方式
const sheet = spread.getActiveSheet()
let nCondition = new RegExFunction('/^1[3456789]\d{9}$/');
let dv8 = new GC.Spread.Sheets.DataValidation.DefaultDataValidator(nCondition);
dv8.type(GC.Spread.Sheets.DataValidation.CriteriaType.custom);
dv8.inputTitle('手机号码')
dv8.inputMessage('格式必须为手机号码!')
dv8.ignoreBlank(false)
sheet.setFormatter(rowIndex, columnIndex, '@')
sheet.getCell(rowIndex, columnIndex).validator(dv8)
设置以后 手动验证一下 输入1 会提示,输入13112345678 不会提示。
然后使用 localStorage.setItem('spreadJson', JSON.stringify(this.spread.toJSON())) 放到内存中
再另一个vue页面使用 this.spread.fromJSON( JSON.parse(localStorage.getItem('spreadJson')))
在新页面再次验证 ,不论输入什么都会提示错误。
这是toJSON以后的 数据
{
"version": "15.1.2",
"sheetCount": 1,
"allowExtendPasteRange": true,
"customList": [],
"sheets": {
"Sheet1": {
"name": "Sheet1",
"isSelected": true,
"activeRow": 1,
"activeCol": 1,
"visible": 1,
"frozenTrailingRowStickToEdge": true,
"frozenTrailingColumnStickToEdge": true,
"theme": "Office",
"data": {
"dataTable": {
"1": {
"1": {
"style": {
"backColor": "rgba(250, 205, 145, 1)",
"formatter": "@",
"borderLeft": {
"style": 1
},
"borderTop": {
"style": 1
},
"borderRight": {
"style": 1
},
"borderBottom": {
"style": 1
}
},
"bindingPath": "Sheet1_B2"
}
}
},
"defaultDataNode": {
"style": {
"themeFont": "Body"
}
}
},
"rowHeaderData": {
"defaultDataNode": {
"style": {
"themeFont": "Body"
}
}
},
"colHeaderData": {
"defaultDataNode": {
"style": {
"themeFont": "Body"
}
}
},
"leftCellIndex": 0,
"topCellIndex": 0,
"selections": {
"0": {
"row": 1,
"rowCount": 1,
"col": 1,
"colCount": 1
},
"length": 1
},
"rowOutlines": {
"items": []
},
"columnOutlines": {
"items": []
},
"validations": [
{
"ignoreBlank": false,
"inputTitle": "手机号码",
"inputMessage": "格式必须为手机号码!",
"type": 7,
"condition": {
"ranges": [
{
"row": 1,
"rowCount": 1,
"col": 1,
"colCount": 1
}
]
},
"ranges": "B2",
"highlightStyle": "{\"type\":0,\"color\":\"red\"}"
}
],
"cellStates": {},
"states": {},
"outlineColumnOptions": {},
"autoMergeRangeInfos": [],
"shapeCollectionOption": {
"snapMode": 0
},
"printInfo": {
"paperSize": {
"width": 850,
"height": 1100,
"kind": 1
}
},
"index": 0
}
},
"sheetTabCount": 0
}
|