在已发布的加载项中找不到自定义菜单和侧边栏

时间:2017-08-28 20:20:46

标签: google-apps-script google-sheets

我正在尝试使用unlisted选项发布Google Sheet加载项:Only people with the link can see it。以下是代码:Code.gs

function myFun() {
  return "myFunValue"
}

function onInstall() {
  onOpen()
}

function onOpen() {
  var html = HtmlService.createHtmlOutputFromFile('Index.html') //your html page name
      .setTitle('My custom sidebar')
      .setWidth(300);

  SpreadsheetApp.getUi().createAddonMenu()
      .addItem('Use in this spreadsheet', 'use')
      .addToUi();

  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
      .showSidebar(html);
}

function use() {
  var title = 'Date Custom Functions';
  var message = 'Message of use';
  var ui = SpreadsheetApp.getUi();
  ui.alert(title, message, ui.ButtonSet.OK);
}

Index.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    super add-on, with custom function "=myFun()" and custom menu
  </body>
</html>

这是链接:

https://chrome.google.com/webstore/detail/functionmenuside/bmojfiljhggogegocdkjdlaoohbkcmod?authuser=0

此附加组件适用于自己的Google表格。但是,发布后,当我点击+Free时,会打开一个新的Google表格,我可以在FunctionMenuSide中找到Add-ons。自定义功能有效,但没有侧边栏,我们找不到自定义菜单Use in this spreadsheet。似乎onOpen没有被执行。

有谁知道如何解决这个问题?

修改1:,在控制台中,有以下消息: 1739997376-ritz_waffle_integrated_i18n_ritzmaestro.js:105 Google Apps Script: You do not have permission to call createHtmlOutputFromFile

1 个答案:

答案 0 :(得分:0)

您正尝试在onOpen()功能中打开侧边栏。由于简单触发器使用Google Apps脚本的方式,这项工作无法实现。

相反,创建另一个打开侧边栏的功能,并将该功能添加为附加菜单中的项目。然后,您的用户可以从附加菜单打开侧边栏。