[英]How do you add google sheet cell data into an html-email using Google Scripts for Sheets?
I'm working on a script add-on for Sheets to send an invoice. 我正在为Sheets发送发票发送脚本。 I'd like to take data from a cell and add it directly into an html chart and then email this to clients.
我想从单元格中获取数据并将其直接添加到html图表中,然后通过电子邮件将其发送给客户端。 I'm having difficulty getting the data from the cell into the html chart.
我很难将数据从单元格获取到html图表中。
I've built [with the help of this community] a script that can send an html chart from Sheets into an email. 我已经建立了一个[可以在这个社区的帮助下]脚本,可以将表格中的html图表发送到电子邮件中。 However, the cell values never come out properly in the email [after I add them into the HTML format].
但是,单元格值永远不会在电子邮件中正确显示出来(在将它们添加为HTML格式之后)。
function composeChart() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[1] var data = sheet.getRange(4,2); var date = data.getValues(); //var chartComplete = titleChart+date+TD+date+TD+TR+endChart; var html2 = '<body>' + '<h2> Test </h2><br />' + '<p> Greetings Earthling </p>' + '<TABLE>'+ '<TR>'+ data +'</TD>'+ '<TD>' + data + '</TD>'+ '</TR>'+ '<TR>'+ '<TD>Data 3</TD>'+ '<TD>Data 4</TD>'+ '</TR>'+ '<TR>'+ '<TD>Data 5</TD>'+ '<TD>Data 6</TD>'+ '</TR>'+ '</TABLE>'+ '</body>' testMailApp3(html2, data); } function testMailApp3(html2, data) { MailApp.sendEmail( 'bakukai@gmail.com', // recipient 'test MailApp DATA', // subject 'TEST'+data, { // body htmlBody: html2 // advanced options } ); }
I'd like the chart to look like this [ideally with simple borders, not shown below]: 我希望图表看起来像这样[理想情况下带有简单的边框,下面未显示]:
DATE 4/5 4/12 4/19 4/26
AMOUNT 231 213 424 213
var sheet = ss.getSheets()[0]
. var sheet = ss.getSheets()[0]
。 date
- in a 2-dimensional array. date
-二维数组。 getRange(4,2)
I undestand that all your data is contained in the single cell B4
. getRange(4,2)
我无法理解您的所有数据都包含在单个单元格B4
。 In this case you need to convert the content of the 2-dimensional array date
to a string and split your string into substrings, eg var stringArray=date[0][0].toString().split(" ");
date
的内容转换为字符串并将字符串拆分为子字符串,例如var stringArray=date[0][0].toString().split(" ");
- provided the entries are separated by spaces stringArray
stringArray
数组元素 '<TR>'+ stringArray[0] +'</TD>'+ '<TD>' + stringArray[1] + '</TD>'...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.