Specifying what row to start onEdit Google Script

北城余情 提交于 2019-12-25 01:40:43

问题


I want this onEdit script on google Spreadsheet to start with Row 2, which skips my header row, but I cannot get it to work with my existing code? Can someone out there help a noob out?

function onEdit(e)
{
  var ss = e.source.getActiveSheet();
  var rr  = e.source.getActiveRange();


//comment 2 lines below if you want it working on all sheets, not just on 2nd one
  if(ss.getIndex()!= 1)
    if(ss.getIndex()!= 2) 
      if(ss.getIndex()!= 3) 
  return;
 ///

  var firstRow = rr.getRow();
  var lastRow = rr.getLastRow();

//the last modified date will appear in the 43th column which is the Last Update Column
  for(var r=firstRow; r<=lastRow; r++)
    ss.getRange(r, 43).setValue(new Date());
}

回答1:


Just check if the current row is within the header, and exit the trigger:

function onEdit(e)
{
  var rr = e.range;
  var ss = e.range.getSheet();

  var headerRows = 1;  // # header rows to ignore

  if (rr.getRow() <= headerRows) return;
  ...


来源:https://stackoverflow.com/questions/11354480/specifying-what-row-to-start-onedit-google-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!