问题
I am trying to make this add-on plugin that can help me and other to export sheet in to JSON. In my testing it's the menu shows up and all the functionality works (as you see in screenshots). When I sent for publish on Google Web Store the "Docs Add-ons Advisor" don't see the menu in the review. So as "Docs Add-ons Advisor" suggested I published it "Unlisted" to see if it work on my side. And it doesn't work. Here is the code I am using and links. Can anyone tell me what I am doing wrong and help me fix it.
Plugin (Unlisted): https://chrome.google.com/webstore/detail/export-to-json/fcnpcmlbpljkcehfcgllklhbgppinbdd?hl=en-US&gl=US&authuser=0
Reference:
- https://developers.google.com/apps-script/guides/menus
Code:
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..
}
回答1:
I had similar problem. But my problem was that I declared global variables which basically prevented onOpen(e)
from running.
I do see that you're not declaring global variables in your example code, though.
回答2:
I had the same problem with my add-on: the menu items were visible when I ran the script, but as soon as I published it as an addon, the menu item mysteriously disappeared (with only the 'help' remaining)
I added another item, and for some reason both started to show up! Try this in your onOpen(e) function:
function onOpen(e) {
SpreadsheetApp.getUi().createAddonMenu()
.addItem('Export to JSON', 'exportInit')
.addSeparator()
.addItem('Test', 'exportInit')
.addToUi();
}
来源:https://stackoverflow.com/questions/32259618/menu-items-do-not-appear-in-google-sheets-add-on