ExcelScript.ListDataValidation interface

Represents the List data validation criteria.

Remarks

Examples

/**
 * 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);
}

Properties

inCellDropDown

Specifies whether to display the list in a cell drop-down. The default is true.

source

Source of the list for data validation When setting the value, it can be passed in as a Range object, or a string that contains a comma-separated number, boolean, or date.

Property Details

inCellDropDown

Specifies whether to display the list in a cell drop-down. The default is true.

inCellDropDown: boolean;

Property Value

boolean

source

Source of the list for data validation When setting the value, it can be passed in as a Range object, or a string that contains a comma-separated number, boolean, or date.

source: string | Range;

Property Value