如果emailSentCol!== Email_Sent,我的脚本目前设置为不发送电子邮件。如果emailSentCol中的单元格为空,我也希望它不发送。有什么建议?谢谢你们。第12行
function myFunction() {
var EMAIL_SENT = "EMAIL_SENT";
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Administrators");
if (sheet != null) {
var data = sheet.getDataRange().getValues();
var startRow = 1; //The starting row of data (zero indexed)
var emailCol = 1; //The column that the email address is in (zero indexed)
var messageCol = 28; //The column that the message is in (zero indexed)
var emailSentCol = 29; //The column that the EMAIL_SENT note is in (zero indexed)
for (var i = startRow; i < data.length; i++) {
if (data[i][emailSentCol] !== EMAIL_SENT) {
var emailAddress = data[i][emailCol];
var subject = "Tuition Reimbursement Status";
var message = data[i][messageCol];
if(emailAddress !== null && emailAddress !== '' && emailAddress !== "") {
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(i+1,emailSentCol+1).setValue(EMAIL_SENT);
}
}
}
}
答案 0 :(得分:0)
修改你的if结构如下:
if (data[i][emailSentCol] && data[i][emailSentCol] !== EMAIL_SENT) {
这确保在检查之前必须定义data [i] [emailSentCol]并且非null,以查看它是否未被发送。