【问题标题】:sidebar not opening on Google Sheets unless run with Script Editor除非使用脚本编辑器运行,否则侧边栏不会在 Google 表格上打开
【发布时间】:2017-12-21 14:26:30
【问题描述】:

我是编码新手。我正在尝试在 google 工作表中运行以下内容,并且在打开工作表时侧边栏未加载。如果我从脚本编辑器运行脚本,它只会显示侧边栏。

function onOpen() {
    SpreadsheetApp.getUi()
        .createMenu('Custom Menu')
        .addItem('Show sidebar', 'showSidebar')
        .addToUi();
}

function showSidebar() {
    var html = HtmlService.createHtmlOutputFromFile('index')
        .setTitle('My custom sidebar')
        .setWidth(300);
    SpreadsheetApp.getUi()
        .showSidebar(html);
}

【问题讨论】:

  • 执行记录有错误吗?

标签: google-apps-script google-sheets triggers sidebar


【解决方案1】:

下面的修改怎么样?

1。修改onOpen()如下。

添加showSidebar()。这样,当电子表格打开时,菜单栏会更新并打开侧边栏。

function onOpen() {
    SpreadsheetApp.getUi()
        .createMenu('Custom Menu')
        .addItem('Show sidebar', 'showSidebar')
        .addToUi();
    showSidebar(); // Added
}

2。安装触发器

  1. 在脚本编辑器上。
  2. 在菜单栏,编辑 -> 当前项目的触发器 -> 单击“未设置触发器。单击此处立即执行”。
    1. 在“运行”中,选择“onOpen”。
    2. 在“事件”中,选择“来自电子表格”和“打开时”。
    3. 点击保存按钮。

以上设置后,请在脚本编辑器上运行showSidebar()以防万一。在此之后,请关闭电子表格并打开它。

【讨论】:

  • 谢谢!选项 2 对我有用,不幸的是选项 1 没有。
猜你喜欢
  • 2016-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多