首先,这是我第一次把关于电子签名的工作放在GMAIL ( html)中。我创建了简单的html并将其放入gmail中。它工作得很好
现在,我的目标是提取像姓氏、名字和职业(作为帐户google的功能)的数据,将它们放在HTML中,然后在gmail中(签名参数)。由于我对javascript等一无所知.,我在youtube上跟踪了解它是如何工作的(参见链接:"")。我收到一条错误消息“无法读取属性(getSheetByName 'of null”)。在我看来,表是空的。所以,我为空的情况添加了一个"if“部分。它仍然不能工作。
你能帮我修一下错误吗?
请提前感谢您的帮助。
由衷地
来自法国图卢兹的B.Delcroix
我的程序,见下文.
谷歌应用程序脚本:
function myFunction() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const ws = ss.getSheetByName('benevoles');
if (ws != null) {
Logger.log(ws.getIndex());
}
const h1 = ws.getRange("B3").getValue();
const subheader = ws.getRange("B4").getValue();
const headers = ws.getRange("B6;E6").getValues();
const initiale = headers[0][0];
const name = headers[0][1];
const prenom = headers[0][2];
const profession = headers[0][3];
const lr = ws.getLastRow();
const tableRangeValues = ws.getRange(7,2,lr-7,4).getValues();
const totalLine = ws.getRange(lr,2,1,4).getValues();
const totalTexte = totalLine[0][0];
const totalCount = totalLine[0][3];
const htmlTemplate = HtmlService.createTemplateFromFile("mail");
htmlTemplate.h1 = h1;
htmlTemplate.subheader = subheader ;
htmlTemplate.headers = headers;
htmlTemplate.initiale = initiale;
htmlTemplate.name = name;
htmlTemplate.totalTexte = totalTexte ;
htmlTemplate.totalCount = totalCount;
htmlTemplate.tableRangeValues = tableRangeValues ;
const htmlForEmail = htmlTemplate.evaluate().getContent();
console.log(htmlForEmail);
GmailApp.SendEmail(
"xxxxxxx@xxxx.com",
"test envoi mail html",
"svp, ouvrez ce mail avec ce support client HTML",
{htmlbody : htmlForEmail});
}HTML
<!DOC TYPE html>
<html>
<Head>
<base target="_top">
</Head>
<body>
<div><div>
</div>
<div>
<h1> <?= h1 ?></h1>
<div> <?= subheader ?></div>
<div></div>
<Table>
<Thead>
<tr><th>initiale</th>
<th>name</th>
<th>prenom</th>
<th>profession</th></tr>
</thead>
<tbody>
<tr>
<td>
Col1 d1
</td>
<td>
Col2 d2
</td>
<td>
Col3 d3
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>
<?= totalTexte ?>
</td>
<td>
</td>
<td>
<?= totalCount ?>
</td>
</tr>
</tfoot>
</Table>
</div>
<div>
</div>
</div>
</body>
</html>发布于 2020-07-03 13:50:38
https://stackoverflow.com/questions/62715981
复制相似问题