谷歌应用程序脚本将自定义菜单功能添加到工作表

时间:2017-08-09 01:08:10

标签: google-apps-script

如何整合此代码,以便所有功能都列在同一标题(下拉列表)下?感谢。

function onOpen ()
{ var sheet = SpreadsheetApp.getActiveSpreadsheet ();  

  var menu = [ {name: "extract e-mail",functionName: "GetAddresses"} ];  
  sheet.addMenu ("Extract E-mail", menu);    

  var menu = [ {name: "remove self",functionName: "readRows"} ];   
  sheet.addMenu ("AOA", menu); 

  var menu = [ {name: "remove duplicates",functionName: "removeDuplicates"} ];  
  sheet.addMenu ("Duplicates", menu); 

  var menu = [ {name: "send e-mail",functionName: "sendEmails"} ];  
  sheet.addMenu ("Mail Merge", menu); 

 }

1 个答案:

答案 0 :(得分:2)

您可以将菜单项作为对象数组传递。

function onOpen ()
{ 
  var sheet = SpreadsheetApp.getActiveSpreadsheet ();  
  var menu = [ 
    {name: "extract e-mail",functionName: "GetAddresses"},
    {name: "remove self",functionName: "readRows"},
    {name: "remove duplicates",functionName: "removeDuplicates"},
    {name: "send e-mail",functionName: "sendEmails"} 
  ];  
  sheet.addMenu ("Mail Merge", menu); 
 }