gpt4 book ai didi

javascript - 此上下文中的异常 : Cannot call SpreadsheetApp. getUi()

转载 作者:行者123 更新时间:2023-12-05 01:53:58 36 4
gpt4 key购买 nike

过去 3 小时我一直被这个错误困在这里。

Error Exception: Cannot call SpreadsheetApp.getUi() from this context.

我将不胜感激。

function onOpen(e) {
var menu = SpreadsheetApp.getUi().createMenu("Refresh");//The error is here
menu.addItem("Refresh Week", "menu");
menu.addToUi();
}
//The same thing goes to this function as well
function menu(){
//get the good week number
var date = new Date();
var wn = [(Math.floor(WEEKNUMBER(date))+3).toFixed(0)]
do {
wn.push((wn[wn.length-1]-1).toFixed(0))
} while(wn[wn.length-1] != 348);
var line = "<select style='width:60px;height:40px;' id='select'>"
for ( var x in wn )
line +="<option>" + wn[x] + "</option>"
line +="</select>"
var ui = SpreadsheetApp.getUi();
var html = HtmlService.createHtmlOutputFromFile('Selector')
.setWidth(200)
.setHeight(150).setContent("<div>"+line + "</div><br><div><button onclick='reset()'>Confirm</button></div><script>function reset(){var wn = document.getElementById('select').value;document.getElementsByTagName('Body')[0].style.cursor = 'wait';google.script.run.withSuccessHandler(function (){google.script.host.close();}).readWP2(wn);}</script>")
SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
.showModalDialog(html, 'Please select a week number');
}

因此,当我创建一个变量并将其设置为 SpreadsheetApp.getUi() 时,我开始收到此错误,并且由于此错误,其余代码不再运行

enter image description here

我正在使用 Google Apps 脚本。

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com