[英]how to have google form data emailed with bold text
I am currently using the following script to have google spreadsheet email my google form responses to me. 我目前正在使用以下脚本来让Google电子表格通过电子邮件将我的Google表单回复发送给我。 All the text in the email is plain text, but I would like the headers to be bold text. 电子邮件中的所有文本均为纯文本,但我希望标题为粗体。 I have tried several variations of adding the java command for bold text into the code to accomplish this but I am basically guessing since I have zero code writing experience. 我尝试了几种将粗体文本的java命令添加到代码中来完成此操作的方法,但是我基本上是在猜测,因为我的代码编写经验为零。 Is it possible and how should my script look to succeed? 我的脚本有可能成功吗? Thank you. 谢谢。
function sendFormByEmail(e) {
var emailSubject = "MOD Report";
// Set with your email address or a comma-separated list of email addresses.
var yourEmail = "xxxx@xxxx.com";
// Set with your spreadsheet's key, found in the URL when viewing your spreadsheet.
var docKey = "xxxx-xxxx-xxxx-xxxx";
// If you want the script to auto send to all of the spreadsheet's editors, set this value as 1.
// Otherwise set to 0 and it will send to the yourEmail values.
var useEditors = 0;
// Have you added columns that are not being used in your form? If so, set this value to
// the NUMBER of the last column that is used in your form.
// for example, Column C is the number 3
var extraColumns = 0;
if (useEditors) {
var editors = DocsList.getFileById(docKey).getEditors();
if (editors) {
var notify = editors.join(',');
} else var notify = yourEmail;
} else {
var notify = yourEmail;
}
// The variable e holds all the submission values in an array.
// Loop through the array and append values to the body.
var s = SpreadsheetApp.getActive().getSheetByName("FormResponses1");
if (extraColumns){
var headers = s.getRange(1,1,1,extraColumns).getValues()[0];
} else var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var message = "";
for(var i in headers) {
message += headers[i] + ' = '+ e.values[i].toString() + '\n\n';
}
MailApp.sendEmail(notify, emailSubject, message);
}
You need to use the htmlBody advanced parameter. 您需要使用htmlBody高级参数。
Google Documentation - Class MailApp Google文档-MailApp类
Note: the HTML bold tags: <b>text here</b>
注意:HTML粗体标签: <b>text here</b>
function sendEmail() {
var message = "This is <b>the</b> message";
MailApp.sendEmail({
to: "theEmail@example.com",
subject: "This is the subject line",
htmlBody: "<br>" +
"inline text" +
message,
});
}
You need to replace this snippet: 您需要替换以下代码段:
for(var i in headers) {
message += headers[i] + ' = '+ e.values[i].toString() + '\n\n';
}
MailApp.sendEmail(notify, emailSubject, message);
with this: 有了这个:
for(var i in headers) {
message += "<b>" + headers[i] + '</b> = '+ e.values[i].toString() + '<br>';
}
MailApp.sendEmail(notify, emailSubject, "", {htmlBody:message});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.