能否请您告诉我,如何更改代码以仅在指定的工作表上运行脚本?如果指定工作表的第二列中的某些值会更改,我想发送电子邮件。目前,如果我更改任何工作表中的第二列,它将发送电子邮件。
我在下面尝试了代码,但是没有用:
var sheet = SpreadsheetApp.getActiveSpreadsheet();
SpreadsheetApp.setActiveSheet(sheet.getSheetByName('sheetname'))
这是我的代码:
function sendNotification() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var mycell = ss.getActiveSelection();
var cellcol = mycell.getColumn();
var row = sheet.getActiveRange().getRow();
var cellvalue = mycell.getValue().toString();
var recipients = "email@email.com";
if (cellcol == 2)
{
var subject = 'Update to '+sheet.getName();
var body = sheet.getName() + ' has been updated. Visit ' + ss.getUrl() + ' to view the changes on row: «' + row + '». New comment: «' + cellvalue + '»';
MailApp.sendEmail(recipients, subject, body);
}
}
谢谢。