Google脚本进行循环,如果单元格为0,则通过列表通过电子邮件发送电子邮件

时间:2018-07-12 23:26:24

标签: google-apps-script google-sheets

如果B列的值为0,则B列是我正在测试的值,C列是我要向其发送电子邮件的电子邮件。该函数运行但不发送电子邮件

function email() {
  var ss = SpreadsheetApp.getActive().getSheetByName('email');
  var range = ss.getRange('B1:B29');
  var email = ss.getRange('C1:C29');
  for (var i = 0; i < range.length; i++){
    var recipient = email[i]
    var x = range[i]
    if(x == 0){
      MailApp.sendEmail(recipient,
                    "Fill in Schedule for next Week",
                    "Your Schedule for next week isn't filled out. Please fill this in by Sunday\n https://docs.google.com/spreadsheets/d/1Yo8neePMv5rB-JRvgFOL6SKo83jv-FBoNuldcSynsUY/edit#gid=0 \n(Automated Message)",
                    {noReply:true});
    }

  }
}

1 个答案:

答案 0 :(得分:0)

我知道了。我只需要使用.getValues()将变量转换为正确的数组

var range = ss.getRange('B1:B29').getValues();
var email = ss.getRange('C1:C29').getValues();