我需要运行由 onedit() 触发的脚本,仅对其中的一张进行处理。
我已经尝试过以下操作,但目前我无法让脚本仅在所需的工作表(“库存”)上工作我确信这对于知道的人来说会非常简单:
function onEdit(e) {
var range = e.range;
if(range.getSheetName() == "Inventory") {
if(range.getValue() == "notify") {
range.setBackgroundColor('red');
var productname = range.offset(0,-3).getValue();
var productinventory = range.offset(0,-2).getValue();
var message = "Product variant " + productname + " has dropped to " + productinventory;
var subject = "Low Stock Notification";
var emailAddress = "[email protected] /cdn-cgi/l/email-protection";
MailApp.sendEmail(emailAddress, subject, message);
range.offset(0,1).setValue("notified");
}
}
}
Thanks!
尝试这样的事情,看看它是否有效:
function onEdit(e) {
var activeSheet = e.source.getActiveSheet();
var range = e.range;
if (activeSheet.getName() !== "Inventory" || e.value !== "notify") return;
range.setBackgroundColor('red');
var productname = range.offset(0, -3).getValue();
var productinventory = range.offset(0, -2).getValue();
var message = "Product variant " + productname + " has dropped to " + productinventory;
var subject = "Low Stock Notification";
var emailAddress = "[email protected] /cdn-cgi/l/email-protection";
MailApp.sendEmail(emailAddress, subject, message);
range.offset(0, 1).setValue("notified");
}
现在,如果活动工作表不是“库存”或编辑的值不是“通知”,脚本将退出。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)