Excel.DataValidationRule interface

データ検証ルールには、さまざまな種類のデータ検証が含まれています。 に従って Excel.DataValidationType一度に使用できるのは、そのうちの 1 つだけです。

注釈

[ API セット: ExcelApi 1.8 ]

プロパティ

custom

データ検証条件のカスタム数式。

date

日付のデータ検証条件。

decimal

10 進数のデータ検証条件。

list

リストのデータ検証条件。

textLength

テキスト長データの検証条件。

time

時刻のデータ検証条件。

wholeNumber

整数データの検証条件。

プロパティの詳細

custom

データ検証条件のカスタム数式。

custom?: Excel.CustomDataValidation;

プロパティ値

注釈

[ API セット: ExcelApi 1.8 ]

date

日付のデータ検証条件。

date?: Excel.DateTimeDataValidation;

プロパティ値

注釈

[ API セット: ExcelApi 1.8 ]

decimal

10 進数のデータ検証条件。

decimal?: Excel.BasicDataValidation;

プロパティ値

注釈

[ API セット: ExcelApi 1.8 ]

list

リストのデータ検証条件。

list?: Excel.ListDataValidation;

プロパティ値

注釈

[ 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 nameRange = 
        sheet.tables.getItem("NameOptionsTable").columns.getItem("Baby Name").getDataBodyRange();

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

    const nameSourceRange = context.workbook.worksheets.getItem("Names").getRange("A1:A3");

    let approvedListRule = {
        list: {
            inCellDropDown: true,
            source: nameSourceRange
        }
    };
    nameRange.dataValidation.rule = approvedListRule;

    await context.sync();
});

textLength

テキスト長データの検証条件。

textLength?: Excel.BasicDataValidation;

プロパティ値

注釈

[ API セット: ExcelApi 1.8 ]

time

時刻のデータ検証条件。

time?: Excel.DateTimeDataValidation;

プロパティ値

注釈

[ API セット: ExcelApi 1.8 ]

wholeNumber

整数データの検証条件。

wholeNumber?: Excel.BasicDataValidation;

プロパティ値

注釈

[ 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();
});