【问题标题】:Google Sheet Tab Change Notification谷歌表格标签更改通知
【发布时间】:2021-08-13 12:12:29
【问题描述】:
当特定标签添加了一行时,我如何才能收到电子邮件?如何添加多个电子邮件地址以通知选项卡的更改?
当 Google 表格中的特定标签发生更改时,我需要一个 Google 应用脚本来通过电子邮件通知我和我工作场所中的特定其他人。通知规则过于宽泛,会触发对整个工作簿的任何更改。
我尝试了一个应用脚本,但它仍在发送电子邮件以更改整个工作簿中的任何选项卡...而不是特定选项卡。
【问题讨论】:
标签:
google-apps-script
google-sheets
notifications
【解决方案1】:
您可以使用installable on change trigger 并检查事件类型是否为INSERT_ROW。虽然在那个页面上没有提到它(但是提到了here),事件对象也包含了它的来源,所以你可以使用它来获取修改后的工作表的名称:
function newRowAdded(event) {
const monitoredSheetName = 'Clients';
const emailAddresses = ['email1@example.com', 'email2@example.com'];
if (event.changeType === 'INSERT_ROW' &&
event.source.getActiveSheet().getName() === monitoredSheetName)
{
MailApp.sendEmail(
emailAddresses.join(','),
'New row added!',
'A new row has been added to sheet ' + monitoredSheetName
);
}
}