1 回答

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 站點中有效。
添加回答
舉報