下面的代碼確實獲得了表單回應,并使用格式如下的正文通過電子郵件發送它:
問題/標題 1
回應 1
問題/標題 2
回應 2
但是,創建的 pdf 將其全部顯示在一行中,如下所示:新回復表:問題/標題1 回應1 問題/標題2 Response2...
如何創建它,使其看起來像上面格式化的電子郵件正文?
function onFormSubmit(e) {
// Get the response that was submitted.
var formResponse = e.response;
// Get the items (i.e., responses to various questions)
// that were submitted.
var itemResponses = formResponse.getItemResponses();
// Create a variable emailBody to store the body
// of the email notification to be sent.
var emailBody = "New form response:\n\n";
// Put together the email body by appending all the
// questions & responses to the variable emailBody.
itemResponses.forEach(function(itemResponse) {
var title = itemResponse.getItem().getTitle();
var response = itemResponse.getResponse();
emailBody = title "\n" response "\n\n";
});
// Send the email notification using the
// sendEmail() function.
sendEmail(emailBody);
var folderID = "SOME_FOLDERID";
var intermediate = DriveApp.createFile('New Form Response','<b>' emailBody '</b>', MimeType.HTML);
var blob = intermediate.getAs(MimeType.PDF);
Logger.log(blob.getContentType());
var pdfFile = DriveApp.createFile(blob);
DriveApp.getFolderById(folderID).addFile(pdfFile)
DriveApp.getFileById(intermediate.getId()).setTrashed(true);
}
// A function that sends the email
// notification.
function sendEmail(emailBody) {
MailApp.sendEmail("EMAIL_ADDRESS", "New form response", emailBody);
}
uj5u.com熱心網友回復:
由于您在創建檔案時使用的是 HTML 型別,因此您需要<br>為新行使用標記emailBody。您可以使用
筆記:
- 您實際上可以
\n在 html 正文中用作換行符,但是您需要在 css 中設定它。請參閱HTML 中的換行符 '\n'
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/357754.html
標籤:javascript pdf 谷歌应用程序脚本 斑点
