Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google sheets googlesheets中的多重数据验证问题_Google Sheets_Drop Down Menu - Fatal编程技术网

Google sheets googlesheets中的多重数据验证问题

Google sheets googlesheets中的多重数据验证问题,google-sheets,drop-down-menu,Google Sheets,Drop Down Menu,我有一个下拉菜单在A1,但我想它拒绝输入,如果B1说“关闭”。它不会让我在创建拒绝输入的数据验证时保留下拉框。如何解决此问题?无法在所选范围内添加两个不同的数据验证标准 您可以做的一个变通方法是使用数据验证来创建一个下拉菜单,并在应用程序脚本中创建一个拒绝输入的函数 示例代码: function onEdit(e){ var cell = e.range; var col = e.range.getColumn(); var ui = SpreadsheetApp.getUi();

我有一个下拉菜单在A1,但我想它拒绝输入,如果B1说“关闭”。它不会让我在创建拒绝输入的数据验证时保留下拉框。如何解决此问题?

无法在所选范围内添加两个不同的数据验证标准

您可以做的一个变通方法是使用数据验证来创建一个下拉菜单,并在应用程序脚本中创建一个拒绝输入的函数

示例代码:

function onEdit(e){

  var cell = e.range;
  var col = e.range.getColumn();
  var ui = SpreadsheetApp.getUi();

  //Check if current edited cell is in column 1 and if the cell besides the current cell is Closed
  if(col == 1 && cell.offset(0,1).getValue() == "Closed"){

    //Display warning message
    ui.alert(
      'Warning',
      'You cannot modify cells that are closed, returning the original value of the cell',
      ui.ButtonSet.OK
    )
    //return cell to its original value
    cell.setValue(e.oldValue);
  }
}
它的作用是什么?

  • 检查修改后的单元格是否在第1列中,并验证其右侧相邻单元格的值是否为“Closed”

  • 如果为true,则显示警告消息并将单元格返回其原始值

  • 输出:

    function onEdit(e){
    
      var cell = e.range;
      var col = e.range.getColumn();
      var ui = SpreadsheetApp.getUi();
    
      //Check if current edited cell is in column 1 and if the cell besides the current cell is Closed
      if(col == 1 && cell.offset(0,1).getValue() == "Closed"){
    
        //Display warning message
        ui.alert(
          'Warning',
          'You cannot modify cells that are closed, returning the original value of the cell',
          ui.ButtonSet.OK
        )
        //return cell to its original value
        cell.setValue(e.oldValue);
      }
    }
    

    我使用+1作为列偏移量来获取当前单元格右侧单元格的值


    其他参考资料:

    function onEdit(e){
    
      var cell = e.range;
      var col = e.range.getColumn();
      var ui = SpreadsheetApp.getUi();
    
      //Check if current edited cell is in column 1 and if the cell besides the current cell is Closed
      if(col == 1 && cell.offset(0,1).getValue() == "Closed"){
    
        //Display warning message
        ui.alert(
          'Warning',
          'You cannot modify cells that are closed, returning the original value of the cell',
          ui.ButtonSet.OK
        )
        //return cell to its original value
        cell.setValue(e.oldValue);
      }
    }