Google 文件編輯器外掛程式快速入門
本快速入門會建立 Google 文件編輯器外掛程式,用於翻譯文件中選取的文字。
目標
必要條件
如要使用這個範例,您必須具備下列先決條件:
- Google 帳戶 (Google Workspace 帳戶可能需要管理員核准)。
- 可連上網際網路的網路瀏覽器。
設定指令碼
- 前往 docs.new 建立 Google 文件。
- 依序按一下「Extensions」>「Apps Script」。
- 按一下「Untitled project」。
- 重新命名 Apps Script 專案「Translate Docs」,然後按一下「Rename」。
- 在
Code.gs
檔案旁邊,依序按一下「更多」圖示 more_vert
>「重新命名」。將檔案命名為 translate
。
- 依序點選「新增檔案」add
>「HTML」。將檔案命名為
sidebar
。
將每個檔案的內容替換為下列對應的程式碼,然後按一下「儲存」
。
執行指令碼
- 在 Google 文件文件中重新載入頁面。
- 依序點選「擴充功能」「翻譯文件」「開始」。
- 出現提示時,請授權使用外掛程式。授權後,外掛程式就會重新啟動。
- 在文件中輸入文字並選取。
- 在外掛程式中,按一下「翻譯」。如要取代文件中的文字,請按一下「插入」。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-02-14 (世界標準時間)。
[null,null,["上次更新時間:2025-02-14 (世界標準時間)。"],[[["This quickstart guide demonstrates how to build a Google Docs add-on using Apps Script that translates selected text within a document."],["The add-on allows users to select text, choose source and target languages, and obtain the translation, with an option to insert the translated text directly into the document."],["Users need a Google Account and a web browser to utilize this add-on, which involves setting up a script, running it, and authorizing permissions."],["The add-on provides a user interface within a sidebar in Google Docs for easy interaction and language selection."],["Further resources are available for extending Google Docs functionality with Apps Script and exploring the Document service for more advanced customizations."]]],[]]