Google-sheets – How to test apps script addon

google sheetsgoogle-apps-scriptgoogle-sheets-addons

I have created an addon using this guide.

code.gs

function onOpen() {
   SpreadsheetApp.getUi().createAddonMenu()
   .addItem('Start', 'showSidebar');
}

function showSidebar() {
  const ui = HtmlService.createHtmlOutputFromFile('index').setTitle('Sample');
  SpreadsheetApp.getUi().showSidebar(ui);
}

index.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <h1>Works</h1>
  </body>
</html>

It says "If you switch back to document and reload you will see a submenu under Add-ons menu.

But I could not find my addon submenu, I think the quickstart guide is outdated.

Please guide me, How to test the addon on google sheet.

Best Answer

The problem is that the onOpen function is incomplete; .addToUi(); is missing.

This is the onOpen function on the referred guide

/**
 * Creates a menu entry in the Google Docs UI when the document is opened.
 * This method is only used by the regular add-on, and is never called by
 * the mobile add-on version.
 *
 * @param {object} e The event parameter for a simple onOpen trigger. To
 *     determine which authorization mode (ScriptApp.AuthMode) the trigger is
 *     running in, inspect e.authMode.
 */
function onOpen(e) {
  DocumentApp.getUi().createAddonMenu()
      .addItem('Start', 'showSidebar')
      .addToUi();
}
Related Topic