如果单元格更改,电子邮件通知 [英] email notification if cell is changed
问题描述
需要谷歌脚本方面的帮助.我有多行 电子表格.
need help with google script. I have multiple row spreadsheet.
需要一个执行以下操作的脚本:
如果 G 列中的任何单元格已更改,则发送电子邮件通知使用此行中的信息自定义地址:信息来自单元格 D 和单元格 G 的新值.
If any cell in column G has been changed, then send email notification to custom address with information from this row: information from cell D and new value of cell G.
UPD
我找到了有用的信息:
function emailNotification() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var cell = ss.getActiveCell().getA1Notation();
var cellvalue = ss.getActiveCell().getValue().toString();
var recipient = "me@gmail.com";
var subject = 'Update to '+sheet.getName();
var body = sheet.getName() + ' has been updated. Visit ' + ss.getUrl() + ' to view the changes on cell: «' + cell + '» New cell value: «' + cellvalue + '»';
MailApp.sendEmail(recipient, subject, body);
};
此脚本跟踪整个表中的更改.我只想跟踪 G 列的变化,并从 D 列获取值.
This script tracks the changes in the entire table. And I would like track changes only in column G, and get values from column D.
问题:
当值有时如何获取D列单元格的值更改了 G 列中的单元格
How to get the value of the cell in column D when the value has changed cell in column G
最后编写脚本——回答我的问题
function sendNotification() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var cell = ss.getActiveCell().getA1Notation();
var row = sheet.getActiveRange().getRow();
var cellvalue = ss.getActiveCell().getValue().toString();
var recipients = "me@gmail.com";
var message = '';
if(cell.indexOf('G')!=-1){
message = sheet.getRange('D'+ sheet.getActiveCell().getRowIndex()).getValue()
}
var subject = 'Update to '+sheet.getName();
var body = sheet.getName() + ' has been updated. Visit ' + ss.getUrl() + ' to view the changes on row: «' + row + '». New comment: «' + cellvalue + '». For message: «' + message + '»';
MailApp.sendEmail(recipients, subject, body);
};
在 onEdit 上设置触发器,脚本将正常工作
Set trigger on onEdit and script will work fine
推荐答案
你应该在发帖之前搜索这个论坛;我确实搜索了 email+cell 并得到了一些结果:
You should search this forum before posting questions; I did search on email+cell and got a few results :
例如,这篇文章的答案几乎完全符合您的要求.
For example, this post answer does almost exactly what you want to do.
在编辑后进行
使用 IF
条件.
像这样:
var cellG = ''
if(cell.indexOf('D')!=-1){ // = if you edit data in col D
cellG = sheet.getRange('G'+ sheet.getActiveCell().getRowIndex()).getValue()
// add more condition if necessary and/or send your mail (cellG contains the value in column G of the active row
}
Logger.log(cellG)
这篇关于如果单元格更改,电子邮件通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!