'''' This code is part of Document Solutions for Word demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.GlobalizationImportsGrapeCity.Documents.WordImportsGrapeCity.Documents.Word.Fields '' This sample shows how to create a Word document with a Table of Contents (TOC)'' that is built with custom TOC entries created using TC (TOC Entry Item) fields.PublicClassTcFieldOptsFunctionCreateDocx() AsGcWordDocumentDim doc = NewGcWordDocument() Dim pageOpts = NewPageFieldOptions(doc) pageOpts.NumberStyle = NumberStyle.DecimalDim sectionPagesOpts = NewSectionPagesFieldOptions(doc) sectionPagesOpts.NumberStyle = NumberStyle.DecimalDim par = doc.Body.Sections.First.Headers(HeaderFooterType.Primary).Body.AddParagraph("Page ") par.AddComplexField(pageOpts) par.GetRange().Runs.Add(" of ") par.AddComplexField(sectionPagesOpts) Dim tocOpts = NewTocFieldOptions(doc) tocOpts.TcFields.Collect = True tocOpts.EntryFormatting.CreateHyperlink = TrueForEach style AsTocStyleLevelIn tocOpts.Styles style.Collect = TrueNext doc.Body.Paragraphs.Add("Table of Contents", doc.Styles(BuiltInStyleId.TocHeading)).AddComplexField(tocOpts) doc.Body.Paragraphs.Last().GetRange().Runs.Last.AddBreak(BreakType.Page) Dim rnd = Util.NewRandom()Dim i AsInteger = 0DoWhile i < rnd.Next(2, 4)Dim headerText = $"Top-level header {i + 1}"Dim p = doc.Body.AddParagraph(headerText, doc.Styles(BuiltInStyleId.MessageHeader)) Dim tcOpts = NewTcFieldOptions(doc) tcOpts.Content.Text = $"TC Field for {headerText}" tcOpts.DisplayLevel = OutlineLevel.Level1 doc.Body.AddParagraph(Util.LoremIpsumPar()).AddComplexField(tcOpts) Dim j AsInteger = 0DoWhile j < rnd.Next(2, 5) headerText = $"Second-level header {j + 1}" p = doc.Body.AddParagraph(vbTab & headerText, doc.Styles(BuiltInStyleId.MessageHeader)) tcOpts = NewTcFieldOptions(doc) tcOpts.Content.Text = $"TC Field for {headerText}" tcOpts.DisplayLevel = OutlineLevel.Level2 doc.Body.AddParagraph(Util.LoremIpsumPar()).AddComplexField(tcOpts) Dim k AsInteger = 0DoWhile k < rnd.Next(2, 6) headerText = $"Third-level header {k + 1}" p = doc.Body.AddParagraph(vbTab & vbTab & headerText, doc.Styles(BuiltInStyleId.MessageHeader)) tcOpts = NewTcFieldOptions(doc) tcOpts.Content.Text = $"TC Field for {headerText}" tcOpts.DisplayLevel = OutlineLevel.Level3 doc.Body.AddParagraph(Util.LoremIpsumPar()).AddComplexField(tcOpts) k += 1Loop j += 1Loop i += 1Loop doc.Body.AddParagraph("The End.", doc.Styles(BuiltInStyleId.IntenseQuote)) doc.UpdateFields(NewGrapeCity.Documents.Word.Layout.WordLayoutSettings() With { .FontCollection = Util.FontCollection, .Culture = CultureInfo.GetCultureInfo("en-US") }) Return docEndFunctionEndClass