这是我编写的函数,每当编辑指定的单元格/行/列时,都会发送电子邮件通知某人,并且我将其设置为触发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列时才需要此功能。
任何想法?我希望是我错过了一些简单的东西,但是我一直找不到解决办法。
您可以在分配sheet
变量后中断函数:
if (sheet.getSheetName() != 'SheetIWant') return;
您需要查看onEdit提供的参数。它会告诉你发生了什么变化