【问题标题】:Dependent Data Validation column script not rejecting input (Apps Script)相关数据验证列脚本不拒绝输入(Apps 脚本)
【发布时间】: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


    【解决方案1】:
    setAllowInvalid(false)
    

    setAllowInvalid(allowInvalidData)

    如果规则应该允许数据验证失败的输入,则为真;如果不是,则为 false。

    【讨论】:

    • 感谢您的更正,但是它仍然只显示无效警告(工作表右上角的红色标记),我的目标是拒绝输入并在无效时显示警告,您有解决方案?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-12
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-26
    相关资源
    最近更新 更多