[英]Highlighting text in a google sheet cell using HTML and google apps script
[英]Wrap text using input from Google Sheet (Google Apps Script)
我有一个脚本,可以从Google表格中的单元格内容生成自动电子邮件。 是否可以限制电子邮件中单元格输出的宽度,从而迫使文本自动换行? 我尝试使用textarea标签,如下所示:
+ <textarea rows="4" cols="20">
+ sheet.getRange(6,9,1,1).getValue()
+ </textarea>
但是,这只是输出为“ + sheet.getRange(6,9,1,1).getValue()+”(即,它不会生成单元格内容)。
这可能吗?
这是我构建脚本的方式:
function EmailFormConfirmation() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
Utilities.sleep(60000);
var sheet = ss.getSheetByName("Form responses");
var lock = LockService.getPublicLock();
lock.waitLock(60000);
lock.releaseLock();
var email = sheet.getRange(2,9,1,1).getValue();
var message = "<HTML><BODY>"
+ "<P >Hi "
+ sheet.getRange(4,9,1,1).getValue()
+ ","
etc.
编辑下面将产生单元格内容,但不包装文本。
var htmlMsg = "<HTML><BODY>"
+ "<textarea rows='4' cols='10'>"
+ sheet.getRange(6,9,1,1).getValue()
+ "</textarea>"
+ "</HTML></BODY>";
MailApp.sendEmail(email, "LMI Request", "", {htmlBody: htmlMsg});
要回答问题re:文本框,请按照您的要求进行以下操作
var htmlMsg = "<HTML><BODY>"
+ "<textarea rows='4' cols='20'>"
+ sheet.getRange(6,9,1,1).getValue()
+ "</textarea>"
+ "</BODY></HTML>";
GmailApp.sendEmail("m....l@gmail.com", "subject","hi" , {htmlBody: htmlMsg});
请注意如何使用单引号和双引号。
这是如何使用模板构建电子邮件回复的示例。 可以在以下位置找到该文档: https : //developers.google.com/apps-script/guides/html/templates
在code.gs中
function myFunction(){
var sheet = SpreadsheetApp .....
var value = sheet.getRange(6,9,1,1).getValue();
var emailHtml = buildTemplate(value);
GmailApp.sendEmail("person@example.com", "subject","Hello", {htmlBody: emailHtml});
}
function buildTemplate(values){
var template = HtmlService.createTemplateFromFile('emailTemplate');
template.tmpValues = values;
return template.evaluate().getContent();
}
在emailTemplate.html中
<html>
<body>
<textarea rows='4' cols='20'>
<?=tmpValues?>
</textarea>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.