Mantieni tutto organizzato con le raccolte Salva e classifica i contenuti in base alle tue preferenze.
Menu
Un menu personalizzato in un'istanza dell'interfaccia utente di un'app Google. Uno script può interagire con l'interfaccia utente solo per l'istanza corrente di un documento o un modulo aperto e solo se lo script è legato al contenitore del documento o del modulo. Per ulteriori informazioni, consulta la guida ai menu.
// Add a custom menu to the active spreadsheet, including a separator and a// sub-menu.functiononOpen(e){SpreadsheetApp.getUi().createMenu('My Menu').addItem('My Menu Item','myFunction').addSeparator().addSubMenu(SpreadsheetApp.getUi().createMenu('My Submenu').addItem('One Submenu Item','mySecondFunction').addItem('Another Submenu Item','myThirdFunction'),).addToUi();}
Inserisce il menu nell'istanza dell'interfaccia utente dell'editor.
Documentazione dettagliata
addItem(caption, functionName)
Aggiunge un elemento al menu. L'etichetta di un elemento del menu deve essere in maiuscolo (solo la prima parola deve essere in maiuscolo).
Parametri
Nome
Tipo
Descrizione
caption
String
L'etichetta della voce di menu, con la sola prima parola in maiuscolo.
functionName
String
Il nome della funzione da chiamare quando l'utente seleziona l'elemento. Puoi utilizzare le funzioni delle librerie incluse, ad esempio Library.libFunction1.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-07-26 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eMenu\u003c/code\u003e class allows you to create custom menus in Google Apps Script, adding items, separators, and submenus.\u003c/p\u003e\n"],["\u003cp\u003eMenus can be used to provide users with easy access to script functionalities within the active document or form.\u003c/p\u003e\n"],["\u003cp\u003eMenu items are linked to specific functions within your script using the \u003ccode\u003eaddItem()\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eaddToUi()\u003c/code\u003e inserts the created menu into the user interface of the current Google App instance.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code example demonstrates creating a basic custom menu with a submenu.\u003c/p\u003e\n"]]],[],null,["Menu\n\nA custom menu in an instance of the user interface for a Google App. A script can only interact\nwith the UI for the current instance of an open document or form, and only if the script is [container-bound](/apps-script/scripts_containers) to the document or form. For more\ninformation, see the [guide to menus](/apps-script/guides/menus).\n\n```javascript\n// Add a custom menu to the active spreadsheet, including a separator and a\n// sub-menu.\nfunction onOpen(e) {\n SpreadsheetApp.getUi()\n .createMenu('My Menu')\n .addItem('My Menu Item', 'myFunction')\n .addSeparator()\n .addSubMenu(\n SpreadsheetApp.getUi()\n .createMenu('My Submenu')\n .addItem('One Submenu Item', 'mySecondFunction')\n .addItem('Another Submenu Item', 'myThirdFunction'),\n )\n .addToUi();\n}\n``` \n\nMethods\n\n| Method | Return type | Brief description |\n|-----------------------------------------------------------|-------------|--------------------------------------------------------------------|\n| [addItem(caption, functionName)](#addItem(String,String)) | [Menu](#) | Adds an item to the menu. |\n| [addSeparator()](#addSeparator()) | [Menu](#) | Adds a visual separator to the menu. |\n| [addSubMenu(menu)](#addSubMenu(Menu)) | [Menu](#) | Adds a sub-menu to the menu. |\n| [addToUi()](#addToUi()) | `void` | Inserts the menu into the instance of the editor's user interface. |\n\nDetailed documentation \n\n`add``Item(caption, functionName)` \nAdds an item to the menu. The label for a menu item should be in sentence case (only the first\nword capitalized).\n\nParameters\n\n| Name | Type | Description |\n|------------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------|\n| `caption` | `String` | The label for the menu item, with only the first word capitalized. |\n| `function``Name` | `String` | The name of the function to invoke when the user selects the item. You can use functions from included libraries, such as `Library.libFunction1`. |\n\nReturn\n\n\n[Menu](#) --- This [Menu](#), for chaining.\n\n*** ** * ** ***\n\n`add``Separator()` \nAdds a visual separator to the menu.\n\nReturn\n\n\n[Menu](#) --- This [Menu](#), for chaining.\n\n*** ** * ** ***\n\n`add``Sub``Menu(menu)` \nAdds a sub-menu to the menu.\n\nParameters\n\n| Name | Type | Description |\n|--------|-----------|--------------------------------------------------|\n| `menu` | [Menu](#) | The sub-menu, constructed like a top-level menu. |\n\nReturn\n\n\n[Menu](#) --- This [Menu](#), for chaining.\n\n*** ** * ** ***\n\n`add``To``Ui()` \nInserts the menu into the instance of the editor's user interface."]]