从Google电子表格中的单元格调用showSidebar() [英] Call showSidebar() from a cell in google spreadsheets

查看:245
本文介绍了从Google电子表格中的单元格调用showSidebar()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为用户 Serge insas ,在此处回答

Ui对话框不能由时间触发的函数调用,它们必须由用户操作触发,也就是说,单击菜单项或某种按钮即可调用显示UI的函数.

Ui Dialogs can not be called by time triggered functions, they have to be triggered by a user action, that's to say a click on a menu item or some sort of button that calls the function showing the UI.

从单元格调用 showSidebar() showModalDialog()怎么样?类似于以下公式,当A1中的值大于0时,应会自动打开侧栏:

What about calling showSidebar() or showModalDialog() from a cell? Something like the following formula, which should open the sidebar automatically when the value in A1 is greater than 0:

=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);
}

我可以通过单击插件菜单中的项目来打开侧边栏,而不会出现问题,但是当我从单元格调用 openBig()时,出现以下错误:

I can open the sidebar by clicking the item in the addons menu without problems but when I call openBig() from a cell I get the following error:

无法从此上下文中调用SpreadsheetApp.getUi().

Cannot call SpreadsheetApp.getUi() from this context.

我做错了什么?缺少什么?

What am I doing wrong? What is missing?

推荐答案

TheMaster是正确的.你什么都没做错.简单来说,您不能从工作表本身(任何单元格)调用SpreadsheetApp.getUi().仅允许从菜单的上下文中调用它.

TheMaster is right. You are doing nothing wrong. Simply, you cannot call SpreadsheetApp.getUi() from the sheet itself (any cell). It is only allowed to be called from the context of the menu.

这篇关于从Google电子表格中的单元格调用showSidebar()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆