我有一個腳本向收件人串列發送 HTML 格式的電子郵件:
<!-- Greeting section START -->
<td width="100%" valign="top">
<h1 style="font-size: 18px; line-height: 26px; margin: 0;">Hi there,</h1>
<p style="margin: 0;"> <br />Please provide the weekly status report by Monday, CoB: <br /> </p>
<p style="margin: 0;">
<?= project ?>
<br /> </p>
<p style="margin: 0;"> Should you have any questions or experience difficulties, reach out to me.<br /> </p>
<h1 style="font-size: 18px; line-height: 28px; margin: 0;">Best regards,</h1>
<h1 style="font-size: 16px; line-height: 24px; margin: 0;">PMO Team</h1>
</td>
<!-- Greeting section END -->
代碼中的參考從各個列(htmlBody.project = row[3])獲取資料:
function sendEmailForm() {
var htmlBody = HtmlService.createTemplateFromFile('mail_template');
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("T_TEST");
var startRow = 2; // First row of data to process
var numRows = 70; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, 11);
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i in data) {
var row = data[i];
{
var emailAddress = row[0]; // First column
if (emailAddress.match('@') === null){
continue; // skip this iteration of the loop and go to the next one
};
var ccEmailAddress = row[1]
// var body = row[3]; // Second column
var subject = row[2];
htmlBody.project = row[3];
//htmlBody.survey = row[10];
var message = htmlBody.evaluate().getContent();
//var body = email_html;
var aliases = GmailApp.getAliases()
Logger.log(aliases); //returns the list of aliases you own
Logger.log(aliases[1])
GmailApp.sendEmail(emailAddress, subject, message, {htmlBody : message, cc: ccEmailAddress,'from': aliases[1]});
}
}
}
但是,這些單元格中的資料按段落組織,例如:專案 1 專案 2 專案 3
我在電子郵件中實際收到的是:專案 1 專案 2 專案 3
有沒有辦法在電子郵件中保留單元格格式?提前感謝您的幫助
uj5u.com熱心網友回復:
那么,作為一個簡單的修改,下面的修改呢?
修改后的腳本:
請sendEmailForm()進行如下修改。
從:
htmlBody.project = row[3];
到:
htmlBody.project = row[3].replace(/\n/g, "<br>");
另外,請按如下方式修改 HTML。
從:
<?= project ?>
到:
<?!= project ?>
- 通過上述修改,
Project 1\nProject 2\nProject 3在一個單元格中轉換為Project 1<br>Project 2<br>Project 3并使用<?!= project ?>.
參考:
- 強制列印腳本
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/418087.html
標籤:
上一篇:GoogleSheet:如果單元格為空,則顯示第一個資料驗證值
下一篇:從谷歌表格上的幾個條件中得到結果
