Чтобы добавить оглавление и нумерацию в Документы Google, вы можете использовать разные методы. Вот несколько подходов с примерами кода:
-
Использование функции «Оглавление»:
# Set the document to have a table of contents document = DocumentApp.getActiveDocument(); document.setShowTableOfContents(true);
-
Вставка оглавления вручную:
# Insert a table of contents at the cursor position document = DocumentApp.getActiveDocument(); body = document.getBody(); cursorPosition = document.getCursor().getElement(); tableOfContents = body.insertTableOfContents(cursorPosition);
-
Использование заголовков со встроенной нумерацией:
# Insert headings with built-in numbering document = DocumentApp.getActiveDocument(); body = document.getBody(); body.appendParagraph('1. Heading 1'); body.appendParagraph('2. Heading 2'); body.appendParagraph('2.1. Subheading 1');
-
Пользовательская нумерация элементов списка:
# Insert custom numbering with list items document = DocumentApp.getActiveDocument(); body = document.getBody(); listItem1 = body.appendListItem('Item 1'); listItem2 = body.appendListItem('Item 2'); listItem2.setIndentStart(18); # Set the desired indentation in points listItem2.setGlyphType(DocumentApp.GlyphType.LOWER_ALPHA); # Set the desired numbering style