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
in |
Specifies whether to display the list in a cell drop-down. The default is |
source | Source of the list for data validation When setting the value, it can be passed in as a |
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
string | ExcelScript.Range
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Office Scripts