Методы добавления оглавления и нумерации в Документах Google

Чтобы добавить оглавление и нумерацию в Документы Google, вы можете использовать разные методы. Вот несколько подходов с примерами кода:

  1. Использование функции «Оглавление»:

    # Set the document to have a table of contents
    document = DocumentApp.getActiveDocument();
    document.setShowTableOfContents(true);
  2. Вставка оглавления вручную:

    # Insert a table of contents at the cursor position
    document = DocumentApp.getActiveDocument();
    body = document.getBody();
    cursorPosition = document.getCursor().getElement();
    tableOfContents = body.insertTableOfContents(cursorPosition);
  3. Использование заголовков со встроенной нумерацией:

    # 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');
  4. Пользовательская нумерация элементов списка:

    # 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