简体   繁体   English

如何让 onEdit 函数运行

[英]how do I get the onEdit function to run

I am making my own D&D sheet for my friends.我正在为我的朋友制作我自己的 D&D 表。 I would like this to be as cool and as complex as possible.我希望它尽可能酷和复杂。 Currently the onEdit function isn't even triggering .目前 onEdit 函数甚至没有触发 . I am trying to hide certain rows based on J3, if J3 = 1 then row 7 will be hidden.我试图根据 J3 隐藏某些行,如果 J3 = 1,则第 7 行将被隐藏。 In the future I will hide rows 7-10, if J3 >= 2 then it will show rows 7-10.将来我将隐藏第 7-10 行,如果 J3 >= 2 那么它将显示第 7-10 行。 When it changes nothing happens.当它改变时,什么也不会发生。 Please help.请帮忙。

function onEdit() {
var sheet = SpreadsheetApp.getActive().getSheetByName('Actions')
    var status = sheet.getRange('J3').getValue();
    if (status == 1) {
      sheet.hideRows(7);
    } else {
    if (status >= 2) {
      sheet.showRows(7);
    }
  }
  Logger.log('yay you did it')}

This works for me:这对我有用:

function onEdit(e) {
  var sh=e.range.getSheet()
  if(sh.getName()!='Actions')return;
  var status=sh.getRange('J3').getValue();
  if (status==1) {
    sh.hideRows(7);
  }else if(status>=2){
    sh.showRows(7);
  }
}

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

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