创建一个新菜单
在电子表格 UI 中创建一个新菜单。每个菜单项都运行用户定义的功能。
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);