google-apps-script - Google App script SyntaxError: Unexpected token '<' when running script
问题描述
有人知道这里有什么问题吗?它已经工作了多次,即使
const htmlForEmail = htmlTemplate.evaluate().getContent();
现在它似乎抛出了一个错误:
错误:错误
SyntaxError: Unexpected token '<'electrical @electric.gs:24 我在运行时版本-runtimeVersion-“V8”
我的谷歌应用脚本代码(html代码在它下面):
function electrical() {
const ss = SpreadsheetApp.getActiveSpreadsheet ();
const ws = ss.getSheetByName("Bid Request");
const h1 = ws.getRange("G4").getValue();
const headers = ws.getRange("G5:H5").getValues();
const project = headers [0][0];
const response = headers [0][1];
const lr =ws.getLastRow();
const tableRangeValues = ws.getRange(6,2,lr-6,2).getDisplayValues();
const htmlTemplate = HtmlService.createTemplateFromFile("email");
htmlTemplate.h1 = h1;
htmlTemplate.headers = headers;
htmlTemplate.project = project;
htmlTemplate.response = response;
htmlTemplate.tableRangeValues = tableRangeValues;
const htmlForEmail = htmlTemplate.evaluate().getContent();
console.log(htmlForEmail);
GmailApp.sendEmail(
"example@gmail.com",
"Bid Request",
"Please",
{htmlBody: htmlForEmail}
);
}
html:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<div>
<div>
</div>
<div>
<h1><?= h1 ?></h1>
<div></div>
<table>
<thead>
<tr>
<th><?= project ?></th><th><?= response></th>
</tr>
</thead>
<tbody>
<? tableRangeValues.forEach(r => { ?>
<tr>
<td><?= r[0] ?></td><td><?= r[1] ?></td>
</tr>
<?}) ?>
</tbody>
</div>
</div>
</body>
</html>
出于某种原因,html 不允许我显示我有 header/body 标签和 html 定义的文档标签,但我这样做了!
解决方案
您的 html 代码中有错字
<thead>
<tr>
<th><?= project ?></th><th><?= response></th>
</tr>
</thead>
应该是这样的
<thead>
<tr>
<th><?= project ?></th><th><?= response ?></th>
</tr>
</thead>
希望能解决你的问题
推荐阅读
- java - 配置 Spring 以使用数据库进行身份验证
- python - 错误:不可散列类型:“列表”。使用 df.groupby.apply 时
- javascript - 从字符串的两个部分创建 html
- macos - Mac:“找不到创建目标的规则”(C,CodeLite)
- python - Python - 想要在它们都运行时将数据从一个脚本传递到另一个脚本
- redirect - ASP.NET Core - 如何在不重新加载的情况下向客户端发送 HTTPClient 响应
- mysql - 尝试在 Mac book pro 上访问 Rails Sever 时出错
- idris - 与 :elab 交互生成的证明不起作用
- android - 针对 Android SDK 版本 26 的 Android 应用程序 - 无法通过 ADB 访问应用程序数据目录
- c++ - 模板参数“(类型)0”与“EnumValue”不匹配