菜单项不会出现在 Google 表格插件中

Sun*_*nil 5 menu google-sheets google-apps-script google-apps-script-addon

我正在尝试制作这个附加插件,可以帮助我和其他人将工作表导出为 JSON。在我的测试中,菜单显示并且所有功能都有效(如屏幕截图中所示)。当我发送到 Google Web Store 上发布时,“Docs Add-ons Advisor”在评论中看不到菜单。因此,正如“Docs Add-ons Advisor”建议的那样,我将其发布为“不公开”,看看它是否适合我。但这不起作用。这是我正在使用的代码和链接。谁能告诉我我做错了什么并帮助我解决它。

插件(未列出):https://chrome.google.com/webstore/detail/export-to-json/fcnpcmbpljkcehfcgllklhbgppinbdd ?hl=en-US&gl=US&authuser=0

参考:

代码:

function onInstall(e) {
  onOpen(e);
}

function onOpen(e) {
  var menu = SpreadsheetApp.getUi().createAddonMenu(); // Or DocumentApp or FormApp.

  if (e && e.authMode == ScriptApp.AuthMode.NONE) {
  // Add a normal menu item (works in all authorization modes).
    menu.addItem('Export to JSON', 'exportInit');
  } else {
    // Add a menu item based on properties (doesn't work in AuthMode.NONE).
    var properties = PropertiesService.getDocumentProperties();
    var workflowStarted = properties.getProperty('workflowStarted');
    if (workflowStarted) {
      menu.addItem('Start to JSON', 'startJson');
    } else {
      menu.addItem('Export to JSON', 'exportInit');
    }
  }
  menu.addToUi();
}

function startJson(){
  ...code...
}
function exportInit() {
  ..code..
}
Run Code Online (Sandbox Code Playgroud)

小智 2

我有类似的问题。但我的问题是我声明的全局变量基本上阻止了onOpen(e)运行。

不过,我确实看到您没有在示例代码中声明全局变量。