如何通过电子邮件发送带有粗体文本的 Google 表单数据
how to have google form data emailed with bold text
我目前正在使用以下脚本让谷歌电子表格通过电子邮件将我的谷歌表单回复发送给我。 电子邮件中的所有文本都是纯文本,但我希望标题是粗体文本。 我已经尝试了几种将粗体文本的java命令添加到代码中以完成此操作的变体,但我基本上是在猜测,因为我的代码编写经验为零。 是否有可能,我的脚本应该如何成功? 谢谢。
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);
}
您需要使用 htmlBody 高级参数。
谷歌文档 - 类邮件应用程序
下面是一些示例代码:
注意: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,
});
}
您需要替换此代码片段:
for(var i in headers) {
message += headers[i] + ' = '+ e.values[i].toString() + ''n'n';
}
MailApp.sendEmail(notify, emailSubject, message);
有了这个:
for(var i in headers) {
message += "<b>" + headers[i] + '</b> = '+ e.values[i].toString() + '<br>';
}
MailApp.sendEmail(notify, emailSubject, "", {htmlBody:message});
相关文章:
- 如何在Google Geochart图表的工具提示文本中添加新行
- 创建包含文本内容的新 Google 云端硬盘文件 (javascript)
- 将JS变量作为文本返回以发送到Google Analytics
- 将文本设置为google+共享按钮
- 设置“;将标签视为文本“;通过脚本将Google电子表格图表的值设置为true
- 文本框值更改 Google 地图上的更新标记
- 如何通过电子邮件发送带有粗体文本的 Google 表单数据
- 当页面上存在特定文本字符串时发送 Google Analytics(分析)事件
- Google 文档如何实现富文本编辑
- 如何通过表单提交在 Google 应用脚本中设置粗体文本
- 如何使用 Google 云端硬盘实时 API 实现协作式富文本编辑
- 使用带有动态文本框的 Google 地方信息自动完成功能
- 如何为 Google 放置 API 自动完成文本框设置默认值
- 将文本替换为图片 Google 脚本
- 在 Google 文档中创建彩虹文本
- 角度.js - Google 自动完成事件触发时的清除文本框
- 如何将文本从 Google 电子表格中的多个单元格提取到网站,每个单元格都位于不同的
标签中
- com.google.gwt.user.client.ui.FileUpload如何设置文本
- 处理上传的文本文件后,在Google云端硬盘中创建新的文档
- Google Apps脚本中Google文档中字符串的文本格式