結構編輯規則和行為
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本節說明使用 Google 文件 API 編輯文件時,您必須瞭解的行為和限制。
一般來說,您無法執行會導致文件內元素結構無效的編輯作業。請查看每個
documents.batchUpdate
要求方法,瞭解適用於這些要求的限制和規則。
以下各節將摘要說明這些方法的主要規則。
插入文字
- 插入換行字元會在該索引處隱含建立
Paragraph
。新段落的段落樣式會從目前插入索引的段落複製,包括清單和項目符號。
- 文字必須插入現有
Paragraph
的界線內。舉例來說,文字無法插入表格的起始索引。文字必須插入前一段落。
- 為避免在 Unicode 字素叢集內插入內容,API 可能會隱含調整位置。發生這種情況時,系統會將文字插入字素叢集後方。
- 系統會自動決定插入文字的樣式,通常會保留鄰近文字的樣式。一般來說,插入文字的樣式會與插入索引前的文字相符。
- 系統會從插入的文字中移除部分控制字元 (
U+0000-U+0008, U+000C-U+001F
) 和 Unicode 基本多語言平面私人使用區的字元 (U+E000-U+F8FF
)。
- 詳情請參閱「插入、刪除及移動文字」。
插入內嵌圖片
- 圖片大小不得超過 50 MB,像素不得超過 2500 萬,且格式必須為 PNG、JPEG 或 GIF。
- 提供的 URI 必須可公開存取,且長度不得超過 2 KB。
- 圖片必須插入現有
Paragraph
的界線內。舉例來說,文字無法插入表格的起始索引。
- 圖片無法插入註腳或方程式中。
- 詳情請參閱「插入內嵌圖片」。
設定文字格式
- 將段落層級格式套用至範圍時,系統會將格式套用至部分或完全與該範圍重疊的任何段落。
- 範圍可能會擴大,納入相鄰的新行。
- 如果範圍完整包含屬於清單的段落,段落的項目符號也會更新為相符的文字樣式。
- 詳情請參閱「設定文字格式」。
建立段落項目符號
- 為與指定範圍重疊的所有段落建立項目符號。
- 每個段落的巢狀層級取決於各段落前的開頭定位點數量。
- 建立項目符號時,系統會移除前置定位點,這可能會變更部分文字的索引。
- 如果您在目標段落前新增與清單相同的段落項目符號,該段落就會加入清單。
- 詳情請參閱「使用清單」。
刪除文字
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間:2025-08-29 (世界標準時間)。"],[],[],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)"]]