Google Sheet add-on onInstall() and onOpen() not working

房东的猫 提交于 2019-12-20 06:36:32

问题


I am trying to create an add-on for Google Sheets, but running in the problem.

The add-on creates additional menu in "Add-on" menu using onOpen() function of Google Drive API, but it does not do that onInstall(). So I have been told to add the folloing

function onInstall(e) {
   onOpen(e)
}

now, what I have tried to do is the following, but it still does not work

    function onInstall() {
       SpreadsheetApp.getUi().createAddonMenu()
          .addItem('Browse My Add-on', 'browseMyAddOn')
          .addToUi();
    }

    function onOpen() {
        SpreadsheetApp.getUi().createAddonMenu()
          .addItem('Browse My Add-on', 'browseMyAddOn')
          .addToUi();
    }

Please help me


回答1:


I think you should try this one instead:

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

function onOpen(e) {
    SpreadsheetApp.getUi().createAddonMenu()
      .addItem('Browse My Add-on', 'browseMyAddOn')
      .addToUi();
}


来源:https://stackoverflow.com/questions/27138535/google-sheet-add-on-oninstall-and-onopen-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!