Google Apps脚本:是否有某种方法可以将子菜单置于子菜单中?

cra*_*ice 4 google-apps-script

有没有一种方法可以使用addMenu(name, subMenus)其他方法将子菜单放入Google电子表格的子菜单中?

Sou*_*ria 5

是的:)但不使用addMenu(name, subMenus); 而是使用addSubMenu

请参阅Google文档,表格,幻灯片或表单中的自定义菜单

G Suite中的自定义菜单

这是代码-

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  // Or DocumentApp or FormApp.
  ui.createMenu('Custom Menu')
      .addItem('First item', 'menuItem1')
      .addSeparator()
      .addSubMenu(ui.createMenu('Sub-menu1')
          .addItem('Second item', 'menuItem2').addSubMenu(ui.createMenu('Sub-menu2')
          .addItem('Third item', 'menuItem3')))
      .addToUi();
}

function menuItem1() {
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
     .alert('You clicked the first menu item!');
}

function menuItem2() {
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
     .alert('You clicked the second menu item!');
}

function menuItem3() {
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
     .alert('You clicked the third menu item!');
}
Run Code Online (Sandbox Code Playgroud)

据我所知,在子菜单中,您可以创建的子菜单的数量没有记录的限制。

希望这可以帮助!