【发布时间】:2020-04-21 19:38:15
【问题描述】:
有谁知道在从谷歌表格发送电子邮件时如何在脚本或单元格公式中自定义电子邮件正文的格式?
代码如下:
// has been sent successfully.
var EMAIL_SENT = 'EMAIL_SENT';
/**
* Sends non-duplicate emails with data from the current spreadsheet.
*/
function sendEmails2() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 1000; // Number of rows to process
// Fetch the range of cells A2:D1000
var dataRange = sheet.getRange(startRow, 1, numRows, 1000);
// 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 subject = row[3]; // Second column
var message = row[3]; // Third column
var emailSent = row[3]; // Fourth column
if (emailSent !== EMAIL_SENT) { // Prevents sending duplicates
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 4).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}
【问题讨论】:
-
@BigBen 编辑了正确的照片。对此感到抱歉。
-
我必须为我糟糕的英语水平道歉。不幸的是,我无法理解
customize the format of an email body in a script or within the cell formula和您的 2 张图片。我可以问你问题的细节和你的目标吗? -
不确定应该如何格式化。你的意思是换行吗?您能否分享您正在处理的电子表格,以便可以看到原始数据格式?
-
@lamblichus 这是表格:docs.google.com/spreadsheets/d/…
标签: email google-apps-script google-sheets