【发布时间】:2021-08-06 18:58:25
【问题描述】:
我制作了以下脚本来为整个列提供一个相关的下拉数据验证列表,但是如果输入无效,我似乎无法找到拒绝输入的方法,即使使用 setAllowInvalid(),我怀疑这是因为我正在做一个偏移量。
任何帮助将不胜感激。
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var data = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Cost Centers");
var ui = SpreadsheetApp.getUi();
var activeCell = ss.getActiveCell();
if(activeCell.getColumn() == 4 && activeCell.getRow() > 1) {
if(activeCell.isBlank()){
activeCell.offset(0,1).clearContent().clearDataValidations();
}
var departments = data.getRange(3,26,1,20).getValues();
var departmentIndex = departments[0].indexOf(activeCell.getValue()) + 26;
if(departmentIndex != 0) {
var validationRange = data.getRange(4,departmentIndex,60);
var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange).setAllowInvalid(true).build();
activeCell.offset(0,1).setDataValidation(validationRule);
} }
}
【问题讨论】:
标签: validation google-apps-script