為初學者的問題道歉。
我有一個應用程式腳本,可以在編輯我的 Google 表格時創建一個用戶彈出選擇選單。選擇選單是用 HTML 創建的。當我從自己的帳戶編輯電子表格時,這完全符合預期。但是,當共享用戶執行相同操作時,會執行 withFailureHandler。
這是我的 Code.gs:
function doGet(e){
var html = HtmlService.createHtmlOutputFromFile('Index')
.setWidth(250)
.setHeight(200);
SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
.showModalDialog(html, 'Animal');
}
function displayMessage(selection){
SpreadsheetApp.getUi().alert("Your selection was: " selection);
}
這是Index.html:
<form>
Select animal:
<br><br>
<div class="custom-select">
<select id="myList" onchange="selectionMade()">
<option>Selection Option</option>
<option>Cat</option>
<option>Dog</option>
<option>Horse</option>
</select>
<script>
function selectionMade(selection) {
var mylist = document.getElementById("myList");
var selection = mylist.options[mylist.selectedIndex].text;
google.script.run
.withSuccessHandler(function(data,element){window.alert("executed");})
.withFailureHandler(function(msg,element){window.alert("failed"); })
.displayMessage(selection);
}
</script>
我正在尋找將選擇值回傳到共享用戶的電子表格的腳本,這與我從我的帳戶中使用它時所做的相同。
提前致謝。
更新:我收到以下錯誤:“ScriptError:需要授權才能執行該操作。” 在登錄到創建腳本的帳戶以外的 Google 帳戶時嘗試運行它。
uj5u.com熱心網友回復:
好吧,你去你的 Code.gs:,選擇函式 displayMessage
function displayMessage(selection){
selection =1;
SpreadsheetApp.getUi().alert("Your selection was: " selection);
}
運行此功能并轉到授權。授權后,從您的代碼中洗掉選擇 =1。那應該有效
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/428176.html
標籤:javascript html 谷歌应用脚本 谷歌表格
上一篇:谷歌表格陣列陣列公式
