【发布时间】:2020-07-06 10:01:53
【问题描述】:
我有一个代码可以读取谷歌表格并应该将数据带到 HTML 表中。
function Getdata(){
const ss= SpreadsheetApp.getActiveSpreadsheet();
const ws= ss.getSheetByName("Projects");
const headers= ws.getRange("A1:F").getValues();
const Project_State = headers[0][0];
const Start_Date = headers[0][1];
const End_Date = headers[0][2];
const Project_ID = headers[0][3];
const Project_Name = headers[0][4];
const Project_Code = headers[0][5];
const First_Name = headers[0][8];
const lr = ws.getLastRow();
const tableRangeValues=ws.getRange(2,1, lr-2).getDisplayValues();
const htmlTemplate = HtmlService.createTemplateFromFile("Notify")
htmlTemplate.Project_State= Project_State;
htmlTemplate.Start_Date= Start_Date;
htmlTemplate.End_Date= End_Date;
htmlTemplate.Project_ID= Project_ID ;
htmlTemplate.Project_Name=Project_Name;
htmlTemplate.Project_Code=Project_Code;
htmlTemplate.First_Name=First_Name;
htmlTemplate.tableRangeValues=tableRangeValues;
const htmlForEmail = htmlTemplate.evaluate().getContent();
MailApp.sendEmail({
to: Session.getActiveUser().getEmail(),
subject: 'Project End - Action Required',
htmlBody: htmlForEmail,
});
}
根据我所做的研究,我已经能够在通过电子邮件发送的 HTML 表中显示工作表的标题,但是我在将行数据从工作表捕获到 HTM 表时遇到了挑战。我不确定我的范围是否关闭,或者我错过了什么。问题是,我只能将第一列数据放入我的 HTML 表中。
这是我的 HTML 代码:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<title>Weekly Report</title>
</head>
<body style="padding:3em;">
<p>Hi Project Leader,</p>
<p>please see below for the latest updates on the projcets you manage.<br>
<br /> Team</p>
<div style=""background-color:blue; height:4px;></div>
<h3> Project Details </h3>
<table>
<thead>
<tr>
<th><?= Project_State ?></th>
<th><?= Start_Date ?></th>
<th><?= End_Date ?></th>
<th><?= Project_ID ?></th>
<th><?= Project_Name?></th>
<th><?= Project_Code ?></th>
</tr>
</thead>
<tbody>
<?tableRangeValues.forEach(r=>{?>
<tr>
<td><?=r[0]?></td>
<td><?=r[1]?></td>
<td><?=r[2]?></td>
<td><?=r[3]?></td>
<td><?=r[4]?></td>
<td><?=r[5]?></td>
</tr>
<?})?>
</tbody>
</table>
<br>
</body>
</html>
这是 google sheet 的结构。
【问题讨论】:
标签: javascript html arrays google-apps-script google-sheets