電子表格新增選單

通常,你需要從 onOpen 函式呼叫 addMenu,以便在載入電子表格時自動建立選單。

 // The onOpen function is executed automatically every time a Spreadsheet is loaded
 function onOpen() {
   var activeSheet = SpreadsheetApp.getActiveSpreadsheet();
   var menuItems = [];
   // When the user clicks on "addMenuExample" then "Menu 1", the function Myfunction1 is executed.
   menuItems.push({name: "Menu 1", functionName: "Myfunction1"});
   menuItems.push(null); // adding line separator
   menuItems.push({name: "Menu 2", functionName: "Myfunction2"});

   activeSheet.addMenu("addMenuExample", menuEntries);
 }