大家好,我从上一篇帖子中复制了此帖子,并使其符合我的需求。当Sent列在第10列中时,我无法阻止它发送整个列表。在这一点上,我对编码的混乱程度超过了我的意愿,并且感觉到它变得凌乱。
有人可以看看它,看看还缺少什么吗?
它将发送电子邮件并执行我需要做的所有事情,但是到目前为止,无论Sent
是否在该列中,它都仅发送所有数据行。
function sendEmails2() {
//setup function
var ActiveSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var StartRow = 2;
var RowRange = ActiveSheet.getLastRow() - StartRow + 1;
var WholeRange = ActiveSheet.getRange(StartRow,1,RowRange,11);
var AllValues = WholeRange.getValues();
var message = "";
//iterate loop
for (i in AllValues) {
//set current row
var CurrentRow = AllValues[i];
//define column to check if sent
var EmailSent = CurrentRow[10];
//if row has been sent, then continue to next iteration
if (EmailSent == "sent")
continue;
//set HTML template for information
message +=
"<p><b>Sales Rep: </b>" + CurrentRow[0] + "</p>" +
"<p><b>Case ID: </b>" + CurrentRow[1] + "</p>" +
"<p><b>Name: </b>" + CurrentRow[2] + "</p>" +
"<p><b>Signing Date: </b>" + CurrentRow[3] + "</p>" +
"<p><b>Draft Date: </b>" + CurrentRow[4] + "</p>" +
"<p><b>Sign to Draft: </b>" + CurrentRow[5] + "</p>" +
"<p><b>Enrolled Debt: </b>" + CurrentRow[6] + "</p><br><br>";
//set the row to look at
var setRow = parseInt(i) + StartRow;
//mark row as "sent"
ActiveSheet.getRange(setRow, 10).setValue("sent");
}
//define who to send email to
var SendTo = "my email address" + "," + "";
//set subject line
var Subject = "NEW DEAL CLOSED";
//send the actual email
MailApp.sendEmail({
to: SendTo,
cc: "",
subject: Subject,
htmlBody: message,
});
}
答案 0 :(得分:0)
错误在var EmailSent = CurrentRow [10]中存在,其中该列实际上在11中。当从工作表中获取整个数据范围时,该列的索引从0开始,因此对于第十栏
//define column to check if sent
var EmailSent = CurrentRow[9];