Add custom menu to a Google Document

2019-09-07 03:12发布

问题:

I'm discovering Google App Script and I'm very attracted by its potential.

I want to improve a Google Document by adding a custom menu. I found many how-to to make this in a spreadsheet but nothing for document.

Did I miss anything ?

回答1:

From: https://developers.google.com/apps-script/reference/document/document-app#getActiveDocument()

 // Add a custom menu to the active document, including a separator and a sub-menu.
 function onOpen() {
   DocumentApp.getUi()
       .createMenu('My Menu')
       .addItem('My Menu Item', 'myFunction')
       .addSeparator()
       .addSubMenu(DocumentApp.getUi().createMenu('My Submenu')
           .addItem('One Submenu Item', 'mySecondFunction')
           .addItem('Another Submenu Item', 'myThirdFunction'))
       .addToUi();
 }


回答2:

It is not possible to have a Document as a container for a script and therefore not possible to add a menu item to the Document.

There is an open issue on the issue tracker which you can subscribe to.