Thursday, September 19, 2013

Speed Blogging: Adding a menu item to a Google Spreadsheet by script

Here is the code to add a Menu to a Google Spreadsheet by code:

//creating the Menu in the onOpen function from: https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet#addMenu(String,Object)

// The onOpen function is executed automatically every time a Spreadsheet is loaded
 function onOpen() {
   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var menuEntries = [];
   // When the user clicks on "addMenuExample" then "Menu Entry 1", the function function1 is
   // executed.
   menuEntries.push({name: "Add teachers that are going to be out to the Calendar", functionName: "subCalendarEditor"});
   menuEntries.push(null); // line separator
   // add more entries to the menu by using the method: menuEntries.push({name: "Menu Entry 2", functionName: "function2"});

   ss.addMenu("Substitute Calendar Editor", menuEntries);
 }