Google Apps脚本:点击主菜单时直接打开侧边栏
由于我的整个 Google 文档附加组件将包含在侧边栏中,因此我希望通过在主菜单上单击一下即可将其显示出来。但是,我看到的所有示例都需要首先单击主菜单,然后单击某种子菜单,例如如下所示。
function onOpen() {
var ui = DocumentApp.getUi();
ui.createMenu('My Add-On')
.addItem('My Add-On sidebar', 'openSidebar')
.addToUi();
}
相反,原则上我想做如下的事情(尽管它不能以这种方式工作)。
function onOpen() {
var ui = DocumentApp.getUi();
ui.createMenu('My Add-On', 'openSidebar') // this doesn't actually work this way
.addToUi();
}
这样当点击主菜单时,侧边栏就会直接打开。
这有可能吗?
Since my entire Google Doc add-on would be included in a sidebar, I'd like to have it appear by a simple single click on the main menu. However, all examples I see require first clicking the main menu, and then some sort of submenu, e.g. as below.
function onOpen() {
var ui = DocumentApp.getUi();
ui.createMenu('My Add-On')
.addItem('My Add-On sidebar', 'openSidebar')
.addToUi();
}
Instead, I'd like to do something like below, in principle (though it cannot work this way).
function onOpen() {
var ui = DocumentApp.getUi();
ui.createMenu('My Add-On', 'openSidebar') // this doesn't actually work this way
.addToUi();
}
So that the sidebar would open directly when clicking on the main menu.
Is that possible somehow?
(There seems to be some sort of a workaround for Spreadsheets described here, but doesn't seem to apply for Docs.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无法通过单击菜单名称来打开侧边栏,因为无法为菜单分配功能。
关于提到的“解决方法”(通过使用简单的触发器打开侧边栏)可能适用于文档所有者,但不适用于文档编辑者,因为 Google 出于安全考虑而进行了更改,但您可以让每个编辑者创建自己的可安装打开改为触发。请记住,您应该包括防止触发冲突的措施,即检查有效用户是否与活动用户相同。
资源
Opening a sidebar with a click on the menu name is not possible, as it's not possible to assign a function to the menu.
Regarding the referred "workaround" (opening a sidebar by using simple trigger) that might work for the document owner but not for document editors due to changes made by Google due to security concerns, but you might make that each editor creates their own installable open trigger instead. Please bear in mind that you should include measures to prevent trigger collisions, i.e. check if the effective user is the same as the active user.
Resources
启动侧边栏,
您会发现有时我的侧边栏我不打开,因此在菜单中有一个为您启动的项目很方便。
Launching a sidebar
You will find that sometimes the sidebar my not open so having an item in the menu to launch it for you is convenient.