简体   繁体   English

使用Google表格中的输入来换行(Google Apps脚本)

[英]Wrap text using input from Google Sheet (Google Apps Script)

I have a script that produces an automated email from cell content in a Google Sheet. 我有一个脚本,可以从Google表格中的单元格内容生成自动电子邮件。 Is it possible to restrict the width of a cell's output in the email, forcing the text to wrap? 是否可以限制电子邮件中单元格输出的宽度,从而迫使文本自动换行? I have tried using textarea tags as follows: 我尝试使用textarea标签,如下所示:

+ <textarea rows="4" cols="20">

+ sheet.getRange(6,9,1,1).getValue()   

+ </textarea>

However, this simply outputs as "+ sheet.getRange(6,9,1,1).getValue() +" (ie it doesn't generate the cell content). 但是,这只是输出为“ + sheet.getRange(6,9,1,1).getValue()+”(即,它不会生成单元格内容)。

Is this possible? 这可能吗?

Here's how I have built the script: 这是我构建脚本的方式:

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.

EDIT The below produces the cell content, but doesn't wrap the text. 编辑下面将产生单元格内容,但不包装文本。

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

To respond to the question re: textbox, the following did as you requested 要回答问题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});

note how the single and double quotes are used. 请注意如何使用单引号和双引号。

Here is an example of how you can use templates to build your email responses. 这是如何使用模板构建电子邮件回复的示例。 The documentation can be found here: https://developers.google.com/apps-script/guides/html/templates 可以在以下位置找到该文档: https : //developers.google.com/apps-script/guides/html/templates

In code.gs 在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();
}

in emailTemplate.html 在emailTemplate.html中

<html>
  <body>
       <textarea rows='4' cols='20'>
         <?=tmpValues?>
       </textarea>
  </body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM