修改单元格时的Google表格通知? [英] Google Sheets Notifications When Cell is Edited?
问题描述
我有一个电子表格,希望在编辑特定单元格时将电子邮件发送给指定的用户.因此,例如,触发器列为J列.我的目标是编辑单元格(例如,J4)时,它将向单元格A4中提供的电子邮件地址发送自动电子邮件.我知道这将需要一个脚本.
I have a spreadsheet that I would like to have send an e-mail to a specified user whenever a particular cell is edited. So, for example, the trigger column is column J. My goal is that when a cell (J4, for example) is edited, it will send an automatic e-mail to the e-mail address that is provided in cell A4. I know this will require a script.
推荐答案
这是我想出的:
function onEditTrigger(e){
var range = e.range;
var intCol = range.getColumn();
if (intCol == 10) // Check for column J
{
var intRow = range.getRow(); // Get the row number of the edited cell
var sheet = SpreadsheetApp.getActiveSheet();
var dataRange = sheet.getRange(intRow, 1, 1, 3); // Select columns A to C on the same row as the edited cell
var dataValues = dataRange.getValues(); // Get the values in the selected range and store them in the dataValues array
MailApp.sendEmail(dataValues[0][0], "Notification", "Value in column C: " + dataValues[0][2]); // dataValues[0][0] = e-mail address, dataValues[0][2] = additional information
}
}
然后在脚本编辑器的资源"菜单上将触发器手动设置为onEdit
.
Then manually set the trigger to onEdit
on the Resources menu of the Script Editor.
当我在此处添加一些注释时,脚本几乎是不言自明的.但基本上,脚本首先检查用户是否编辑了触发"列.如果它是触发器"列,则它将获取该已编辑单元格的行号,并在A列中获取相应的电子邮件地址,并在同一行的C列中获取其他信息.然后,将一封带有主题"Notification"和C列中的值作为电子邮件正文的通知电子邮件发送到该电子邮件地址.
The script is pretty much self-explanatory as I put some comments there. But basically, the script first checks if a user edited the "trigger" column. If it is the "trigger" column, it gets the row number of that edited cell and gets the corresponding e-mail address in column A, and the additional information in column C of the same row. A notification e-mail is then sent to that e-mail address with the subject "Notification" and the value in column C as the body of the e-mail message.
这篇关于修改单元格时的Google表格通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!