您好,这个问题需要您自定义一个Condition,在Condition的evaluate 中去写您的验证逻辑,该方法最后只需要return true/false;
下面代码您参考一下:
- var ns = GC.Spread.Sheets;
-
- function RegExCondition(expected) {
- ns.ConditionalFormatting.Condition.call(this, ns.ConditionalFormatting.TextCompareType.EqualsTo, {expected: expected});
- }
- RegExCondition.prototype = new ns.ConditionalFormatting.Condition(ns.ConditionalFormatting.ConditionType.TextCondition);
- RegExCondition.prototype.evaluate = function (evaluator, baseRow, baseColumn, actualObj) {
- var reg = new RegExp(this.expected());
- if (actualObj) {
- return reg.test(actualObj.toString());
- }
- }
- $(document).ready(function () {
- var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'), {sheetCount: 3});
- var sheet = spread.getActiveSheet();
- var condition = new RegExCondition("(?:&|<|>|"|\'|`)");
- var validator = new ns.DataValidation.DefaultDataValidator(condition);
- validator.type(ns.DataValidation.CriteriaType.Custom);
- sheet.setDataValidator(0, 0, validator);
- spread.options.highlightInvalidData = true;
- });
复制代码 |