我一直在尝试编辑一个必须将某些文本加粗的脚本。该脚本从 Google 表单电子表格中提取信息并返回如下所示的电子邮件:
教师参与度: 初步观察,教师适当参与(直接指导、建模、构建知识、指导/独立实践等)
技术整合: 没有技术使用或集成的证据
我希望标题“教师参与:”和“技术集成”为粗体并可能带有下划线。如何在我的代码中实现 HTML?
我的代码是:
function sendEmail() {
var sheet = SpreadsheetApp.getActiveSheet();
var row = sheet.getActiveRange().getRowIndex();
var userEmail = sheet.getRange(row,
getColIndexByName("Username")).getValue();
var body = "Below are the results of a recent Walkthrough: ";
body += "\n\nTeacher Engagement: \n" + sheet.getRange(row,
getColIndexByName("Teacher Engagement")).getValue();
body += "\n\nTechnology Integration: \n" + sheet.getRange(row,
getColIndexByName("Technology Integration")).getValue();
MailApp.sendEmail(userEmail, subject, body, {name:"Classroom Walkthrough"});
}
最佳答案
使用 MailApp 格式化电子邮件的唯一可行的解决方案是使用 HTMLbody 选项并将文本编写为 HTML。
示例:
function sendEmail() {
var sheet = SpreadsheetApp.getActiveSheet();
var row = sheet.getActiveRange().getRowIndex();
var userEmail = sheet.getRange(row,
getColIndexByName("Username")).getValue();
var body = "<HTML><BODY>"
+"Below are the results of a recent Walkthrough: "
+"<P>Teacher Engagement: <BR>"
+sheet.getRange(row,getColIndexByName("Teacher Engagement")).getValue()
+"</P>"
+"<P>Technology Integration: <BR>"
+sheet.getRange(row,getColIndexByName("Technology Integration")).getValue()
+"</P></BODY></HTML>";
MailApp.sendEmail({
to:userEmail,
subject:subject,
htmlBody:body,
name:"Classroom Walkthrough"
});
}
结果:
Below are the results of a recent Walkthrough:
Teacher Engagement:
stuff
Technology Integration:
other stuff
关于javascript - 如何在 Google 脚本中设置文本格式,以便在发送电子邮件时显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31663006/