2017-05-30 70 views
0

Google表格中的換行符您好,我是Google Apps腳本的新手。我有一個6列和1行的谷歌表,將插入更多,一旦我可以讓它運行如何使用(GAS)

我的目標是發送自我的電子郵件列表中的電子郵件從我的列1。將在第2-6列的電子郵件中發送,我已經設法發送電子郵件,但它一起亂放。

是否有人知道要編寫哪些代碼才能使每個列的下一行顯示正常的電子郵件,並在列之前添加「您的學生」之類的文本?

這是我

function sendEmails() { 
    var sheet = SpreadsheetApp.getActiveSheet(); 
    var startRow = 2; // First row of data to process 
    var numRows = 1; // Number of rows to process 
    // Fetch the range of cells A1:F2 
    var dataRange = sheet.getRange(startRow, 1, numRows, 5) 
    // Fetch values for each row in the Range. 
    var data = dataRange.getValues(); 
    for (i in data) { 
    var row = data[i]; 
    var emailAddress = row[0]; // First column 
    var message = "Hello your Student" + row[1] 
    **" Has done a marvelous job in Class" + row[2] 
    " His new area to grow involves" + row[3]+ row [4]+ row [5] ;** 
    var subject = "Report for your Student"; 
    MailApp.sendEmail(emailAddress, subject, message); 

} }

什麼是出演是沒有看到的電子郵件,也許是因爲它的下一行,我不知道該怎麼代碼來介紹它仍然繼續下去,並在電子郵件中使用空格。由於

回答

0
var message = "Hello your Student" + row[1] 
    + " Has done a marvelous job in Class" + row[2] 
    + " His new area to grow involves" + row[3]+ row [4]+ row [5] ; 

,或者如果你需要換行

var message = "Hello your Student" + row[1] + '\n' 
    + " Has done a marvelous job in Class" + row[2] + '\n' 
    + " His new area to grow involves" + row[3]+ row [4]+ row [5] ; 
0

使用HTML,您可以添加休息和或其他格式,如粗體。

function sendEmails() { 
 
    var sheet = SpreadsheetApp.getActiveSheet(); 
 
    var startRow = 2; // First row of data to process 
 
    var numRows = 1; // Number of rows to process 
 
    // Fetch the range of cells A1:F2 
 
    var dataRange = sheet.getRange(startRow, 1, numRows, 5) 
 
    // Fetch values for each row in the Range. 
 
    var data = dataRange.getValues(); 
 
    for (i in data) { 
 
    var row = data[i]; 
 
    var emailAddress = row[0]; // First column 
 
    var myMessage = "<b>Hello your Student</b> " + row[1] + " <br> Has done a marvelous job in Class" + row[2] + "<br> His new area to grow involves:" + "<br>" + row[3] + "<br>" + row [4] + "<br>" + row [5] ; 
 
    var subject = "Report for your Student"; 
 
    MailApp.sendEmail(emailAddress, subject, 'text Body',{htmlBody: myMessage}); 
 
    }}