ExcelScript.ListDataValidation interface

Representa os critérios de validação de dados de lista.

Comentários

Exemplos

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

Propriedades

inCellDropDown

Especifica se é necessário exibir a lista em uma lista suspensa de células. O padrão é true.

source

Origem da lista para validação de dados Ao definir o valor, ele pode ser passado como um Range objeto ou uma cadeia de caracteres que contém um número separado por vírgulas, booliano ou data.

Detalhes da propriedade

inCellDropDown

Especifica se é necessário exibir a lista em uma lista suspensa de células. O padrão é true.

inCellDropDown: boolean;

Valor da propriedade

boolean

source

Origem da lista para validação de dados Ao definir o valor, ele pode ser passado como um Range objeto ou uma cadeia de caracteres que contém um número separado por vírgulas, booliano ou data.

source: string | Range;

Valor da propriedade