我希望设置一些内容,只有在更改特定的单个单元格时才会发送通知。我几乎没有编码经验,对需要采取的措施有一个大概的了解。根据我收集的内容,我创建了一个脚本,但它包含了所有单元格更改的通知。任何有关更改为仅在单个单元格上通知的建议都将受到赞赏。
function emailNotification() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var cell = ss.getActiveCell().getA1Notation();
var cellvalue = ss.getActiveCell().getValue().toString();
var recipient = "mail@mail.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);
};
答案 0 :(得分:0)
尝试更改
var cell = ss.getActiveCell().getA1Notation();
var cellvalue = ss.getActiveCell().getValue().toString();
to
var cell = ss.getRange(row, column); //Put in the row and column of your cell
var cellvalue = cell.getValue().toString();
答案 1 :(得分:0)
假设有'更改'你的意思是手工编辑,以限制'对于某个工作表和/或某个单元格的脚本,您必须检查当前编辑的单元格是什么。例如:如果您只想在编辑Sheet1的单元格A1时触发脚本,请尝试类似:
function emailNotification(e) {
var sheet = e.source.getActiveSheet();
if (sheet.getName() !== 'Sheet1' || e.range.getA1Notation() !== 'A1') return;
var recipient = "mail@gmail.com";
var subject = 'Update to ' + sheet.getName();
var body = sheet.getName() + ' has been updated.\nVisit ' + e.source.getUrl() + ' to view the changes on cell A1.\nNew cell value: «' + e.value + '»';
MailApp.sendEmail(recipient, subject, body);
};
更改工作表名称和单元格以查看是否有效?
答案 2 :(得分:-1)
var cell = ss.getRange("F2:F50"); //Put in the row and column of your cell
我也在使用它。如果编辑了任何单元格,脚本仍在发送通知,而不仅仅是列F