我知道,無法使用Google Apps腳本自動打開文檔。但有沒有辦法從自定義菜單中打開文檔?從菜單中選擇一個項目並直接打開一個特定的文檔比打開一個對話框更加方便,在這個對話框中,我必須點擊文檔的鏈接。Google Apps腳本:從菜單中打開文檔
0
A
回答
1
考慮到這一點,側欄可以作爲一種菜單,您可以強制它在打開時顯示,並且可以在關閉時返回側欄。這對您的需求可能是可行的,因爲它提供了一種菜單項和選擇鏈接的能力。使用Dialogs and Sidebars in G Suite Documents頁面中的示例,下面的代碼將允許您知道的對話框場景以及側欄菜單項並打開側欄菜單項打開:
在Code.gs文件中,地點:
function onOpen() {
showSidebar();
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.createMenu('Dialog')
.addItem('Open', 'openDialog')
.addItem('Show sidebar', 'showSidebar')
.addToUi();
}
function openDialog() {
var html = HtmlService.createHtmlOutputFromFile('dialog');
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.showModalDialog(html, 'Dialog title');
}
function showSidebar() {
var html = HtmlService.createHtmlOutputFromFile('sidebar')
.setTitle('My custom sidebar')
.setWidth(300);
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.showSidebar(html);
}
接下來,創建2個HTML文件, 「對話」 和 「側欄」,然後添加以下到每個,用於顯示用途: 在dialog.html地方執行以下操作:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
Hello, World!
<input type="button" value="Close"
onclick="google.script.host.close()" />
</body>
</html>
並在sidebar.html中放置:
Hello, world! <input type="button" value="Close" onclick="google.script.host.close()" />
<br/>
<a href="https://drive.google.com/open?id=16HHKXBMmWXh5NBZRAnFDiwGrZ">Open My Sample File here</a>
<br/>
<a href="https://drive.google.com/open?id=16HHKXBMmWXh5NBZRAnFDiwGrZ" target="_blank">Open My Sample File in a new tab</a>
如果您運行的OnOpen()在編輯器中,或保存並關閉文件,然後重新打開,你應該在你的文件中的側邊欄。將HTML中的Hello World項目替換爲適當的項目。請注意,由於我刪除了一部分網址,因此提供的鏈接無效。
+0
謝謝!這是一個很好的解決方法。 – wepli23
相關問題
- 1. 從Google Apps腳本在瀏覽器窗口中打開Google文檔
- 2. Google Apps腳本MailApp使用htmlBody文檔
- 3. 從Google Apps腳本
- 4. Google Apps腳本 - >將文本從文檔寫入工作表
- 5. 使用Apps腳本從Google文檔中添加圖片
- 6. 從Google Apps腳本運行python腳本
- 7. Google Apps腳本 - getBlob()。isGoogleType()爲Google文檔返回false
- 8. Google Apps腳本(Google文檔) - 觸發評論添加或更改?
- 9. Google Apps腳本 - 向文檔添加動態頁眉/頁腳
- 10. Google Apps引擎,Google Apps腳本和Javascript
- 11. Google Apps腳本DockPanel
- 12. Google Apps腳本[createServerClickHandler]
- 13. 刪除Google Apps腳本文檔服務中的內容
- 14. Google Apps腳本中的多形態功能文檔
- 15. 在Google Apps腳本中獲取javascript「文檔HTML DOM」信息
- 16. Google Apps腳本 - 打字機效果
- 17. 自動打開Google Apps腳本UI
- 18. Google Apps腳本 - AuthMode - 安裝後沒有任何菜單
- 19. Google Apps腳本:動態創建電子表格菜單項
- 20. 使用Google Apps腳本的可滾動自定義菜單
- 21. Google Apps腳本網絡編輯器在打開時崩潰
- 22. Google Apps腳本[表單響應數據]
- 23. Google Apps腳本 - 拒絕表單提交
- 24. 無法通過replaceText訪問Google Apps腳本文檔
- 25. 如何通過google apps腳本保存文檔?
- 26. 許多文檔引用的一個Google Apps腳本
- 27. Google Apps腳本自動生成的庫文檔
- 28. 無法在腳本中打開Google文檔重複文檔
- 29. 如何從HtmlUnit運行Google Apps腳本?
- 30. 如何從Google Apps腳本輸出HTML?
自定義菜單是使用Google Apps腳本創建的,因此屬於相同的限制。您可以做的最好的方法是使用自定義菜單打開一個對話框,其中包含任何可用的菜單鏈接,並將其視爲打開文件的菜單項。 –
好的。我已經這麼想過了。謝謝。 – wepli23