在脚本编辑器中添加多行主体

时间:2017-07-25 14:14:49

标签: google-apps-script google-sheets

我目前正在电子表格中使用以下代码发送电子邮件。

// This constant is written in column C for rows for which an email
// has been sent successfully.
var EMAIL_SENT = "EMAIL_SENT";

function sendEmails2() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2;  // First row of data to process
  var numRows = 2;   // Number of rows to process
  // Fetch the range of cells A2:B3
  var dataRange = sheet.getRange(startRow, 1, numRows, 3)
  // Fetch values for each row in the Range.
  var data = dataRange.getValues();
  for (var i = 0; i < data.length; ++i) {
    var row = data[i];
    var emailAddress = row[0];  // First column
    var message = row[1];       // Second column
    var emailSent = row[2];     // Third column
    if (emailSent != EMAIL_SENT) {  // Prevents sending duplicates
      var subject = "Sending emails from a Spreadsheet";
      MailApp.sendEmail(emailAddress, subject, message);
      sheet.getRange(startRow + i, 3).setValue(EMAIL_SENT);
      // Make sure the cell is updated right away in case the script is interrupted
      SpreadsheetApp.flush();
    }
  }
}
In the above the message is only being processed from a single cell while i want it to use multiple cells. 

实施例: the second column contains the body to be sent

我怎么能调整它。

2 个答案:

答案 0 :(得分:2)

将邮件放在单个单元格中,并根据需要在该单元格中对其进行格式化。即如果你想跳过一行或2按住控制并按回车键,光标将转到下一行。 enter image description here

获取脚本中的单元格。 enter image description here

发送电子邮件时,格式将被保留。 enter image description here

答案 1 :(得分:0)

您还可以在脚本消息上使用'\ n \ n'来跳过行。