Google Script无效分配左侧

时间:2014-08-06 15:48:47

标签: javascript google-apps-script

好的,我有这个代码。对不起,我不知道问题出在哪里所以我粘贴了所有内容。它说:左侧无效的任务。 (第1行,文件“代码”)。我知道问题不在第一线,但不知道它在哪里。

function send(sheet, email, row){
  var tmp = GmailApp.getAliases();
  var alias = tmp[0];

  var subject = "Thank you for signing up for "+ sheet.getSheetName()+ "!";
  var body = "Hello "+ sheet.getRange(row,3).getValue() + " " + sheet.getRange(row,4).getValue() + "," + '\n'+'\n';
  var temp = 2;
  var bool = "TRUE";
  while (bool == "TRUE"){
    if (sheet.getRange(temp,11).getValue() != ''){
      body += '\n' + sheet.getRange(temp,11);
      temp += 1;
    }
    if (sheet.getRange(temp + 1,11).getValue() != '')
      body += '\n' + body += '\n' + sheet.getRange(temp + 1,11);
    else {bool = "FALSE"}
  }

  Logger.log(body);

  if ( sheet.getRange('L2').getValue() != ""){
    var html = sheet.getRange('L2').getValue();  // Place HTML code here
    try {
      GmailApp.sendEmail(email, subject, body, {'from': alias, 'htmlbody': html});
      sheet.getRange(row, 9).setBackground("green");
      sheet.getRange(row, 9).setValue("Yes");
      sheet.getRange("J2").setValue(row - 2);
    } catch (e) {
      var me = Session.getActiveUser().getEmail();
      MailApp.sendEmail(me, "Autoreply error", "There was a problem sending an email to: " + email +".");
    }
  }
  else{
    try {
      GmailApp.sendEmail(email, subject, body, {'from': alias});
      sheet.getRange(row, 9).setBackground("green");
      sheet.getRange(row, 9).setValue("Yes");
      sheet.getRange("J2").setValue(row - 2);
    } catch (e) {
      MailApp.sendEmail(me, "Autoreply error", "There was a problem sending an email to: " + email +".");
    }
  }
}

function main(){
  var ss = SpreadsheetApp.openById("1a2xvZ6hx69hst0CoLnCc8V5Igi-V5_HaNm6GTpEU8B4"); // Unique ID for the 'Responses' spreadsheet
  var sheet = ss.getActiveSheet();

  if ( sheet.getRange('J2').getValue() == "" ){
    sheet.getRange('I1').setValue("Sent");  // Initialize labels
    sheet.getRange('J1').setValue("Count");
    sheet.getRange('K1').setValue("Email body");
    sheet.getRange('L1').setValue("HTML body");
    var row = 2;
  } else {
    var row = sheet.getRange("J2").getValue() + 2;
  }
  while ( (sheet.getRange(row,9).getValue() != '') && (sheet.getRange(row,2).getValue() != '')) {
    var email = sheet.getRange(row, 2).getValue();
    send(sheet, email, row);
    row += 1;
  }
}

1 个答案:

答案 0 :(得分:1)

你不能写这样的一行:(2 x +=在同一个声明中)

body += '\n' + body += '\n' + sheet.getRange(temp + 1,11); // this throws the error

我建议使用这样的中间变量:

 var xxx = '\n' + sheet.getRange(temp + 1,11);
 body+= '\n'+ body + xxx ;

如果这真的是你想做的......但我觉得这很奇怪......

不应该是这样的:body+= '\n'+sheet.getRange(temp + 1,11);