Table of Contents

Method InsertTableOfContents

Namespace
DocWright.Dom.Editing
Assembly
DocWright.Dom.dll

InsertTableOfContents(WordDocument, DocumentPosition, TableOfContentsOptions?, FieldUpdateOptions?)

Inserts a table of contents at a position, listing the body's headings of the levels asked for, as one undoable edit. Each heading gets a _Toc bookmark round its text (an existing one is reused); the TOCn styles are added as Word defines them when the document has none.

public static DocumentEdit InsertTableOfContents(this WordDocument document, DocumentPosition at, TableOfContentsOptions? options = null, FieldUpdateOptions? fieldOptions = null)

Parameters

document WordDocument

The document that holds the position.

at DocumentPosition

Where the table goes: mid-paragraph, the paragraph is split there (Word's placement).

options TableOfContentsOptions

The levels and links, or null for Word's defaults (levels 1-3, links).

fieldOptions FieldUpdateOptions

What PAGEREF results show (PageReference), or null to leave them empty for layout to draw.

Returns

DocumentEdit

The edit; After is just after the table.

Exceptions

ArgumentNullException

document is null.

ArgumentException

The position is not in document.

ArgumentOutOfRangeException

A level is outside 1-9, or MinLevel is above MaxLevel.

InvalidOperationException

The position's paragraph is not in a block container, or is inside a shape's text box.