我有一些脚本可以运行以查找“E”列中的空单元格,如果找到则发送电子邮件。它运行并工作。问题是,它会为“E”列为空的每一行发送一封单独的电子邮件。如果在该列中找到空单元格,我只需要发送一封电子邮件。
如何实现?
function sendSupervisorEmail(e) {
var ss= SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Form Responses 1");
var data = sheet.getDataRange().getValues();
for(var i = 1; i < data.length; i++)
{
if(data[i][4] == "")
{var msg = "There are time off requests that have an open approval status. \n Click the following link to approve \n '>>>>URL<<<<'";
MailApp.sendEmail(">>>>EMAIL<<<<", "Open Approval Status - Time Off Requests", msg, {noReply: true} )}
}
}
如果E列有任何空白,您想发送电子邮件。
getLastRow
= 工作表中的行数sheet.getRange("e1:e").getValues().filter(String).length
= 获取 E 列中的记录数(忽略空白单元格)。function sendSupervisorEmail(e) {
var ss= SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Form Responses 1");
var data = sheet.getDataRange().getValues();
// get the number of records in Column E
var eRecords = sheet.getRange("e1:e").getValues().filter(String).length;
// get the last row in the sheet
var lastRow = sheet.getLastRow()
// send an email if the last row <> number of records
if (lastRow != eRecords){
var msg = "There are time off requests that have an open approval status. \n Click the following link to approve \n '>>>>URL<<<<'";
MailApp.sendEmail(">>>>EMAIL<<<<", "Open Approval Status - Time Off Requests", msg, {noReply: true} )
}
}