javascript - 如何在 Google 脚本中设置文本格式,以便在发送电子邮件时显示?

标签 javascript html google-apps-script formatting

我一直在尝试编辑一个必须将某些文本加粗的脚本。该脚本从 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/

相关文章:

javascript - Google Script API 理解

javascript - 如果处理程序在同级组件上调用 setState,则 react 表单 event.preventDefault() 不起作用

javascript - 使用 Angular 获取列表中每个 li' 的 x 和 y 位置

html - CSS:具有半流体中心的三列布局

javascript - 如何从保存的 base64 图像中裁剪未使用的 Canvas 空间?

javascript - 单引号 Google 脚本的串联

google-app-engine - e.response.getId().getEditResponseUrl();在 Google Apps 脚本中不起作用

javascript - 粘性页脚 CSS 不工作

javascript - 阻塞 javascript 执行直到响应完成

html - 单击按钮清除文本字段