Google Apps脚本 - MailApp不适用于我的脚本

时间:2015-09-04 13:49:07

标签: google-apps-script google-sheets

对于草率的代码感到抱歉。我对此很陌生。我试图这样做,以便在点击Browser.Buttons.YES_NO时,当选择是时,它执行代码并发送带有预定消息的电子邮件。每当我尝试放入MailApp.sendEmail("email@gmail.com", "test", "test");时,就会破坏代码,导致代码无法执行。任何帮助将不胜感激。

function onEdit(event) {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var s = event.source.getActiveSheet();
    var r = event.source.getActiveRange();

    if(s.getName() == "to do" && r.getColumn() == 13 && r.getValue() == "yes") {  
      var confirm = Browser.msgBox("Mark this job as complete?", Browser.Buttons.YES_NO);

      if(confirm == "yes") { //I would like to put the MailApp inside this if statement 
        var row = r.getRow();
        var numColumns = s.getLastColumn();
        var targetSheet = ss.getSheetByName("done");
        var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
        s.getRange(row, 1, 1, numColumns).moveTo(target);
        s.deleteRow(row);
        return Browser.msgBox("File transferred", Browser.Buttons.OK); 
      }
   }
}

1 个答案:

答案 0 :(得分:0)

function onEdit(event) {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var s = event.source.getActiveSheet();
    var r = event.source.getActiveRange();

    if(s.getName() == "to do" && r.getColumn() == 13 && r.getValue() == "yes") {  
      var confirm = Browser.msgBox("Mark this job as complete?", Browser.Buttons.YES_NO);

      if(confirm == "yes") { //I would like to put the MailApp inside this if statement 
        var row = r.getRow();
        var numColumns = s.getLastColumn();
        var targetSheet = ss.getSheetByName("done");
        var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
        s.getRange(row, 1, 1, numColumns).moveTo(target);
        s.deleteRow(row);
        return Browser.msgBox("File transferred", Browser.Buttons.OK); 
      }
   }
}

你错过了开头大括号