Google 文件編輯器外掛程式快速入門
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本快速入門導覽會建立 Google 文件編輯器外掛程式,翻譯文件中選取的文字。
目標
必要條件
如要使用這個範例,您必須符合下列先決條件:
- Google 帳戶 (Google Workspace 帳戶可能需要管理員核准)。
- 可連上網際網路的網路瀏覽器。
設定指令碼
- 前往 docs.new 建立 Google 文件。
- 依序點選「擴充功能」>「Apps Script」。
- 按一下「未命名專案」。
- 將 Apps Script 專案重新命名為「Translate Docs」,然後按一下「重新命名」。
- 找出
Code.gs
檔案,然後依序點選「更多」圖示 more_vert
>「重新命名」。將檔案命名為 translate
。
- 依序點選「新增檔案」圖示 add
「HTML」。將檔案命名為
sidebar
。
將每個檔案的內容替換成下列對應的程式碼,然後按一下「儲存」圖示
。
執行指令碼
- 在 Google 文件中重新載入頁面。
- 依序點選「擴充功能」>「翻譯文件」>「開始」。
- 出現提示時,請授權外掛程式。
授權後,外掛程式會重新啟動。
- 在文件中輸入一些文字,然後選取這些文字。
- 在外掛程式中,按一下「翻譯」。如要取代文件中的文字,請按一下「插入」。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-31 (世界標準時間)。
[null,null,["上次更新時間:2025-07-31 (世界標準時間)。"],[[["\u003cp\u003eThis quickstart guide demonstrates how to build a Google Docs add-on using Apps Script that translates selected text within a document.\u003c/p\u003e\n"],["\u003cp\u003eThe 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.\u003c/p\u003e\n"],["\u003cp\u003eUsers need a Google Account and a web browser to utilize this add-on, which involves setting up a script, running it, and authorizing permissions.\u003c/p\u003e\n"],["\u003cp\u003eThe add-on provides a user interface within a sidebar in Google Docs for easy interaction and language selection.\u003c/p\u003e\n"],["\u003cp\u003eFurther resources are available for extending Google Docs functionality with Apps Script and exploring the Document service for more advanced customizations.\u003c/p\u003e\n"]]],["This document guides the creation of a Google Docs add-on for text translation. It involves creating a new Google Docs file and an Apps Script project. You will rename files to `translate` and `sidebar`, and replace their content with provided code. The code defines functions for opening a sidebar, selecting text, translating it, and inserting the translated text back into the document. After reloading, accessing the add-on requires selecting text, choosing languages, clicking 'Translate', and finally, clicking 'Insert'.\n"],null,[]]