结构修改规则和行为
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本部分介绍了使用 Google Docs API 修改文档时必须了解的行为和限制。
一般来说,您无法执行会导致文档中元素结构无效的编辑操作。查看每种 documents.batchUpdate
请求方法,了解适用于这些请求的限制和规则。
以下部分总结了这些方法中的关键规则。
插入文本
- 插入换行符会在相应索引处隐式创建
Paragraph
。新段落的段落样式是从当前插入索引处的段落复制的,包括列表和项目符号。
- 文本必须插入到现有
Paragraph
的边界内。例如,无法在表格的起始索引处插入文本。文本必须插入到上一个段落中。
- 该 API 可能会隐式调整位置,以防止在 Unicode 字形集群内插入内容。发生这种情况时,文本会紧跟在字形集群之后插入。
- 系统会自动确定插入文本的样式,通常会保留相邻文本的样式。通常,插入文本的文字样式与插入索引紧前方的文字样式一致。
- 系统会从插入的文本中去除某些控制字符 (
U+0000-U+0008, U+000C-U+001F
) 和来自 Unicode 基本多语言平面专用区 (U+E000-U+F8FF
) 的字符。
- 如需了解详情,请参阅插入、删除和移动文本。
插入内嵌图片
- 图片大小必须小于 50 MB,像素数不得超过 2500 万,且必须采用 PNG、JPEG 或 GIF 格式。
- 所提供的 URI 必须可以公开访问,且长度不得超过 2 KB。
- 图片必须插入到现有
Paragraph
的边界内。例如,无法在表格的起始索引处插入文本。
- 图片无法插入到脚注或公式中。
- 如需了解详情,请参阅插入内嵌图片。
设置文字格式
- 如果您对某个范围应用段落级格式,则该格式会应用于部分或完全被该范围覆盖的任何段落。
- 范围可能会扩展到包含相邻的换行符。
- 如果范围完全包含属于列表的段落,则段落的项目符号也会更新为匹配的文本样式。
- 如需了解详情,请参阅设置文本格式。
创建段落项目符号
- 为与指定范围重叠的所有段落创建项目符号。
- 每个段落的嵌套级别由每个段落前面的前导制表符数量决定。
- 创建项目符号时,系统会移除前导标签页,这可能会更改部分文本的索引。
- 如果您添加的段落项目符号与目标段落紧前方的列表项目符号一致,则该段落会加入到列表中。
- 如需了解详情,请参阅使用列表。
删除文字
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):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)"]]