čtvrtek 26. března 2015

Custom menu (create, delete,...)

How to create custom menu in google Apps.

Create custom menu

Example 1. Menu is create in Active Spreadsheet.

function CreateMenu1() {
 var ss = SpreadsheetApp.getActiveSpreadsheet(),
     options = [
      {name:"Run First", functionName:"scrFirst"},
      {name:"Run Two", functionName:"scrSecond"}
     ];
 ss.addMenu("My menu", options);
}

function scrFirst() {
     Browser.msgBox("First menu script.");
}

function scrSecond() {
     Browser.msgBox("Second mune script.");
}



Create custom menu 2

Example 2. Menu is create in Active Spreadsheet.

function CreateMenu2() {
  var ss = SpreadsheetApp.getUi();

  ss.createMenu('Custom Menu')
      .addItem('First item', 'menuItem1')
      .addSeparator()
      .addSubMenu(ss.createMenu('Sub-menu')
          .addItem('Second item', 'menuItem2'))
      .addToUi();
}

function CreateMenu3() {
var ss = SpreadsheetApp.getUi();

  ss.createMenu('Custom Menu')
      .addItem('First item', 'menuItem1')
      .addSeparator()
      .addItem('Second item', 'menuItem2')
      .addToUi();
}



Remove custom menu 2

Remove "Custom Menu" form Example 2

function RemoveMenu1() {
     var ss = SpreadsheetApp.getActiveSpreadsheet();
     ss.removeMenu('Custom Menu');
}

Žádné komentáře:

Okomentovat