简体   繁体   English

如何使用电子表格中的表格填充 HTML 表格?

[英]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

  1. You want to create a HTML table from the values retrieved from the active Spreadsheet, and want to send it as the HTML body using Google Apps Script.您想根据从活动电子表格中检索到的值创建一个 HTML 表,并希望使用 Google Apps 脚本将其作为 HTML 正文发送。
  2. You want to run the script by the time-driven trigger.您希望通过时间驱动触发器运行脚本。

If my understanding is correct, how about this answer?如果我的理解是正确的,这个答案怎么样? Please think of this as just one of several possible answers.请将此视为几种可能的答案之一。

Answer for Q1:回答 Q1:

When your script is modified, it becomes as follows.当你的脚本被修改时,它变成如下。

Modified script:修改后的脚本:

From: 从:
 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});
  • In this case, 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.在这种情况下,当邮件程序无法读取 HTML 正文时,将显示文本正文。

Answer for Q2:回答 Q2:

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.关于这一点,请根据您的实际情况进行设置。

References:参考:

If I misunderstood your question and this was not the direction you want, I apologize.如果我误解了您的问题并且这不是您想要的方向,我深表歉意。

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

相关问题 如何从HTML表格导出到Excel电子表格? - How do I export from an HTML table to an excel spreadsheet? 我需要使用带有奇怪的 Google 电子表格链接的 Javascript 创建一个 HTML 表格。 我该怎么做呢? - I need to create an HTML table using Javascript with a weird Google Spreadsheet link. How do I do this? 如何从电子表格显示时间戳到 html 表 - How to display timestamp from spreadsheet to html table 如何使用 JavaScript 创建和填充 HTML 表格 - How can I create and populate an HTML table using JavaScript 如何使用 javascript 填充由 Django 创建的 HTML 表? - How can I populate an HTML table created by Django using javascript? 如何使用来自 URL 的 JSON 数据集填充 HTML 表 - How to populate a HTML table using a JSON dataset from an URL 如何从存储在我 PC 上的文件中获取 XML 数据并使用 javascript 以 HTML 格式填充表格? - How can I fetch XML Data from a file stored on my PC and populate a table in HTML using javascript? 如何使用来自JSON文件的Ajax请求填充表格 - How do I populate a table with an ajax request from a JSON file 如何获取要从JSON数据填充的表行? - How do I get table rows to populate from JSON data? 如何从JavaScript对象填充HTML表? - How to populate an HTML table from JavaScript Object?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM