简体   繁体   English

onEdit(e) 触发器在编辑单元格时不执行任何操作

[英]onEdit(e) trigger does nothing when cell is being edited

I am trying to change the text in a cell (different from the edited one) when a specific cell is being edited当正在编辑特定单元格时,我试图更改单元格中的文本(与编辑的文本不同)

I am using the following code:我正在使用以下代码:

function get_cells(){
  
  if (sheet.getRange(3,6).getValue() == 'Cat') {
  sheet.getRange(5,5).setValue('Animal')
} else if (sheet.getRange(3,6).getValue() == 'Apple') {
  sheet.getRange(5,5).setValue('Fruit')
} else {
  sheet.getRange(5,5).setValue(NaN)
}

}

function onEdit(e){
  var range = e.range;

  if (range.getRow()== 3 && range.getColumn()==6){
    get_cells();
  }
}

The idea is that when the cell (3,6) is edited then the content of the cell (5,5) will be changed automatically.这个想法是,当单元格 (3,6) 被编辑时,单元格 (5,5) 的内容将自动更改。 But it doesn't work但它不起作用

Try it this way:试试这个方法:

Get cells required the sheet.获取工作表所需的单元格。 You could have learned this by viewing you executions.您可以通过查看处决来了解这一点。

function get_cells(sheet) {

  if (sheet.getRange(3, 6).getValue() == 'Cat') {
    sheet.getRange(5, 5).setValue('Animal')
  } else if (sheet.getRange(3, 6).getValue() == 'Apple') {
    sheet.getRange(5, 5).setValue('Fruit')
  } else {
    sheet.getRange(5, 5).setValue(NaN)
  }

}

function onEdit(e) {
  e.source.toast('entry');
  const sheet = e.range.getSheet();
  if (e.range.rowStart == 3 && e.range.columnStart == 6) {
    e.source.toast('first if')
    get_cells(sheet);
  }
}

Incomplete list of event object values 事件对象值的不完整列表

暂无
暂无

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

相关问题 Google脚本中的onEdit(e)-尝试将上次编辑的日期放在单元格中,并在某些工作表(标签)上排除此功能 - onEdit(e) in Google Script - trying to put last edited date in cell and exclude this functionality on certain sheets (tabs) 如果使用VLOOKUP,onEdit()不会触发 - onEdit() does not trigger if using VLOOKUP onEdit() 触发器删除已编辑的单元格 eventId,然后创建新单元格 - onEdit() trigger to delete edited cells eventId and then create new one 使用onEdit触发器将值返回到Google电子表格中的单元格 - Return a value to a cell in google spreadsheet with an onEdit trigger Function onEdit(e) 仅适用于单个单元格编辑 - Function onEdit(e) works only for single cell edit 当我编辑任何单元格时,我需要一个 function 来运行。 我试过 onEdit 但它没有触发 function - When I edit any cell, I need a function to run. I tried onEdit but it's not getting trigger the function 当单元格被编辑为谷歌表格应用程序脚本中的某些文本时,如何触发 function? - How to trigger function when cell is edited to certain text in google sheet app script? jqGrid在编辑时访问单元格数据 - jqGrid access cell data while it is being edited 为什么$ watch会在没有任何变化时使用AngularJS触发? - Why does $watch trigger with AngularJS when nothing has changed? 特定列的 Google Apps 脚本 onEdit(e) 不起作用 - Google Apps Script onEdit(e) for specific column does not work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM