简体   繁体   English

来自 Gsheet 的 html 文件中的 Google Apps 脚本动态项目符号列表

[英]Google Apps Script dynamically bulleted list in an html file from Gsheet

I would like to create a dynamically bulleted list in an html file from a google apps-script with variable.我想从带有变量的谷歌应用程序脚本的 html 文件中创建一个动态项目符号列表。 and for this I would like to have some helps as I'm really new on this.为此,我想得到一些帮助,因为我对此很陌生。 at this moments mail email as fixed op[x] variables therefore if they are empty I have empty bullet list.此时将 email 邮件作为固定 op[x] 变量,因此如果它们为空,我有空的项目符号列表。

I have the function called luli I have variables in an array call operation expecting to be the bulleted list actually I have also created a countable variable of the sum of them我有一个名为 luli 的luli我在数组调用操作中有变量,期望成为项目符号列表实际上我还创建了它们之和的可数变量

luli.gs luligs

function luli() {
  var emailTemp = HtmlService.createTemplateFromFile('INTERVENTION-EMAIL');
  var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Template Creation');
  // for bulleted list
  var operation = ws.getRange('B27:B32').getValues();
  var i = ws.getRange('$B$33').getValue();
  // used at the moment
  var op1 = wsSettings.getRange('$B$27').getValue();
  var op2 = wsSettings.getRange('$B$28').getValue();
  var op3 = wsSettings.getRange('$B$29').getValue();
  var op4 = wsSettings.getRange('$B$30').getValue();

  //email variables used at the moment
  emailTemp.op1 = op1;
  emailTemp.op2 = op2;
  emailTemp.op3 = op3;
  emailTemp.op4 = op4;

  var htmlMessage = emailTemp.evaluate().getContent();

  GmailApp.createDraft(
    mail,
    sujet,

    //send  message generated htmlbody & htmlmessage built.
    { name: nom, htmlBody: htmlMessage, cc: cc, from: from },
  );
}

I have an email template called intervention-email我有一个名为干预电子邮件的 email 模板

intervention-email.html干预电子邮件.html

<p dir="ltr">
  <span style="font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif"
    ><?= corps1 ?></span
  >
</p>
<ul style="list-style-type: square">
  <li dir="ltr">
    <span
      style="
        font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif;
        font-size: 10pt;
      "
      ><?= op1 ?></span
    >
  </li>
  <li dir="ltr">
    <span
      style="
        font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif;
        font-size: 10pt;
      "
      ><?= op2 ?></span
    >
  </li>
  <li dir="ltr">
    <span
      style="
        font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif;
        font-size: 10pt;
      "
      ><?= op3 ?></span
    >
  </li>
  <li dir="ltr">
    <span
      style="
        font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif;
        font-size: 10pt;
      "
      ><?= op4 ?></span
    >
  </li>
</ul>
<p>&nbsp;</p>

It will be nice to have a code generating the li bulleted list according to the information contenned in the operation variable then populating the email list.最好有一个代码根据操作变量中包含的信息生成 li 项目符号列表,然后填充 email 列表。 Thank you for your help.谢谢您的帮助。

You can push your variables into an array (or directly retrieve them as an array) and then pass the array to the template您可以将变量推送到数组中(或直接将它们作为数组检索),然后将数组传递给模板

Sample样本

Code.gs代码.gs

...
var values = wsSettings.getRange('B27:B30').getValues().flat();
emailTemp.options = values;
var htmlMessage = emailTemp.evaluate().getContent();
...

intervention-email.html干预电子邮件.html

...
<ul style="list-style-type: square">
<? for (var i = 0; i < options.length; i++) { ?>
  <li dir="ltr">
    <span style="font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif; font-size: 10pt;">
      <?= options[i] ?>
    </span>
  </li>
<? } ?>
</ul>
...

See documentation .请参阅文档

暂无
暂无

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

相关问题 来自 Gsheet 的 html 文件中的 Google Apps 脚本动态表格行 - Google Apps Script dynamically table row in an html file from Gsheet Google Apps脚本中的强行换行(带有Google Form字段的Google文档可在项目符号列表中创建新项目符号) - Hard Line Break in Google Apps Script (Google Docs with Google Form Field to create new bullet in bulleted list) 如何在Google Apps脚本中使用Gsheet文件的名称获取ID - How to I get the ID of a Gsheet file by using its name in google apps script 从 google 应用程序脚本中的 html 文件调用 javascript 函数 - Call javascript function from html file in google apps script 如何从外部 Html 文件获取 Google Apps 脚本中的 ElementById? - How to getElementById in Google Apps Script from external Html file? 将数组从 javascript(Google Apps 脚本)添加到 html 文件 - Add array to a html file from javascript (Google Apps Script) Google Apps脚本-将来自应用脚本功能的输出返回给html文件javascript函数 - Google Apps Script - return output from apps script function back to the html file javascript function Google Apps脚本WebApp将html传递到文件 - Google Apps Script WebApp Pass html to file 在Google Apps脚本Web应用中使用Google Visualization API显示GSheet范围时出错 - Error showing GSheet range using Google Visualization API in Google Apps Script Web App 从Google Apps脚本创建HTML页面 - create html page from google apps script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM