ExcelScript.DataValidationErrorAlert interface

表示数据验证的错误警报属性。

注解

示例

/**
 * This script creates a data validation rule for the range B1:B5.
 * All values in that range must be a positive number.
 * Attempts to enter other values are blocked and an error message appears.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the range B1:B5 in the active worksheet.
  const currentSheet = workbook.getActiveWorksheet();
  const positiveNumberOnlyCells = currentSheet.getRange("B1:B5");

  // Create a data validation rule to only allow positive numbers.
  const positiveNumberValidation: ExcelScript.BasicDataValidation = {
    formula1: "0",
    operator: ExcelScript.DataValidationOperator.greaterThan
  };
  const positiveNumberOnlyRule: ExcelScript.DataValidationRule = {
    wholeNumber: positiveNumberValidation
  };

  // Set the rule on the range.
  const rangeDataValidation = positiveNumberOnlyCells.getDataValidation();
  rangeDataValidation.setRule(positiveNumberOnlyRule);

  // Create an alert to appear when data other than positive numbers are entered.
  const positiveNumberOnlyAlert: ExcelScript.DataValidationErrorAlert = {
    message: "Positive numbers only",
    showAlert: true,
    style: ExcelScript.DataValidationAlertStyle.stop,
    title: "Invalid data"
  };
  rangeDataValidation.setErrorAlert(positiveNumberOnlyAlert);
}

属性

message

表示错误警报消息。

showAlert

指定当用户输入无效数据时是否显示错误警报对话框。 默认值为 true

style

有关详细信息,请参阅 ExcelScript.DataValidationAlertStyle 数据验证警报类型。

title

表示错误警报对话框标题。

属性详细信息

message

表示错误警报消息。

message: string;

属性值

string

showAlert

指定当用户输入无效数据时是否显示错误警报对话框。 默认值为 true

showAlert: boolean;

属性值

boolean

style

有关详细信息,请参阅 ExcelScript.DataValidationAlertStyle 数据验证警报类型。

style: DataValidationAlertStyle;

属性值

title

表示错误警报对话框标题。

title: string;

属性值

string