1 回答

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超6個(gè)贊
我相信你的目標(biāo)如下。
在您的情況下,底部腳本嵌入到 Google 站點(diǎn)。
您想要從中檢索值
doGet
并將單元格“B2”的值放入輸入標(biāo)簽。Web Apps 的設(shè)置是
Execute the app as: Me
和Who has access to the app: Anyone, even Anonymous
。
修改點(diǎn):
對(duì)于您的情況,我認(rèn)為這
return ContentService.createTextOutput(output);
比return HtmlService.createHtmlOutput(output);
在 Google Apps 腳本中更合適。為了從中檢索值
doGet
,在此修改中,fetch
使用了。您要從 中檢索單元格“B2”
usableVariable[1,1];
,請(qǐng)將其修改為usableVariable[1][1];
當(dāng)以上幾點(diǎn)反映到您的腳本中時(shí),它會(huì)變成如下。
修改腳本:
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>
筆記:
當(dāng)您修改 Web Apps 的 Google Apps Script 時(shí),請(qǐng)將 Web Apps 重新部署為新版本。由此,最新的腳本被反映到Web Apps。請(qǐng)注意這一點(diǎn)。
在我的環(huán)境中,我可以通過(guò)嵌入確認(rèn)上述 HTML 和 Javascript 在 Google 站點(diǎn)中有效。
添加回答
舉報(bào)