2
votes

I am new to coding. I am trying to run the following in a google sheet and the sidebar is not loading when the sheet is opened. It only shows the sidebar if I run the script from the script editor.

function onOpen() {
    SpreadsheetApp.getUi()
        .createMenu('Custom Menu')
        .addItem('Show sidebar', 'showSidebar')
        .addToUi();
}

function showSidebar() {
    var html = HtmlService.createHtmlOutputFromFile('index')
        .setTitle('My custom sidebar')
        .setWidth(300);
    SpreadsheetApp.getUi()
        .showSidebar(html);
}
1
Is there any error on the execution transcript? - Rubén

1 Answers

4
votes

How about the following modifications?

1. Modify onOpen() as follows.

Add showSidebar(). By this, when spreadsheet is opened, menu bar is updated and open sidebar.

function onOpen() {
    SpreadsheetApp.getUi()
        .createMenu('Custom Menu')
        .addItem('Show sidebar', 'showSidebar')
        .addToUi();
    showSidebar(); // Added
}

2. Install a trigger

  1. On the script editor.
  2. At menu bar, Edit -> Current project's triggers -> Click "No triggers set up. Click here to one now."
    1. At "Run", select "onOpen".
    2. At "Event", select "From spreadsheet" and "On open".
    3. Click save button.

After above setting, please run showSidebar() on script editor just in case. After this, please close spreadsheet and open it.