0

这是我编写的函数,它会在编辑指定的单元格/行/列时发送电子邮件通知某人,并且我将其设置为触发 onEdit。它按原样工作。

/* This function send an email when a specified range is edited
 * The spreadsheets triggers must be set to onEdit for the function
*/

function sendNotification() {
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var sheet = ss.getActiveSheet();
  //Get Active cell
      var mycell = ss.getActiveSelection();
      var cellcol = mycell.getColumn();
      var cellrow = mycell.getRow();
  //Define Notification Details
      var recipients = "me@email.com";
      var subject = "Update to "+ss.getName();
      var body = ss.getName() + "has been updated.  Visit " + ss.getUrl() + " to view the changes.";
  //Check to see if column is A or B to trigger
      if (cellcol == 1, 2)
      {
  //check for row to trigger
        if (cellrow == 1)
        {
  //Send the Email
      MailApp.sendEmail(recipients, subject, body);
      }
  //End sendNotification
 }
}

我的问题是,只有当电子表格的某个工作表(页面)上的列或行被编辑时,我才需要这个工作,而不是电子表格中任何工作表中的 X 列。

有任何想法吗?我希望这是我错过的简单事情,但我一直无法找到解决方案。

4

2 回答 2

1

您可以在分配sheet变量后中断函数:

if (sheet.getSheetName() != 'SheetIWant') return;
于 2013-05-17T20:45:46.440 回答
0

You need to look at the parameters that onEdit provides. It will tell you where the change happened.

于 2013-05-17T22:28:48.660 回答