Javascript 从google电子表格中的单元格调用showSidebar()
作为用户Serge insas的回答 Ui对话框不能由时间触发函数调用,它们必须由用户操作触发,也就是说,单击菜单项或某种按钮调用显示Ui的函数 从单元格调用showSidebar()或showModalDialog()怎么样?类似于以下公式,当A1中的值大于0时,应自动打开侧栏:Javascript 从google电子表格中的单元格调用showSidebar(),javascript,google-apps-script,google-sheets-formula,spreadsheet,google-sheets-api,Javascript,Google Apps Script,Google Sheets Formula,Spreadsheet,Google Sheets Api,作为用户Serge insas的回答 Ui对话框不能由时间触发函数调用,它们必须由用户操作触发,也就是说,单击菜单项或某种按钮调用显示Ui的函数 从单元格调用showSidebar()或showModalDialog()怎么样?类似于以下公式,当A1中的值大于0时,应自动打开侧栏: =if(A1>0;showSidebar();"nothing to show") 这可能吗 这是我的剧本: function onOpen() { SpreadsheetApp.getUi().crea
=if(A1>0;showSidebar();"nothing to show")
这可能吗
这是我的剧本:
function onOpen() {
SpreadsheetApp.getUi().createAddonMenu().addItem('Open Beeper', 'openBig').addToUi();
}
function openBig() {
var htmlContent = HtmlService.createHtmlOutputFromFile('audioHtml').setTitle('Beeper');
SpreadsheetApp.getUi().showSidebar(htmlContent);
}
我可以通过单击addons菜单中的项目来打开侧边栏,没有问题,但是当我从单元格调用openBig()时,我得到以下错误:
无法从此上下文调用SpreadsheetApp.getUi()
我做错了什么?缺少什么?主是对的。你没有做错什么。简单地说,您不能从工作表本身(任何单元格)调用
SpreadsheetApp.getUi()
。仅允许从菜单上下文调用它 不可能。自定义函数的权限/权限比时间触发器少得多。使用onEdit触发器可以很好地工作。但是,如果使用onChange(Automatic)触发器,则会发送上下文错误。这是因为onEdit()触发器仅在用户编辑时发生。有些人一直在使用onEdit触发器从移动版本的Google Sheets运行函数。