1 回答
![?](http://img1.sycdn.imooc.com/54584f8f00019fc002200220-100-100.jpg)
TA贡献1825条经验 获得超6个赞
我相信你的目标如下。
在您的情况下,底部脚本嵌入到 Google 站点。
您想要从中检索值
doGet
并将单元格“B2”的值放入输入标签。Web Apps 的设置是
Execute the app as: Me
和Who has access to the app: Anyone, even Anonymous
。
修改点:
对于您的情况,我认为这
return ContentService.createTextOutput(output);
比return HtmlService.createHtmlOutput(output);
在 Google Apps 脚本中更合适。为了从中检索值
doGet
,在此修改中,fetch
使用了。您要从 中检索单元格“B2”
usableVariable[1,1];
,请将其修改为usableVariable[1][1];
当以上几点反映到您的脚本中时,它会变成如下。
修改脚本:
Google Apps 脚本端:
function doGet(e) {
var spreadsheet = SpreadsheetApp.openById('spreadsheetID');
var worksheet = spreadsheet.getSheetByName('Rankings C/U');
var output = JSON.stringify({ data: worksheet.getDataRange().getValues() });
return ContentService.createTextOutput(output);
}
HTML 和 Javascript 端:
<form name="get-images">
<input name="test" id="test" value="we'll put the contents of cell A1 here">
</form>
<script>
let url = "https://script.google.com/macros/s/###/exec";
fetch(url)
.then((res) => res.json())
.then((res) => {
const usableVariable = res.data;
const form = document.forms['get-images'];
form.elements['test'].value = usableVariable[1][1]; // usableVariable[1][1] is the cell "B2".
});
</script>
笔记:
当您修改 Web Apps 的 Google Apps Script 时,请将 Web Apps 重新部署为新版本。由此,最新的脚本被反映到Web Apps。请注意这一点。
在我的环境中,我可以通过嵌入确认上述 HTML 和 Javascript 在 Google 站点中有效。
添加回答
举报