【发布时间】:2021-06-10 07:07:47
【问题描述】:
谁能指导我,我尝试了很多不同的方法,但无法找出问题。
<!DOCTYPE html>
<html>
<body>
<head>
<base target="_top">
</head>
<body style="font-family:roboto,light,300;font-size:14px;font-style:normal;">
<div >
<p>
Hi there,<br/><br/>
The following case requires to be process.<br/>Please have a look and update the spreadsheet, click here to open: <br/>
https://docs.google.com/spreadsheets/d/1hPfBxMpXABG09cPOvzAQu0SDZLf-TSUTvv4_02BA8HE/edit#gid=0 <br/>
</p>
</div>
</body>
<head>
<style>
table {width:75%;}
table, th, td
{
border: 1px solid black;
border-collapse: collapse;
}
th, td
{
padding: 14px;
text-align: left;
}
#t01 tr:nth-child(even)
{
background-color: #eee;
}
#t01 tr:nth-child(odd)
{
background-color: #fff;
}
#t01 th
{
background-color: #3e8cbd;
color: white;
}
</style>
</head>
<body>
<table id="t01">
<tr>
<th width="100" scope="col" >Status</th>
<th scope="col" >Language</th>
<th scope="col" >P/R</th>
<th scope="col" >DJID F-Code</th>
<th scope="col" >Deadline</th>
</tr>
<tr>
<td><?= subVals[0][1] ?></td>
<td><?= subVals[0][5] ?></td>
<td><?= subVals[0][6] ?></td>
<td><?= subVals[0][7] ?></td>
<td><?= deadline ?></td>
</tr>
</table>
</body>
<body>
<br/>
<head>
<base target="_top">
</head>
<body style="font-family:roboto,light,300;font-size:14px;font-style:normal;">
<div >
<p> Should you have any questions or doubts please reach out to us: xxxxxx@gmail.com <br/> <br/> Best Regards, </p>
</div>
</body>
</html>
- 我想用在谷歌表格中提交的所有新项目(行)向不同的接收者发送电子邮件。 到目前为止,当我运行脚本时,只会发送 1 行,row3。对于要发送的“所有包含数据的行”,我缺少哪一部分?
- 从“后台”选项卡将电子邮件添加到分发列表,其中包含收件人电子邮件列表,运行时没有错误,但不会向人员列表发送电子邮件。我想这里缺少什么?
[![enter image description here][3]][3]
function sendEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet(),
sheet = ss.getSheetByName('ESCALATION'); //Code running off "ESCALATION" tab
var row = 3;
subVals = sheet.getRange(row, 1, 1, 22).getValues(),
deadline = sheet.getRange(3, 13).getDisplayValue(), //Gets display value of deadline date to pass to html file due to time/date formatting
subject = "Escalations Report"; //Create subject variable
var template = HtmlService.createTemplateFromFile('Email Table'); //Create template of html file
template.subVals = subVals; //Send subVals variables to template so can reference in html using scriplets
template.deadline = deadline; //Send deadline variable to template so can reference in html using scriplets
var html = template.evaluate().getContent(); //Evalutate and create html output
var sendto = "xxxxxx@gmail.com"; //Test send Email only to myself
// Add Email to Distribution List > is not working!!???
var BACKsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Backstage"); // "Backstage" tab with a list of recipience email
var columnValues = BACKsheet.getRange(1, 10, BACKsheet.getLastRow()).getValues(); //1st is header row
GmailApp.sendEmail(sendto, subject, '', {htmlBody:html}); //send email with recipients from subVals and options set htmlBody to html variable we created
}
【问题讨论】:
-
您的代码包含以下行:` var row = 3; subVals = sheet.getRange(row, 1, 1, 22).getValues()` - 所以您只从该行检索值。如果您还对其他行感兴趣,则需要相应地循环遍历它们 - 显示您的电子表格(或它的屏幕截图)并更详细地描述您要完成的工作会有所帮助。
-
除了上面的评论,更具体地说,
sheet.getRange(row, 1, 1, 22).getValues()表示您要求从第 3 行和第 1 列开始收集总共 1 行和 22 列的值。您的电子邮件分发列表与.getLastRow()有正确的想法,但您需要稍作调整。在您的分发列表构建中:那里什么都没有。您所做的就是获取第 1 列值的数组。收件人必须是逗号分隔的字符串,而不是数组。 -
@ziganotschka 我添加了我的电子表格的屏幕截图。请您看一下并指导我。非常感谢!
-
我确实尝试了不同的方法(1 和 2),但都没有奏效。例如,而不是`var row = 3; subVals = sheet.getRange(row, 1, 1, 22).getValues()` : 1. //lastRow = sheet.getLastRow(); //subVals = sheet.getRange(sheet.getLastRow(), 1, 1 ,22).getValues(); // 测试有数据的最后一行 2. // subVals = sheet.getRange(lastRow -1 , 1, 1 ,22).getValues(); // 测试有数据的最后一行 //lastRow-1
-
当你说
I'd like to sendEmail to the different receivers with all NEW ITEM (rows) that are submitted in google sheet提交是什么意思。您是在谈论表单提交吗?
标签: function email google-apps-script datatable range