【发布时间】:2019-03-11 09:59:23
【问题描述】:
目前,我的脚本正在使用“是”更新所选范围内的所有单元格,但我只希望它更新满足 if 条件的单元格。任何帮助将不胜感激。
//Active spreadsheet var that can be used anywhere in the programme
var ss = SpreadsheetApp.getActiveSpreadsheet();
// Get and check if there is an email address
function checkSendEmailAdd () {
//Getting the array of values
var activeSheet = ss.getActiveSheet();
var emailCol = activeSheet.getRange(2, 9, activeSheet.getLastRow() - 1, 2).getValues();
//Looping over the array of values
emailCol.forEach(function(val){
var email = val[0].toLowerCase();
var sentEmail = val[1];
//If the send date column is empty and the email column has a @ within the string an email will be sent
if (email.indexOf("@") !== -1 && sentEmail == ""){
//Email contents
var subject = "Survey";
var body = "Hi" + "<br><br>" +
"Testing 123";
GmailApp.sendEmail(email, subject, "", { htmlBody: body } );
//Update and set a new value in the sent email column
var newSetValue = "YES";
var updateSentEmail = activeSheet.getRange(2, 10, activeSheet.getLastRow() - 1, 1).setValue(newSetValue);
} else {
}
});
我面临的问题是已发送列正在更新每个单元格,但我只希望它更新在电子邮件列中有电子邮件的单元格。
【问题讨论】:
-
欢迎。脚本不完整,问题没有包含足够的细节。 emailCol. 有什么值?参考。 minimal reproducible example.
-
嗨@Rubén 感谢您的欢迎和建议。我现在更新了帖子以包含代码并进一步概述了问题。
标签: javascript google-apps-script google-sheets