Share via


ExcelScript.ListDataValidation interface

List データ検証条件を表します。

注釈

/**
 * This script creates a dropdown selection list for a cell.
 * It uses the existing values of the selected range as the choices for the list.
 */
function main(workbook: ExcelScript.Workbook) {
    // Get the values for data validation.
    const selectedRange = workbook.getSelectedRange();
    const rangeValues = selectedRange.getValues();

    // Convert the values into a comma-delimited string.
    let dataValidationListString = "";
    rangeValues.forEach((rangeValueRow) => {
        rangeValueRow.forEach((value) => {
            dataValidationListString += value + ",";
        });
    });

    // Clear the old range.
    selectedRange.clear(ExcelScript.ClearApplyTo.contents);

    // Apply the data validation to the first cell in the selected range.
    const targetCell = selectedRange.getCell(0, 0);
    const dataValidation = targetCell.getDataValidation();

    // Set the content of the dropdown list.
    let validationCriteria : ExcelScript.ListDataValidation = {
        inCellDropDown: true,
        source: dataValidationListString
    };
    let validationRule: ExcelScript.DataValidationRule = {
        list: validationCriteria
    };
    dataValidation.setRule(validationRule);
}

プロパティ

inCellDropDown

セルドロップダウンにリストを表示するかどうかを指定します。 既定値は です true

source

データ検証のリストのソース 値を設定するときに、オブジェクトとして Range 渡すか、コンマ区切りの数値、ブール値、または日付を含む文字列を渡すことができます。

プロパティの詳細

inCellDropDown

セルドロップダウンにリストを表示するかどうかを指定します。 既定値は です true

inCellDropDown: boolean;

プロパティ値

boolean

source

データ検証のリストのソース 値を設定するときに、オブジェクトとして Range 渡すか、コンマ区切りの数値、ブール値、または日付を含む文字列を渡すことができます。

source: string | Range;

プロパティ値