กฎและลักษณะการทำงานของการแก้ไขโครงสร้าง
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ส่วนนี้จะอธิบายลักษณะการทำงานและข้อจำกัดที่คุณต้องทำความเข้าใจเมื่อ
แก้ไขเอกสารโดยใช้ Google เอกสาร API
โดยทั่วไปแล้ว คุณจะทำการแก้ไขที่ทำให้โครงสร้างของ
องค์ประกอบภายในเอกสารไม่ถูกต้องไม่ได้ ตรวจสอบแต่ละ
documents.batchUpdate
วิธีการส่งคำขอเพื่อดูข้อจำกัดและกฎที่ใช้กับคำขอเหล่านั้น
ส่วนต่อไปนี้จะสรุปกฎหลักๆ ของวิธีการเหล่านี้
แทรกข้อความ
- การแทรกอักขระขึ้นบรรทัดใหม่จะสร้าง
Paragraph
ที่
ดัชนีนั้นโดยนัย ระบบจะคัดลอกรูปแบบย่อหน้าของย่อหน้าใหม่จาก
ย่อหน้าที่ดัชนีการแทรกปัจจุบัน รวมถึงรายการและหัวข้อย่อย
- ต้องแทรกข้อความภายในขอบเขตของ
Paragraph
ที่มีอยู่ เช่น
แทรกข้อความที่ดัชนีเริ่มต้นของตารางไม่ได้ ต้องแทรกข้อความในย่อหน้าก่อนหน้า
- API อาจปรับตำแหน่งโดยนัยเพื่อป้องกันการแทรกภายใน
กลุ่มกราฟีม Unicode เมื่อเกิดกรณีนี้ ระบบจะแทรกข้อความ
หลังกลุ่มกราฟีมทันที
- ระบบจะกำหนดรูปแบบข้อความสำหรับข้อความที่แทรกโดยอัตโนมัติ ซึ่งโดยทั่วไป
จะรักษาการจัดรูปแบบของข้อความที่อยู่ใกล้เคียง โดยปกติแล้ว รูปแบบข้อความสำหรับ
ข้อความที่แทรกจะตรงกับข้อความที่อยู่ก่อนดัชนีการแทรกทันที
- ระบบจะนำอักขระควบคุมบางตัว (
U+0000-U+0008, U+000C-U+001F
) และอักขระจาก
พื้นที่ใช้งานส่วนตัวของระนาบหลายภาษาพื้นฐานของ Unicode (U+E000-U+F8FF
) ออกจากข้อความที่แทรก
- ดูข้อมูลเพิ่มเติมได้ที่แทรก ลบ และย้ายข้อความ
แทรกรูปภาพในบรรทัด
- รูปภาพต้องมีขนาดไม่เกิน 50 MB, มีความละเอียดไม่เกิน 25 เมกะพิกเซล และต้องอยู่ในรูปแบบ PNG, JPEG หรือ GIF
- URI ที่ระบุต้องเข้าถึงได้แบบสาธารณะและมีความยาวไม่เกิน 2 KB
- ต้องแทรกรูปภาพภายในขอบเขตของ
Paragraph
ที่มีอยู่ เช่น
แทรกข้อความที่ดัชนีเริ่มต้นของตารางไม่ได้
- คุณแทรกรูปภาพภายในเชิงอรรถหรือสมการไม่ได้
- ดูข้อมูลเพิ่มเติมได้ที่แทรกรูปภาพในบรรทัด
จัดรูปแบบข้อความ
- เมื่อใช้การจัดรูปแบบระดับย่อหน้ากับช่วง การจัดรูปแบบจะ
มีผลกับย่อหน้าใดก็ตามที่ช่วงนั้นทับซ้อนกันบางส่วนหรือทั้งหมด
- ระบบอาจขยายช่วงให้รวมบรรทัดใหม่ที่อยู่ติดกัน
- หากช่วงมีทั้งย่อหน้าที่อยู่ในรายการ ระบบจะอัปเดตสัญลักษณ์แสดงหัวข้อย่อยของย่อหน้าด้วยรูปแบบข้อความที่ตรงกันด้วย
- ดูข้อมูลเพิ่มเติมได้ที่จัดรูปแบบ
ข้อความ
สร้างสัญลักษณ์แสดงหัวข้อย่อยของย่อหน้า
- สร้างหัวข้อย่อยสำหรับย่อหน้าทั้งหมดที่ทับซ้อนกับช่วงที่ระบุ
- ระดับการซ้อนของแต่ละย่อหน้าจะกำหนดโดยจำนวนแท็บนำหน้า
ก่อนแต่ละย่อหน้า
- ระบบจะนำแท็บนำออกเมื่อสร้างหัวข้อย่อย ซึ่งอาจเปลี่ยน
ดัชนีของข้อความบางส่วน
- หากคุณเพิ่มสัญลักษณ์หัวข้อย่อยของย่อหน้าซึ่งตรงกับของรายการที่อยู่ก่อนหน้าย่อหน้าเป้าหมายทันที
ระบบจะรวมย่อหน้าเข้ากับรายการ
- ดูข้อมูลเพิ่มเติมได้ที่หัวข้อการทำงานกับรายการ
ลบข้อความ
การลบข้อความที่ข้ามขอบเขตย่อหน้าอาจทำให้เกิดการเปลี่ยนแปลง
รูปแบบย่อหน้า รายการ ออบเจ็กต์ที่วางตำแหน่ง และที่คั่นหน้า เนื่องจากระบบจะผสานย่อหน้า 2 รายการ
เข้าด้วยกัน
ไม่อนุญาตให้ลบข้อมูลที่ทำให้โครงสร้างเอกสารไม่ถูกต้อง ตัวอย่างคำขอลบที่ไม่ถูกต้องมีดังนี้
การลบหน่วยรหัส 1 หน่วยของคู่ตัวแทน
การลบอักขระขึ้นบรรทัดใหม่สุดท้ายของ
Body
,
Header
,
Footer
,
Footnote
,
TableCell
หรือ
TableOfContents
การลบจุดเริ่มต้นหรือจุดสิ้นสุดของ
Table
TableOfContents
หรือ
Equation
โดยไม่ลบทั้งองค์ประกอบ
การลบอักขระขึ้นบรรทัดใหม่ก่อน Table
, TableOfContents
หรือ
SectionBreak
โดยไม่ลบองค์ประกอบ
การลบแถวหรือเซลล์แต่ละรายการในตาราง อนุญาตให้ลบเนื้อหาใน
ตารางได้
ดูข้อมูลเพิ่มเติมได้ที่แทรก ลบ และย้ายข้อความ
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-29 UTC
[null,null,["อัปเดตล่าสุด 2025-08-29 UTC"],[],[],null,["# Structural edit rules and behavior\n\nThis section describes behaviors and limitations that you must understand when\nyou edit documents using the Google Docs API.\n\nIn general, you cannot execute edits that cause the invalid structure of\nelements within a document. Review each\n[`documents.batchUpdate`](/workspace/docs/api/reference/rest/v1/documents/batchUpdate)\nrequest method for constraints and rules that apply to those\n[requests](/workspace/docs/api/reference/rest/v1/documents/request).\n\nThe following sections summarize the key rules across these methods.\n\nInsert text\n-----------\n\n- Inserting a newline character implicitly creates a [`Paragraph`](/workspace/docs/api/reference/rest/v1/documents#paragraph) at that index. The paragraph style of the new paragraph is copied from the paragraph at the current insertion index, including lists and bullets.\n- Text must be inserted within the bounds of an existing `Paragraph`. For example, text cannot be inserted at a table's start index. The text must be inserted in the preceding paragraph.\n- The API may implicitly adjust the location to prevent insertions within Unicode grapheme clusters. When this happens, the text is inserted immediately after the grapheme cluster.\n- Text styles for inserted text are determined automatically, generally preserving the styling of neighboring text. Typically, the text style for the inserted text matches the text immediately before the insertion index.\n- Some control characters (`U+0000-U+0008, U+000C-U+001F`) and characters from the Unicode Basic Multilingual Plane Private Use Area (`U+E000-U+F8FF`) are stripped out of inserted text.\n- For more information, see [Insert, delete, and move\n text](/workspace/docs/api/how-tos/move-text).\n\nInsert inline images\n--------------------\n\n- Image must be less than 50 MB in size, cannot exceed 25 megapixels, and must be in one of PNG, JPEG, or GIF formats.\n- The provided URI must be publicly accessible and at most 2 KB in length.\n- Image must be inserted within the bounds of an existing `Paragraph`. For example, text cannot be inserted at a table's start index.\n- Images can't be inserted inside a footnote or equation.\n- For more information, see [Insert inline\n images](/workspace/docs/api/how-tos/images).\n\nFormat text\n-----------\n\n- When you apply paragraph-level formatting to a range, the formatting is applied to any paragraph that's partially or completely overlapped by that range.\n- The range might be extended to include adjacent newlines.\n- If the range fully contains a paragraph belonging to a list, the paragraph's bullet is also updated with the matching text style.\n- For more information, see [Format\n text](/workspace/docs/api/how-tos/format-text).\n\nCreate paragraph bullets\n------------------------\n\n- Creates bullets for all paragraphs that overlap with the given range.\n- The nesting level of each paragraph is determined by the number of leading tabs before each paragraph.\n- The leading tabs are removed when creating the bullets, which might change the indexes of parts of the text.\n- If you add paragraph bullets that match those of a list immediately before the target paragraph, the paragraph is joined to the list.\n- For more information, see [Work with lists](/workspace/docs/api/how-tos/lists).\n\nDelete text\n-----------\n\n- Deleting text that crosses a paragraph boundary might cause changes to\n paragraph styles, lists, positioned objects, and bookmarks as the two\n paragraphs are merged.\n\n- Deletions that cause an invalid document structure are not permitted. Some\n examples of invalid delete requests include:\n\n - Deleting one code unit of a surrogate pair.\n\n - Deleting the last newline character of a\n [`Body`](/workspace/docs/api/reference/rest/v1/documents#body),\n [`Header`](/workspace/docs/api/reference/rest/v1/documents#header),\n [`Footer`](/workspace/docs/api/reference/rest/v1/documents#footer),\n [`Footnote`](/workspace/docs/api/reference/rest/v1/documents#footnote),\n [`TableCell`](/workspace/docs/api/reference/rest/v1/documents#tablecell), or\n [`TableOfContents`](/workspace/docs/api/reference/rest/v1/documents#tableofcontents).\n\n - Deleting the start or end of a\n [`Table`](/workspace/docs/api/reference/rest/v1/documents#table),\n `TableOfContents`, or\n [`Equation`](/workspace/docs/api/reference/rest/v1/documents#equation)\n without deleting the entire element.\n\n - Deleting the newline character before a `Table`, `TableOfContents`, or\n [`SectionBreak`](/workspace/docs/api/reference/rest/v1/documents#sectionbreak)\n without deleting the element.\n\n - Deleting individual rows or cells of a table. Deleting the content in a\n table cell is allowed.\n\n- For more information, see [Insert, delete, and move\n text](/workspace/docs/api/how-tos/move-text).\n\nRelated topics\n--------------\n\n- [Structure of a Google Docs document](/workspace/docs/api/concepts/structure)\n- [Requests and responses](/workspace/docs/api/concepts/request-response)"]]