คำแนะนำเริ่มต้นใช้งานส่วนเสริมของเครื่องมือแก้ไข Google เอกสาร
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
คู่มือเริ่มต้นฉบับนี้จะสร้างส่วนเสริมของเครื่องมือแก้ไขเอกสารของ Google ที่แปล
ข้อความที่เลือกในเอกสาร
วัตถุประสงค์
- ตั้งค่าสคริปต์
- เรียกใช้สคริปต์
ข้อกำหนดเบื้องต้น
หากต้องการใช้ตัวอย่างนี้ คุณต้องมีข้อกำหนดเบื้องต้นต่อไปนี้
- บัญชี Google (บัญชี Google Workspace อาจต้องได้รับการอนุมัติจากผู้ดูแลระบบ)
- เว็บเบราว์เซอร์ที่มีสิทธิ์เข้าถึงอินเทอร์เน็ต
ตั้งค่าสคริปต์
- สร้างเอกสารใน Google เอกสารที่ docs.new
- คลิกส่วนขยาย > Apps Script
- คลิกโปรเจ็กต์ที่ไม่มีชื่อ
- เปลี่ยนชื่อโปรเจ็กต์ Apps Script เป็น Translate Docs แล้วคลิกเปลี่ยนชื่อ
- คลิกเพิ่มเติม more_vert ข้าง
Code.gs
ไฟล์
> เปลี่ยนชื่อ ตั้งชื่อไฟล์ 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,[]]