[英]Accessing HTML script variable from google script
我正在嘗試在Google表格中整理一個選擇器。 將文件上傳到Google驅動器后,我希望將網址發布到電子表格的當前單元格中。
這是我的pickerCallback位於html文件中:
var message;
function pickerCallback(data) {
var action = data[google.picker.Response.ACTION];
if (action == google.picker.Action.PICKED) {
var doc = data[google.picker.Response.DOCUMENTS][0];
var id = 'https://drive.google.com/open?id=' + doc[google.picker.Document.ID];
google.script.run.accessSpreadsheet();
} message = id;
document.getElementById('result').innerHTML = message;
}
這將在選擇器對話框中返回URL。
我的accessSpreadsheet函數如下所示,位於google腳本文件中:
function accessSpreadsheet() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var currentCell = sheet.getCurrentCell();
currentCell.setValue(message);
return spreadsheet;
}
該函數運行,但無法定義消息。 有沒有辦法從Google腳本功能訪問html文件中的函數中定義的變量? 還是有另一種更好的方法來做到這一點?
將字符串id
從客戶端傳遞到服務器。
google.script.run.accessSpreadsheet(id);
function accessSpreadsheet(id) {
currentCell.setValue(id);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.