[]
Sheets.DataValidation.DefaultDataValidator
• new DefaultDataValidator(condition?
)
数据验证器
代码示例
//本示例验证单元数据
spread.options.highlightInvalidData = true;
var dv = GC.Spread.Sheets.DataValidation.createTextLengthValidator(GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan, 5);
activeSheet.setDataValidator(0, 0, 1, 1, dv, GC.Spread.Sheets.SheetArea.viewport);
activeSheet.setValue(0, 0, "abcf");
属性名 | 类型 |
---|---|
condition? |
Condition |
▸ comparisonOperator(value?
): any
获取或设置比较运算符
属性名 | 类型 |
---|---|
value? |
ComparisonOperators |
any
如果未设置任何值,则返回比较运算符;否则,返回数据验证器
▸ condition(value?
): any
获取或设置要验证的条件
属性名 | 类型 |
---|---|
value? |
Condition |
any
如果未设置任何值,则返回条件以进行验证;否则,返回数据验证器
▸ errorMessage(value?
): any
获取或设置错误消息
属性名 | 类型 |
---|---|
value? |
string |
any
如果未设置任何值,则返回错误消息否则,返回数据验证器
▸ errorStyle(value?
): any
获取或设置要显示的错误样式
属性名 | 类型 |
---|---|
value? |
ErrorStyle |
any
如果未设置任何值,则返回要显示的错误样式否则,返回数据验证器
▸ errorTitle(value?
): any
获取或设置错误标题
属性名 | 类型 |
---|---|
value? |
string |
any
如果未设置任何值,则返回错误标题否则,返回数据验证器
▸ getValidList(evaluator
, baseRow
, baseColumn
): any
[]
如果数据验证类型为列表,则返回有效数据列表;否则,返回null
属性名 | 类型 | 说明 |
---|---|---|
evaluator |
Object |
可以计算条件的对象 |
baseRow |
number |
基行 |
baseColumn |
number |
基列 |
any
[]
有效数据列表或null
▸ highlightStyle(style?
): Object
获取或设置无效的数据单元格高亮显示样式
代码示例
//本示例使用highlightStyle方法
sheet.setValue(1, 1, "sss");
var dv = GC.Spread.Sheets.DataValidation.createListValidator('Fruit,Vegetable,Food');
dv.highlightStyle({
type:GC.Spread.Sheets.DataValidation.HighlightType.dogEar,
color:'blue',
position:GC.Spread.Sheets.DataValidation.HighlightPosition.topLeft
});
sheet.setDataValidator(1,1, dv);
spread.options.highlightInvalidData = true;
属性名 | 类型 |
---|---|
style? |
IHighLightStyle |
any
如果未设置任何值,则返回高亮显示样式对象;否则,返回数据验证器
▸ ignoreBlank(value?
): any
获取或设置是否忽略空值
代码示例
//本示例使用IgnoreBlank方法
var nCondition = new GC.Spread.Sheets.ConditionalFormatting.Condition(GC.Spread.Sheets.ConditionalFormatting.ConditionType.cellValueCondition);
nCondition.compareType(GC.Spread.Sheets.ConditionalFormatting.GeneralComparisonOperators.equalsTo);
nCondition.expected(0);
//当选项为false时,验证失败并显示红色警报
//当选项为true时,将把空白单元格视为零,验证成功
nCondition.treatNullValueAsZero(false);
var validator = new GC.Spread.Sheets.DataValidation.DefaultDataValidator(nCondition);
validator.type(GC.Spread.Sheets.DataValidation.CriteriaType.custom);
validator.ignoreBlank(false);
activeSheet.getCell(0, 0, GC.Spread.Sheets.SheetArea.viewport).validator(validator);
spread.options.highlightInvalidData = true;
activeSheet.setValue(0, 0, null);
属性名 | 类型 |
---|---|
value? |
boolean |
any
如果未设置任何值,则返回是否忽略空值否则,返回数据验证器
▸ inCellDropdown(value?
): any
获取或设置是否显示下拉按钮
代码示例
//本示例使用inCellDropdown方法
spread.options.highlightInvalidData = true;
var dv = GC.Spread.Sheets.DataValidation.createListValidator("1,2,3");
dv.showInputMessage(true);
dv.inputMessage("Value must be 1,2 or 3");
dv.inputTitle("tip");
dv.inCellDropdown(true);
activeSheet.setDataValidator(1,1,1,1,dv,GC.Spread.Sheets.SheetArea.viewport);
var validList = activeSheet.getDataValidator(1, 1).getValidList(activeSheet, 1, 1);
alert(validList);
属性名 | 类型 | 说明 |
---|---|---|
value? |
boolean |
是否显示下拉按钮 |
any
如果未设置任何值,则返回是否显示下拉按钮;否则,返回数据验证器
▸ inputMessage(value?
): any
获取或设置输入消息
代码示例
spread.options.highlightInvalidData = true;
var dv = GC.Spread.Sheets.DataValidation.createListValidator("1,2,3");
dv.showInputMessage(true);
dv.inputMessage("Value must be 1,2 or 3");
dv.inputTitle("tip");
activeSheet.setDataValidator(1,1,1,1,dv,GC.Spread.Sheets.SheetArea.viewport);
alert(activeSheet.getDataValidator(1,1).getValidList(activeSheet,1,1));
属性名 | 类型 | 说明 |
---|---|---|
value? |
string |
输入消息 |
any
如果未设置任何值,则返回输入消息否则,返回数据验证器
▸ inputTitle(value?
): any
获取或设置输入标题
代码示例
spread.options.highlightInvalidData = true;
var dv = GC.Spread.Sheets.DataValidation.createListValidator("1,2,3");
dv.showInputMessage(true);
dv.inputMessage("Value must be 1,2 or 3");
dv.inputTitle("tip");
activeSheet.setDataValidator(1,1,1,1,dv,GC.Spread.Sheets.SheetArea.viewport);
alert(activeSheet.getDataValidator(1,1).getValidList(activeSheet,1,1));
属性名 | 类型 | 说明 |
---|---|---|
value? |
string |
输入标题 |
any
如果未设置任何值,则返回输入标题否则,返回数据验证器
▸ isValid(evaluator
, baseRow
, baseColumn
, actual
): boolean
确定当前值是否有效
代码示例
sheet.setArray(0, 0,
[
[ 3.4 ],
[ 102.8 ]
]);
var expression1 = 1.1;
var expression2 = 101.2;
var dv = GC.Spread.Sheets.DataValidation.createNumberValidator(GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.between, expression1, expression2, false);
sheet.getCell(0, 0, GC.Spread.Sheets.SheetArea.viewport).validator(dv);
dv = sheet.getCell(0, 0, GC.Spread.Sheets.SheetArea.viewport).validator(); // Limitation of SDM, the dv is copied when set to style.
console.log(dv.isValid(sheet, 0, 0, 3)); // true
console.log(dv.isValid(sheet, 0, 0, 1)); // false
console.log(dv.isValid(sheet, 0, 0, 101)); // true
console.log(dv.isValid(sheet, 0, 0, 0)); // false
console.log(dv.isValid(sheet, 0, 0, 120.0)); // false
属性名 | 类型 | 说明 |
---|---|---|
evaluator |
Object |
计算器 |
baseRow |
number |
基行 |
baseColumn |
number |
基列 |
actual |
Object |
当前值 |
boolean
true
该值有效;否则为false
▸ preciseCompareDate(value?
): any
获取或设置是比较整天还是精确日期时间
代码示例
//本示例使用preciseCompareDate方法
var dateCondition = new GC.Spread.Sheets.ConditionalFormatting.Condition(GC.Spread.Sheets.ConditionalFormatting.ConditionType.dateCondition);
dateCondition.compareType(GC.Spread.Sheets.ConditionalFormatting.DateCompareType.after);
dateCondition.expected(new Date(2020, 4, 22, 6));
//When the option is false, the validator compares the whole day, and they are the same, so validation fails and the red alert is displayed.
//When the option is true, the date time 7 o'clock is greater than 6 o'clock, so the result is successful.
var validator = new GC.Spread.Sheets.DataValidation.DefaultDataValidator(dateCondition);
validator.type(GC.Spread.Sheets.DataValidation.CriteriaType.date);
validator.preciseCompareDate(true);
activeSheet.getCell(0, 0, GC.Spread.Sheets.SheetArea.viewport).validator(validator);
spread.options.highlightInvalidData = true;
activeSheet.setValue(0, 0, new Date(2020, 4, 22, 07));
属性名 | 类型 | 说明 |
---|---|---|
value? |
boolean |
比较整天或精确日期时间 |
any
如果未设置值,则返回比较全天或精确日期时间;否则,返回数据验证
▸ reset(): void
重置数据验证器
代码示例
//本示例使用reset方法
var nCondition = new GC.Spread.Sheets.ConditionalFormatting.Condition(GC.Spread.Sheets.ConditionalFormatting.ConditionType.cellValueCondition);
nCondition.compareType(GC.Spread.Sheets.ConditionalFormatting.GeneralComparisonOperators.equalsTo);
nCondition.expected(0);
//When the option is false, the validation fails and the red alert is displayed.
//When the option is true, the blank cell is treated as zero and the validation is successful.
nCondition.treatNullValueAsZero(false);
var validator = new GC.Spread.Sheets.DataValidation.DefaultDataValidator(nCondition);
validator.type(GC.Spread.Sheets.DataValidation.CriteriaType.custom);
validator.ignoreBlank(false);
activeSheet.getCell(0, 0, GC.Spread.Sheets.SheetArea.viewport).validator(validator);
spread.options.highlightInvalidData = true;
activeSheet.setValue(0, 0, null);
validator.reset();
void
▸ showErrorMessage(value?
): any
获取或设置是否显示错误消息
代码示例
spread.options.highlightInvalidData = true;
//如果公式条件返回true,则公式验证有效
var dv = GC.Spread.Sheets.DataValidation.createFormulaValidator("A1>0");
dv.showInputMessage(true);
dv.inputMessage("Enter a value greater than 0 in A1.");
dv.inputTitle("Tip");
dv.showErrorMessage(true);
dv.errorMessage("Incorrect Value");
activeSheet.setDataValidator(0, 0, 1, 1, dv, GC.Spread.Sheets.SheetArea.viewport);
//bind
activeSheet.bind(GC.Spread.Sheets.Events.ValidationError, function (sender, args) {
if (args.validator.showErrorMessage()) {
if (confirm(args.validator.errorMessage())) {
args.validationResult = GC.Spread.Sheets.DataValidation.DataValidationResult.retry;
} else {
args.validationResult = GC.Spread.Sheets.DataValidation.DataValidationResult.forceApply;
}
}
});
属性名 | 类型 | 说明 |
---|---|---|
value? |
boolean |
是否显示错误消息 |
any
如果未设置任何值,则返回是否显示错误消息否则,返回数据验证器
▸ showInputMessage(value?
): any
获取或设置是否显示输入标题和输入消息
代码示例
spread.options.highlightInvalidData = true;
var dv = GC.Spread.Sheets.DataValidation.createListValidator("1,2,3");
dv.showInputMessage(true);
dv.inputMessage("Value must be 1,2 or 3");
dv.inputTitle("tip");
activeSheet.setDataValidator(1,1,1,1,dv,GC.Spread.Sheets.SheetArea.viewport);
alert(activeSheet.getDataValidator(1,1).getValidList(activeSheet,1,1));
属性名 | 类型 |
---|---|
value? |
boolean |
any
如果未设置任何值,则返回是否显示输入标题和输入消息否则,返回数据验证器
▸ type(value?
): any
获取或设置此数据验证器的条件类型
属性名 | 类型 |
---|---|
value? |
CriteriaType |
any
如果未设置任何值,则返回此数据验证器的条件类型;否则,返回数据验证器
▸ value1(baseRow?
, baseColumn?
): any
获取数据验证的第一个值
代码示例
//本示例验证单元格值
var nCondition = new GC.Spread.Sheets.ConditionalFormatting.Condition(GC.Spread.Sheets.ConditionalFormatting.ConditionType.cellValueCondition);
nCondition.compareType(GC.Spread.Sheets.ConditionalFormatting.GeneralComparisonOperators.equalsTo);
nCondition.expected(0);
//当选项为false时,验证失败并显示红色警报
//当选项为true时,将把空白单元格视为零,验证成功
nCondition.treatNullValueAsZero(false);
var validator = new GC.Spread.Sheets.DataValidation.DefaultDataValidator(nCondition);
validator.type(GC.Spread.Sheets.DataValidation.CriteriaType.custom);
validator.ignoreBlank(false);
activeSheet.getCell(0, 0, GC.Spread.Sheets.SheetArea.viewport).validator(validator);
spread.options.highlightInvalidData = true;
activeSheet.setValue(0, 0, null);
alert(validator.value1());
属性名 | 类型 | 说明 |
---|---|---|
baseRow? |
number |
基行 |
baseColumn? |
number |
基列 |
any
第一个值
▸ value2(baseRow?
, baseColumn?
): any
获取数据验证的第二个值
代码示例
//本示例验证单元格值
var nCondition = new GC.Spread.Sheets.ConditionalFormatting.Condition(GC.Spread.Sheets.ConditionalFormatting.ConditionType.cellValueCondition);
nCondition.compareType(GC.Spread.Sheets.ConditionalFormatting.GeneralComparisonOperators.equalsTo);
nCondition.expected(0);
//当选项为false时,验证失败并显示红色警报
//当选项为true时,将把空白单元格视为零,验证成功
nCondition.treatNullValueAsZero(false);
var validator = new GC.Spread.Sheets.DataValidation.DefaultDataValidator(nCondition);
validator.type(GC.Spread.Sheets.DataValidation.CriteriaType.custom);
validator.ignoreBlank(false);
activeSheet.getCell(0, 0, GC.Spread.Sheets.SheetArea.viewport).validator(validator);
spread.options.highlightInvalidData = true;
activeSheet.setValue(0, 0, null);
alert(validator.value2());
属性名 | 类型 | 说明 |
---|---|---|
baseRow? |
number |
基行 |
baseColumn? |
number |
基列 |
any
第二个值