[英]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
我在数组调用操作中有变量,期望成为项目符号列表实际上我还创建了它们之和的可数变量
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 模板
<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> </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.谢谢您的帮助。
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.