[英]Send an email from Google Sheets after a change to one column
I have a simple google sheet collecting data. 我有一个简单的谷歌表收集数据。 We use the sheet to follow up events.
我们使用工作表来跟进事件。 I want to send an email based on a change to a cell (column W) which will always be the same column.
我想根据对单元格(W列)的更改发送电子邮件,该单元格将始终为同一列。 The email is always to the same person in the business.
电子邮件总是发给业务中的同一个人。
I have got to the point of being able to make a change to ANY cell in the sheet and the first email is sent. 我已经到了能够对工作表中的任何单元格进行更改并发送第一封电子邮件的程度。 But I cannot figure out how to lock it down to only look at one column.
但我无法弄清楚如何锁定它只看一列。
Ideally the event will leave a footprint so I wanted to add a comment in the cell. 理想情况下,该事件将留下足迹,因此我想在单元格中添加注释。 It is working also.
它也在工作。
What I need - how do I limit the script to only look at column W??? 我需要什么 - 如何限制脚本仅查看列W ??? Thank you.
谢谢。
The columns also pull through tot he email fine. 列也通过电子邮件完成。
function onEdit(event)
{
var ss = event.source.getActiveSheet();
var r = event.source.getActiveRange();
r.setComment("Email Sent To Warrens: " + (new Date()));
}
function CustomEmail() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A2:W13");
var UserData = range.getValues();
var text = 'm******n@gmail.com';
for (i in UserData) {
var row = UserData[i];
var Title = row[6];
var SURNAME = row[7];
var EmailAddress = row[9];
var Rentalagreementnumber = row[3];
var Startofhiredate = row[4];
var Invoicereason = row[5];
var Amountdue = row [2];
var Rentallocation = row [8];
MailApp.sendEmail(text, "a***@*****.co.uk", "SUBJECT", "EMAIL TEXT");
}
}
Get the range from the event object , then use the function range#getA1Notation() to check which column was edited. 从事件对象获取范围 ,然后使用函数范围#getA1Notation()来检查编辑了哪个列。
function onEdit(event)
{
var range = event.range;
if(range.getA1Notation().charAt(0) === 'W'){
sendEmail();
range.setComment("Email Sent To Warrens: " + (new Date()));
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.