[英]How do I populate an HTML table using a table from a spreadsheet?
So I have a simple 4 column table with rows that will be added by a function.所以我有一个简单的 4 列表,其中的行将由函数添加。 I'd like to create and html body that will include a table and be emailed out 3 times per week using google script.
我想创建一个包含表格的 html 正文,并使用 google 脚本每周通过电子邮件发送 3 次。 I am able to get the data out of the spreadsheet and into a variable.
我能够将数据从电子表格中取出并放入一个变量中。 The problem is that I can't make it into a darn table, I know this is probably a simple solution but I am quite new to google script.
问题是我不能把它变成一个糟糕的表,我知道这可能是一个简单的解决方案,但我对谷歌脚本很陌生。 This is my script;
这是我的脚本;
function emailsLeanKitchen() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var Sheet = ss.getSheetByName("Sheet1"); var dataTable = Sheet.getRange(1,1,Sheet.getLastRow(),4).getValues(); Logger.log(dataTable); GmailApp.sendEmail("my email","subject", dataTable);// }
And if Anyone Knows of a good way to set this script on a timer, that would be cool too because that's my next goal.如果有人知道在计时器上设置此脚本的好方法,那也会很酷,因为这是我的下一个目标。 I've attached a link to my spreadsheet.
我附上了一个链接到我的电子表格。 I appreciate any help!
我感谢任何帮助!
https://docs.google.com/spreadsheets/d/1X_UcqyXXRMyjZ2j46TymMrIMWvt19HOZTTaEUlIVqwE/edit?usp=sharing https://docs.google.com/spreadsheets/d/1X_UcqyXXRMyjZ2j46TymMrIMWvt19HOZTTaEUlIVqwE/edit?usp=sharing
If my understanding is correct, how about this answer?如果我的理解是正确的,这个答案怎么样? Please think of this as just one of several possible answers.
请将此视为几种可能的答案之一。
When your script is modified, it becomes as follows.当你的脚本被修改时,它变成如下。
GmailApp.sendEmail("my email","subject", dataTable);//
To:
var htmlTable = dataTable.reduce(function(s, e) { return s += "<tr><th>" + e.join("</th><th>") + "</th></tr>" }, "<table border=\\"1\\">") + "</table>"; GmailApp.sendEmail("my email","subject", "sample text body", {htmlBody: htmlTable});
htmlTable
is sent as the HTML body.htmlTable
作为 HTML 正文发送。 "sample text body"
is sent as the text body. "sample text body"
作为文本正文发送。 In this case, when the mailer cannot read the HTML body, the text body is shown. You can run the function emailsLeanKitchen()
with the time-driven event trigger.您可以使用时间驱动的事件触发器运行函数
emailsLeanKitchen()
。 You can see how to set the trigger at here .您可以在此处查看如何设置触发器。 In this case, from
3 times per week
of your question, "Week timer" might be suitable for "Select type of time based trigger".在这种情况下,从
3 times per week
您的问题开始,“周计时器”可能适用于“选择基于时间的触发器类型”。 About this, please set this for your actual situation.关于这一点,请根据您的实际情况进行设置。
If I misunderstood your question and this was not the direction you want, I apologize.如果我误解了您的问题并且这不是您想要的方向,我深表歉意。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.