ExcelScript.ListDataValidation interface
表示列表数据验证条件。
注解
示例
/**
* 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);
}
属性
in |
指定是否在单元格下拉列表中显示列表。 默认值为 |
source | 用于数据验证的列表源 设置值时,可以将其作为 |
属性详细信息
inCellDropDown
指定是否在单元格下拉列表中显示列表。 默认值为 true
。
inCellDropDown: boolean;
属性值
boolean
source
用于数据验证的列表源 设置值时,可以将其作为 Range
对象或包含逗号分隔数字、布尔值或日期的字符串传入。
source: string | Range;
属性值
string | ExcelScript.Range