Google apps script 如何在Google Apps脚本中通过行循环检查值

Google apps script 如何在Google Apps脚本中通过行循环检查值,google-apps-script,Google Apps Script,我的脚本检查单元格的值,并根据该值触发电子邮件。我需要它在行中循环,而不是应用于特定的单元格。代码工作正常,但它必须检查该列中的所有值 function CheckCalStatus() { var CalStatusRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1").getRange("Q2"); var CalStatus = CalStatusRange.getValue(); if (CalSta

我的脚本检查单元格的值,并根据该值触发电子邮件。我需要它在行中循环,而不是应用于特定的单元格。代码工作正常,但它必须检查该列中的所有值

function CheckCalStatus() {
var CalStatusRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1").getRange("Q2"); 
var CalStatus = CalStatusRange.getValue();
if (CalStatus == "INVITED"){
var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1").getRange("P2");
var emailAddress = emailRange.getValues();

// Send Alert Email.
var message = 'Respond to your invite'; 
var subject = 'A Calendar Invite is waiting for your response';
MailApp.sendEmail(emailAddress, subject, message);
}
}

函数CheckCalStatus(){
var CalStatusData=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“Sheet1”).getDataRange().getValues();
//在图纸的每一行中循环
对于(var i=0;i
function CheckCalStatus() {

  var CalStatusData=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1").getDataRange().getValues();

  //Loops through each row of the sheet
  for(var i=0;i<CalStatusData.length;i++)
  {
    //Takes data of Q Column
    var CalStatus=CalStatusData[i][16];
    if (CalStatus == "INVITED"){

      //Takes data of P Column
      var emailAddress =CalStatusData[i][15];
      // Send Alert Email.
      var message = 'Respond to your invite'; 
      var subject = 'A Calendar Invite is waiting for your response';
      MailApp.sendEmail(emailAddress, subject, message);
    }
  }
}