Excel.DataValidationErrorAlert interface

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

注解

[ API 集:ExcelApi 1.8 ]

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/22-data-validation/data-validation.yaml

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getItem("Decision");
    const rankingRange = sheet.tables.getItem("NameOptionsTable").columns.getItem("Ranking").getDataBodyRange();

    // When you are developing, it is a good practice to
    // clear the dataValidation object with each run of your code.
    rankingRange.dataValidation.clear();

    let greaterThanZeroRule = {
        wholeNumber: {
            formula1: 0,
            operator: Excel.DataValidationOperator.greaterThan
        }
    };
    rankingRange.dataValidation.rule = greaterThanZeroRule;

    rankingRange.dataValidation.prompt = {
        message: "Please enter a positive number.",
        showPrompt: true,
        title: "Positive numbers only."
    };

    rankingRange.dataValidation.errorAlert = {
        message: "Sorry, only positive numbers are allowed",
        showAlert: true,
        style: "Stop",
        title: "Negative Number Entered"
    };

    await context.sync();
});

属性

message

表示错误警报消息。

showAlert

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

style

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

title

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

属性详细信息

message

表示错误警报消息。

message: string;

属性值

string

注解

[ API 集:ExcelApi 1.8 ]

showAlert

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

showAlert: boolean;

属性值

boolean

注解

[ API 集:ExcelApi 1.8 ]

style

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

style: Excel.DataValidationAlertStyle | "Stop" | "Warning" | "Information";

属性值

Excel.DataValidationAlertStyle | "Stop" | "Warning" | "Information"

注解

[ API 集:ExcelApi 1.8 ]

title

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

title: string;

属性值

string

注解

[ API 集:ExcelApi 1.8 ]