你好,我是一个新手与谷歌脚本,试图编码自动发送电子邮件功能.要跳过任何空行,以便函数继续


function sendEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow();
for (var i = 2; i <= lr; i++) {
var currentEmail = ss.getRange(i, 2).getValue();
var currentTitle = ss.getRange(i, 3).getValue();
GmailApp.sendEmail(currentEmail, currentTitle, "Hi")

像这样?

function sendEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
//Get all the values with one call into memory
var values = ss.getRange(2, 2, ss.getLastRow() - 1, 2).getValues();
//Loop over the array or rows and destructure the values.
values.forEach(value => {
const [email, title] = value
//check if email is not empty string. If so then skip.
if (email == "") {
return
}
GmailApp.sendEmail(email, title, "Hi")
})
}

最新更新