I published a Google Sheet add-on privately.
When I install it, a new Google sheet is systematically opened, the custom function works. However, if I create a new Google Sheet, the custom function does not work in the first place. I need to click Add-ons ==> TotallyNew ==> Use
, which opens the sidebar, and the custom function works as well.
I just don't understand why the custom function is activated by Use
.
Does anyone know the reason?
function myFun() {
console.log("inside myFun");
return "myFunValue"
}
function onInstall(e) {
console.info("inside onInstall");
onOpen(e);
}
function onOpen(e) {
console.info("inside onOpen");
console.info(e.authMode);
SpreadsheetApp.getUi().createAddonMenu()
.addItem('Use', 'use')
.addToUi();
}
function use() {
console.info("inside Use")
var html = HtmlService.createHtmlOutputFromFile('Index.html')
.setTitle('My custom sidebar')
.setWidth(300);
SpreadsheetApp.getUi()
.showSidebar(html)
}
You are close. Change
createAddonMenu
tocreateMenu