Google ドキュメント エディタ アドオンのクイックスタート
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
このクイックスタートでは、ドキュメント内の選択したテキストを翻訳する Google ドキュメント エディタ アドオンを作成します。
目標
- スクリプトを設定します。
- スクリプトを実行します。
前提条件
このサンプルを使用するには、次の前提条件を満たしている必要があります。
- Google アカウント(Google Workspace アカウントの場合、管理者の承認が必要となる可能性があります)。
- インターネットにアクセスできるウェブブラウザ。
スクリプトを設定する
- docs.new で Google ドキュメントを作成します。
- [拡張機能] > [Apps Script] をクリックします。
- [無題のプロジェクト] をクリックします。
- Apps Script プロジェクトの名前を「Translate Docs」に変更し、[名前を変更] をクリックします。
Code.gs
ファイルの横にあるその他アイコン more_vert
> [名前を変更] をクリックします。ファイル名を translate
とします。
- [ファイルを追加] add
> [HTML] をクリックします。ファイル名を
sidebar
とします。
各ファイルの内容を次の対応するコードに置き換え、[保存]
をクリックします。
スクリプトを実行する
- Google ドキュメントでページを再読み込みします。
- [拡張機能] > [ドキュメントの翻訳] > [開始] をクリックします。
- プロンプトが表示されたら、アドオンを承認します。承認されると、アドオンが再起動します。
- ドキュメントにテキストを入力して選択します。
- アドオンで [翻訳] をクリックします。ドキュメント内のテキストを置換するには、[挿入] をクリックします。
次のステップ
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-31 UTC。
[null,null,["最終更新日 2025-07-31 UTC。"],[[["\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,[]]