Règles et comportement des modifications de structure
Restez organisé à l'aide des collections Enregistrez et classez les contenus selon vos préférences.
Cette section décrit les comportements et les limites que vous devez connaître lorsque vous modifiez des documents à l'aide de l'API Google Docs.
En général, vous ne pouvez pas effectuer de modifications qui entraînent une structure d'éléments non valide dans un document. Vérifiez chaque méthode de requête documents.batchUpdate pour connaître les contraintes et les règles qui s'appliquent à ces requêtes.
Les sections suivantes récapitulent les règles clés de ces méthodes.
Insérer du texte
L'insertion d'un caractère de nouvelle ligne crée implicitement un Paragraph à cet index. Le style de paragraphe du nouveau paragraphe est copié à partir du paragraphe à l'indice d'insertion actuel, y compris les listes et les puces.
Le texte doit être inséré dans les limites d'un Paragraph existant. Par exemple, vous ne pouvez pas insérer de texte à l'index de début d'un tableau. Le texte doit être inséré dans le paragraphe précédent.
L'API peut ajuster implicitement l'emplacement pour éviter les insertions dans les groupes de graphèmes Unicode. Dans ce cas, le texte est inséré immédiatement après le cluster de graphèmes.
Les styles de texte pour le texte inséré sont déterminés automatiquement, en conservant généralement le style du texte voisin. En règle générale, le style de texte du texte inséré correspond au texte immédiatement avant l'indice d'insertion.
Certains caractères de contrôle (U+0000-U+0008, U+000C-U+001F) et caractères de la zone à usage privé du plan multilingue de base Unicode (U+E000-U+F8FF) sont supprimés du texte inséré.
Lorsque vous appliquez une mise en forme au niveau du paragraphe à une plage, elle est appliquée à tous les paragraphes partiellement ou complètement chevauchés par cette plage.
La plage peut être étendue pour inclure les sauts de ligne adjacents.
Si la plage contient entièrement un paragraphe appartenant à une liste, la puce du paragraphe est également mise à jour avec le style de texte correspondant.
Crée des puces pour tous les paragraphes qui chevauchent la plage donnée.
Le niveau d'imbrication de chaque paragraphe est déterminé par le nombre d'onglets avant chaque paragraphe.
Les onglets d'en-tête sont supprimés lors de la création des puces, ce qui peut modifier les indices de certaines parties du texte.
Si vous ajoutez des puces de paragraphe qui correspondent à celles d'une liste immédiatement avant le paragraphe cible, le paragraphe est joint à la liste.
Si vous supprimez du texte qui traverse une limite de paragraphe, les styles de paragraphe, les listes, les objets positionnés et les signets peuvent changer lorsque les deux paragraphes sont fusionnés.
Les suppressions qui entraînent une structure de document non valide ne sont pas autorisées. Voici quelques exemples de requêtes de suppression non valides:
Suppression d'une unité de code d'une paire de substitution.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/01 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Il n'y a pas l'information dont j'ai besoin","missingTheInformationINeed","thumb-down"],["Trop compliqué/Trop d'étapes","tooComplicatedTooManySteps","thumb-down"],["Obsolète","outOfDate","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Mauvais exemple/Erreur de code","samplesCodeIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/08/01 (UTC)."],[],[],null,["This 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- 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- 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- 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- 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- 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- [Structure of a Google Docs document](/workspace/docs/api/concepts/structure)\n- [Requests and responses](/workspace/docs/api/concepts/request-response)"]]