简体   繁体   English

Google表格应用脚本onEdit()触发器

[英]Google Sheets Apps Script onEdit() Trigger

I am new to programming, so bear with me here. 我是编程新手,所以在这里忍受。 I'm writing a script that, among other things, takes a cell value upon edit and then underlines a series of cells in various other ranges. 我正在编写一个脚本,除其他事项外,该脚本在编辑时获取一个单元格值,然后在其他各个范围内的一系列单元格下划线。 The given cell has validation on it so that the user can only select from a range of options from a dropdown menu. 给定的单元格具有验证,因此用户只能从下拉菜单的一系列选项中进行选择。

The validation function works fine from what I can tell, but when I edit the designated cell by selecting one of the dropdown menu options, nothing happens. 根据我的判断,验证功能可以正常工作,但是当我通过选择下拉菜单选项之一来编辑指定的单元格时,什么也没发生。 Do I need to call the onEdit(e) function? 我需要调用onEdit(e)函数吗? I've read the api references and searched stackoverflow and the web for help, but I'm stuck. 我已经阅读了api参考,并搜索了stackoverflow和网络以寻求帮助,但是我陷入了困境。

Please advise; 请指教; any help is appreciated. 任何帮助表示赞赏。 Here is the relevant part of my code: 这是我的代码的相关部分:

function validateLeagueSizeInput(sheet) {
  var cell = sheet.getRange('G2'),
      values = [[8], [10], [12]],
      range = sheet.getRange('A998:A1000').setValues(values),
      rule = SpreadsheetApp.newDataValidation().requireValueInRange(range, true).build();
  cell.setDataValidation(rule);
}

function onEdit(e) {
  var cell = e.value,
      range = SpreadsheetApp.getActiveSheet().getRange('A2:F301');
  for (var i = cell + 1; i < Math.floor(301 / cell); i += cell) {
    for (var j = 1; j <= 6; j++) {
      range[i][j].setBorder(null, null, true, null, null, null);
    }
  }
}

There are plenty of Spreadsheet changes that don't trigger onEdit() functions - you may just be the first person to report this particular one. 有许多电子表格更改不会触发onEdit()函数-您可能只是第一个报告此特定onEdit()的人。 See Detect user inserting row or column in a google spreadsheet and reacting in a script . 请参阅检测用户在Google电子表格中插入行或列并在脚本中做出反应

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM