How do I format my text in Google Script, for it to show when I send an email?

烂漫一生 提交于 2021-01-28 02:51:39

问题


I have been trying to edit a script that I have to bold certain text. This script pulls information from a Google Form Spreadsheet and returns an email that looks like this:


Teacher Engagement: At initial observation, the teacher is appropriately engaged (Direct Instruction, Modeling, Constructing Knowledge, Guided/Independent Practice, etc.)

Technology Integration: No evidence of technology use or integration


I would like for the headers "Teacher Engagement:" & "Technology Integration" to be Bold and maybe underlined.How can I implement HTML into my code?

My code is:

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"});
}

回答1:


The only viable solution to format an E-mail with the MailApp is to use the HTMLbody option and to write your texte as HTML.

example :

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"
});
}

result :

Below are the results of a recent Walkthrough: 

Teacher Engagement: 
stuff

Technology Integration: 
other stuff


来源:https://stackoverflow.com/questions/31663006/how-do-i-format-my-text-in-google-script-for-it-to-show-when-i-send-an-email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!