Reguły i sposób edytowania strukturalnego
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
W tej sekcji opisujemy zachowania i ograniczenia, które musisz znać podczas edytowania dokumentów za pomocą interfejsu Google Docs API.
Zasadniczo nie możesz wprowadzać zmian, które powodują nieprawidłową strukturę elementów w dokumencie. Sprawdź każdą metodę żądania
documents.batchUpdate
pod kątem ograniczeń i reguł, które mają zastosowanie do tych żądań.
W sekcjach poniżej znajdziesz podsumowanie najważniejszych zasad dotyczących tych metod.
Wstaw tekst
- Wstawienie znaku nowego wiersza powoduje niejawne utworzenie elementu
Paragraph
w tym indeksie. Styl akapitu nowego akapitu jest kopiowany z akapitu w bieżącym indeksie wstawiania, w tym listy i punktorów.
- Tekst musi być wstawiony w obrębie istniejącego elementu
Paragraph
. Na przykład nie można wstawić tekstu w indeksie początkowym tabeli. Tekst musi zostać wstawiony w poprzednim akapicie.
- Interfejs API może niejawnie dostosować lokalizację, aby zapobiec wstawianiu w obrębie klastrów grafemów Unicode. W takim przypadku tekst jest wstawiany bezpośrednio po klastrze grafemów.
- Style tekstu wstawionego są określane automatycznie, zwykle z zachowaniem stylu sąsiedniego tekstu. Zwykle styl tekstu wstawionego jest taki sam jak styl tekstu bezpośrednio przed indeksem wstawienia.
- Niektóre znaki sterujące (
U+0000-U+0008, U+000C-U+001F
) i znaki z obszaru prywatnego użytku podstawowej wielojęzycznej płaszczyzny Unicode (U+E000-U+F8FF
) są usuwane z wstawianego tekstu.
- Więcej informacji znajdziesz w artykule Wstawianie, usuwanie i przenoszenie tekstu.
Wstawianie obrazów w treści
- Obraz musi mieć rozmiar mniejszy niż 50 MB, nie może przekraczać 25 megapikseli i musi być w jednym z formatów PNG, JPEG lub GIF.
- Podany identyfikator URI musi być dostępny publicznie i mieć maksymalnie 2 KB.
- Obraz musi być wstawiony w granicach istniejącego elementu
Paragraph
. Na przykład nie można wstawić tekstu w indeksie początkowym tabeli.
- Obrazów nie można wstawiać w przypisach ani równaniach.
- Więcej informacji znajdziesz w artykule Wstawianie obrazów w tekście.
Formatowanie tekstu
- Gdy zastosujesz formatowanie na poziomie akapitu do zakresu, formatowanie zostanie zastosowane do każdego akapitu, który jest częściowo lub całkowicie objęty tym zakresem.
- Zakres może zostać rozszerzony o sąsiednie znaki nowego wiersza.
- Jeśli zakres w pełni zawiera akapit należący do listy, punktor akapitu jest również aktualizowany o pasujący styl tekstu.
- Więcej informacji znajdziesz w artykule Formatowanie tekstu.
Tworzenie punktorów akapitów
- Tworzy punktor dla wszystkich akapitów, które pokrywają się z podanym zakresem.
- Poziom zagnieżdżenia każdego akapitu jest określany przez liczbę tabulatorów na początku akapitu.
- Podczas tworzenia punktorów wiodące tabulatory są usuwane, co może zmienić indeksy części tekstu.
- Jeśli dodasz wypunktowania akapitów, które pasują do wypunktowań listy bezpośrednio przed akapitem docelowym, akapit zostanie dołączony do listy.
- Więcej informacji znajdziesz w artykule Praca z listami.
Usuń tekst
Usunięcie tekstu, który przekracza granicę akapitu, może spowodować zmiany w stylach akapitów, listach, obiektach umieszczonych i zakładkach, ponieważ 2 akapity zostaną połączone.
Usuwanie elementów, które powodują nieprawidłową strukturę dokumentu, jest niedozwolone. Oto kilka przykładów nieprawidłowych żądań usunięcia:
Usunięcie 1 jednostki kodu z pary zastępczej.
Usunięcie ostatniego znaku nowego wiersza w przypadku Body
, Header
, Footer
, Footnote
, TableCell
lub TableOfContents
.
Usuwanie początku lub końca elementu Table
, TableOfContents
lub Equation
bez usuwania całego elementu.
Usunięcie znaku nowego wiersza przed znakiem Table
, TableOfContents
lub SectionBreak
bez usuwania elementu.
usuwanie poszczególnych wierszy lub komórek tabeli; Usuwanie treści w komórce tabeli jest dozwolone.
Więcej informacji znajdziesz w artykule Wstawianie, usuwanie i przenoszenie tekstu.
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-08-29 UTC.
[null,null,["Ostatnia aktualizacja: 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)"]]