Google apps script 谷歌电子表格功能从所有表格中获取数据,而不仅仅是一张
这是我编写的函数,它在编辑指定的单元格/行/列时发送电子邮件通知某人,并将其设置为触发OneEdit。它按原样工作Google apps script 谷歌电子表格功能从所有表格中获取数据,而不仅仅是一张,google-apps-script,google-sheets,google-spreadsheet-api,Google Apps Script,Google Sheets,Google Spreadsheet Api,这是我编写的函数,它在编辑指定的单元格/行/列时发送电子邮件通知某人,并将其设置为触发OneEdit。它按原样工作 /* 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 = Spreadsheet
/* 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列时,才需要这样做
有什么想法吗?我希望这是我错过的简单问题,但我一直无法找到解决方案。您可以在分配
工作表
变量后中断函数:
if (sheet.getSheetName() != 'SheetIWant') return;
您需要查看onEdit提供的参数。它会告诉你变化发生在哪里。效果很好。我找到的另一个解决方案是这行代码。if(event.source.getActiveSheet().getName()=“SheetIWant”)