Method InsertTableOfContents
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
documentWordDocumentThe document that holds the position.
atDocumentPositionWhere the table goes: mid-paragraph, the paragraph is split there (Word's placement).
optionsTableOfContentsOptionsThe levels and links, or null for Word's defaults (levels 1-3, links).
fieldOptionsFieldUpdateOptionsWhat 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
documentis null.- ArgumentException
The position is not in
document.- ArgumentOutOfRangeException
A level is outside 1-9, or
MinLevelis aboveMaxLevel.- InvalidOperationException
The position's paragraph is not in a block container, or is inside a shape's text box.