【发布时间】:2021-01-20 20:35:22
【问题描述】:
使用 Google Apps 脚本,一旦有人将数据输入 Google 电子表格,如何在 HTML 页面中显示数据(无需刷新页面)?
我编写了以下代码,这些代码会呈现电子表格中存在的所有数据。但是我无法在不需要刷新页面的情况下添加动态呈现数据的功能。
index.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<h1>Hello world</h1>
<? for(var i=0; i<list.length; i++){ ?>
<h3><?= list[i] ?></h3>
<? } ?>
</body>
</html>
code.gs
var ss = SpreadsheetApp.getActiveSpreadsheet();
function doGet() {
var ws = ss.getSheetByName('list');
var lastRow = ws.getLastRow();
var numRow = lastRow - 1;
var vals = ws.getRange(2,1,numRow,2).getValues();
var temp = HtmlService.createTemplateFromFile('index');
temp.list = vals;
return temp.evaluate();
}
电子表格
【问题讨论】:
标签: javascript google-apps-script google-sheets web-applications