2

Is it possible to open a sidebar without having to open a menu and clicking an item? I mean can we just add a menu that acts like a button and opens the sidebar when clicked?

The shortest way I know is to add a single item to the menu:

function onOpen(e) {
   SpreadsheetApp.getUi()
       .createAddonMenu()
       .addItem('Show', 'showSidebar')
       .addToUi();
 }

but this are two clicks. I'd like to open it with only a single click on the menu itself.

t3chb0t
  • 16,340
  • 13
  • 78
  • 118
  • 2
    The only "one-click" solution would be an image with a script assigned to it. You can style the image to look like a button. [Stack Overflow answer Adding Buttons to Google Sheets](http://stackoverflow.com/a/28677553/2946873) – Alan Wells Sep 11 '16 at 17:28
  • @SandyGood perfect! it will do. thank you ;-) I didn't know it was possible to assign scripts to images. – t3chb0t Sep 11 '16 at 17:36

1 Answers1

-1

You can do something like:

function showSideBarUserInterface()
{
   var html = HtmlService.createTemplateFromFile(
        'SideBarUserInterface').evaluate()
        .setWidth(400)
        .setTitle("What would you like to do?")
        .setSandboxMode(HtmlService.SandboxMode.IFRAME);
    var ss = SpreadsheetApp.getActive();
    SpreadsheetApp.getUi().showSidebar(html);
}

You can call this function within onOpen and if you did, the sidebar appears without you doing anything more than just opening the sheet. You may want to make your required sheet within the spreadsheet active before calling this function though.

t3chb0t
  • 16,340
  • 13
  • 78
  • 118
VLBaindoor
  • 224
  • 3
  • 7