如上面动图,在我插入几行的时候这行还是有校验的,删掉之后 它就消失了
- import GC from '@grapecity/spread-sheets'
- export default function setDataValidation(title, activeSheet) {
- let fieldType = title.fieldType
- let limitSize = 0
- if (fieldType.includes('varchar')) {
- limitSize = fieldType.match(/\d+/) ? fieldType.match(/\d+/)[0] : 0
- fieldType = 'varchar'
- }
- if (title.fieldCode.includes('amount')) {
- //金额
- fieldType = 'number'
- }
- if (title.fieldSelectionRange) {
- fieldType = 'list'
- }
- switch (fieldType) {
- case 'date':
- var dv = GC.Spread.Sheets.DataValidation.createDateValidator(GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.lessThan, new Date(3000, 1, 1));
- dv.showInputMessage(true);
- dv.inputMessage("请输入日期格式");
- dv.inputTitle("提示");
- activeSheet.getCell(-1, title.fieldSort - 1).validator(dv);
- activeSheet.getCell(0, title.fieldSort - 1).validator(null);
- activeSheet.setFormatter(-1, title.fieldSort - 1, 'yyyy-mm-dd');
- break;
- case 'number':
- var dv = GC.Spread.Sheets.DataValidation.createNumberValidator(GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.lessThan, "9999999999999", false);
- dv.showInputMessage(true);
- dv.inputMessage("请输入数字");
- dv.inputTitle("提示");
- activeSheet.getCell(-1, title.fieldSort - 1).validator(dv);
- activeSheet.getCell(0, title.fieldSort - 1).validator(null);
- break;
- case 'list':
- let listStr = ''
- if (typeof title.fieldSelectionRange[0] == 'object') {
- listStr = title.fieldSelectionRange.map((item) => item.value || item.name).join(',')
- } else {
- listStr = title.fieldSelectionRange.join(',')
- }
- var dv = new GC.Spread.Sheets.DataValidation.createFormulaListValidator(`TEXTSPLIT("${listStr}",,",")`);
- dv.highlightStyle({
- color: 'red',
- type: GC.Spread.Sheets.DataValidation.HighlightType.dogEar,
- position: GC.Spread.Sheets.DataValidation.HighlightPosition.topLeft
- });
- dv.showInputMessage(true);
- dv.inputMessage("必须是范围内的值");
- dv.inputTitle("提示");
- activeSheet.getCell(-1, title.fieldSort - 1).validator(dv);
- activeSheet.getCell(0, title.fieldSort - 1).validator(null);
- break;
- default:
- break;
- }
- }
复制代码 这是我设置校验规则的函数,第一行是标题,所以设置了第一行的校验为空,
|
|