2012-07-06 85 views
0

我在發現Google應用腳本,並且很受其潛力所吸引。將自定義菜單添加到Google文檔

我想通過添加自定義菜單來改進Google文檔。 我發現了許多如何在電子表格中進行此操作,但沒有任何文檔。

我錯過了什麼嗎?

回答

2

來源: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(); 
} 
1

不可能將Document作爲腳本的容器,因此無法將菜單項添加到Document中。

有一個open issue on the issue tracker你可以訂閱。

+0

我希望能夠選擇的內容直接發送到Twitter。你有想法來管理這個嗎? 感謝您的幫助。 – 2012-07-06 08:06:52

+0

@ user1506051:這篇[文章](https://developers.google.com/apps-script/articles/twitter_tutorial)將幫助您從GAS開始使用Twitter。 – megabyte1024 2012-07-06 08:25:25

+0

這個答案已經過時。 – 2017-10-18 02:50:27

相關問題