構造の編集ルールと動作
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
このセクションでは、Google Docs API を使用してドキュメントを編集する際に理解しておく必要のある動作と制限事項について説明します。
一般に、ドキュメント内の要素の構造が無効になるような編集は実行できません。各 documents.batchUpdate
リクエスト メソッドについて、それらのリクエストに適用される制約とルールを確認します。
以降のセクションでは、これらの方法に共通する主なルールについて説明します。
テキストを挿入
- 改行文字を挿入すると、そのインデックスに
Paragraph
が暗黙的に作成されます。新しい段落の段落スタイルは、リストや箇条書きなど、現在の挿入インデックスにある段落からコピーされます。
- テキストは既存の
Paragraph
の境界内に挿入する必要があります。たとえば、テーブルの開始インデックスにテキストを挿入することはできません。テキストは前の段落に挿入する必要があります。
- API は、Unicode 書記素クラスタ内への挿入を防ぐために、暗黙的に位置を調整する場合があります。この場合、テキストは書記素クラスタの直後に挿入されます。
- 挿入されたテキストのテキスト スタイルは自動的に決定され、通常は隣接するテキストのスタイルが保持されます。通常、挿入されたテキストのテキスト スタイルは、挿入インデックスの直前のテキストと一致します。
- 一部の制御文字(
U+0000-U+0008, U+000C-U+001F
)と Unicode 基本多言語面私用領域(U+E000-U+F8FF
)の文字は、挿入されたテキストから削除されます。
- 詳しくは、テキストの挿入、削除、移動をご覧ください。
インライン画像を挿入する
- 画像のサイズは 50 MB 未満、2,500 万ピクセル以下で、PNG、JPEG、GIF のいずれかの形式である必要があります。
- 指定する URI は一般公開されており、長さが 2 KB 以下である必要があります。
- 画像は既存の
Paragraph
の境界内に挿入する必要があります。たとえば、テーブルの開始インデックスにテキストを挿入することはできません。
- 画像は脚注や数式の中に挿入できません。
- 詳細については、インライン画像を挿入するをご覧ください。
テキストの書式を設定する
- 段落レベルの書式設定を範囲に適用すると、その範囲に一部または完全に重なるすべての段落に書式設定が適用されます。
- 範囲が拡張され、隣接する改行が含まれることがあります。
- 範囲にリストに属する段落が完全に含まれている場合、段落の箇条書きも一致するテキスト スタイルで更新されます。
- 詳しくは、テキストの書式設定をご覧ください。
段落の箇条書きを作成する
- 指定された範囲と重複するすべての段落に箇条書きを作成します。
- 各段落のネストレベルは、各段落の先頭にあるタブの数によって決まります。
- 箇条書きを作成すると、先頭のタブが削除されるため、テキストの一部でインデックスが変更されることがあります。
- リストの直前の段落に、リストの箇条書きと一致する箇条書きを追加すると、その段落はリストに結合されます。
- 詳細については、リストの操作をご覧ください。
テキストを削除する
段落の境界を越えてテキストを削除すると、2 つの段落が結合されるため、段落スタイル、リスト、配置されたオブジェクト、ブックマークが変更されることがあります。
ドキュメント構造が無効になる削除は許可されません。無効な削除リクエストの例は次のとおりです。
詳しくは、テキストの挿入、削除、移動をご覧ください。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 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)"]]