目标:在google站点页面中,显示在给定列中具有给定值的特定google工作表中的行数,而无需在google站点页面中显示完整的工作表。
问题是:我还没有找到任何服务器端支持创建从google工作表中提取数据并可以从客户端javascript调用的函数。
我尝试过的是:我考虑过在页面中创建google应用程序,但它们似乎不能从嵌入在google站点页面中的javascript调用。
例如: Google站点第1页:志愿注册表单Google单:志愿注册表单(回复)列:时间戳、电子邮件、名、姓、电话、兴趣Google站点第2页:可用的后续任务显示:面试请求()
第一步:发布Google站点第1页,允许网站访问者填写并提交他们的信息,这些信息将自动添加到Google表单中。
步骤2:创建一个服务器端脚本来计数志愿人员注册表单(responses)中的所有行,其中的“兴趣”值与“请求面试”相匹配。(我是在应用程序脚本中这样做,还是最好的方法是什么?)
步骤3:将javascript嵌入到Google 2中,以调用服务器端脚本中的函数来检索匹配的行计数。
我以前在C#中使用MVC,在客户端使用javascript/jquery和JSON,在服务器端使用PHP,所以我熟悉客户机-服务器堆栈的概念,只是还不熟悉Google的实现。
有什么好的资源可以启发我,或者有人能给我举个例子吗?
发布于 2022-09-18 03:16:57
在新站点中嵌入new应用程序
GS:
function doGet(e) {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName("Sheet0");
return HtmlService.createHtmlOutput(`<h1>Number of Lines: ${sh.getLastRow()} </h1>`);
}遵循找到这里的步骤

这里有一个有更多肉的版本:
GS:
function doGet(e) {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName("Sheet0");
let t = HtmlService.createTemplateFromFile("ah1");
t.lr = sh.getLastRow();
return t.evaluate();
}
function getMyData() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName("Sheet0");
return sh.getDataRange().getValues();
}HTML:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<div id="tabledata">
<? var vs = getMyData(); ?>
<table>
<? vs.forEach((r,i)=>{ ?>
<tr>
<? r.forEach((c,j)=>{ ?>
<? if(i == 0) { ?>
<th style="padding:2px 5px;font-weight:bold;border:1px solid black;"><?= c ?> </th>
<? } else { ?>
<td style="padding:2px 5px;border:1px solid black;"><?= vs[i][j] ?> </td>
<? } ?>
<? }); ?>
</tr>
<? }); ?>
</table>
</div>
<h3> Number of rows: <?= lr ?> </h3>
</body>
</html>网站的产出:

https://stackoverflow.com/questions/73759203
复制相似问题