'''' This code is part of Document Solutions for Word demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.GlobalizationImportsSystem.IOImportsGrapeCity.Documents.WordImportsGrapeCity.Documents.Word.Fields '' This sample shows how to insert a TOC (Table of Contents) field'' into an existing DOCX Word document.PublicClassAddTocToDocxFunctionCreateDocx() AsGcWordDocumentDim doc = NewGcWordDocument() doc.Load(Path.Combine("Resources", "WordDocs", "JsFrameworkExcerpt.docx")) Dim tocOpts = NewTocFieldOptions(doc) tocOpts.EntryFormatting.CreateHyperlink = True Dim fo = NewFindOptions(doc) fo.FormattingOptions.ParagraphFormat.PageBreakBefore = TrueDim find = doc.Body.Find("", fo).FirstOrDefault()Dim para AsParagraphIf find IsNotNothingThen para = find.Range.ParentParagraph.GetRange().Paragraphs.Insert("Table of Contents", doc.Styles(BuiltInStyleId.TocHeading), InsertLocation.Before) para = para.GetRange().Paragraphs.Insert(InsertLocation.After)Else para = doc.Body.Paragraphs.Insert("Table of Contents", doc.Styles(BuiltInStyleId.TocHeading), InsertLocation.Start)EndIf para.AddComplexField(tocOpts).Update(NewGrapeCity.Documents.Word.Layout.WordLayoutSettings() With { .FontCollection = Util.FontCollection, .Culture = CultureInfo.GetCultureInfo("en-US") }) Return docEndFunctionEndClass