我有专栏" D"在我的电子表格中。我想获取列中的所有对象并向他们发送电子邮件。我的脚本在列中获取了第一个用户然后循环它,它不会继续。
这就是我所拥有的:
function email(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var dataSheet = ss.getSheets()[0];
var email = dataSheet.getRange(2, 5);
var email2 = email.getValue();
for (var i = 0; i < email2.length; ++i) {
// Get a row object
var rowData = email2[i];
MailApp.sendEmail(rowData emailSubject, emailText);
Logger.log(email2);
}
}
答案 0 :(得分:0)
您只选择了一个单元格,因此您在单个元素中进行循环...
尝试这种方式:
function email(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var dataSheet = ss.getSheets()[0];
var emails = dataSheet.getRange('D2:D').getValues();
for (var i = 0; i < emails.length; ++i) {
// Get a row object
var rowData = emails[i][0];
if(rowData!=''){
MailApp.sendEmail(rowData emailSubject, emailText);// I assume emailSubject and emailText are defined in your real code...
}
Logger.log(emails[i]);
}
}