Add custom menu to a Google Document

2019-09-07 02:33发布

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 ?

2条回答
可以哭但决不认输i
2楼-- · 2019-09-07 03:04

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.

查看更多
The star\"
3楼-- · 2019-09-07 03:24

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();
 }
查看更多
登录 后发表回答