'''' 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 use the REF field options to add'' and customize a reference to a bookmarked paragraph elsewhere'' in the document, either as the paragraph's own list number or'' as a copy of its text.PublicClassRefFieldOptsFunctionCreateDocx() AsGcWordDocumentDim doc = NewGcWordDocument() doc.Body.AddParagraph("A numbered list of requirements:") '' A ListTemplate is used to make paragraphs part of a numbered list:Dim listTemplate = doc.ListTemplates.Add(BuiltInListTemplateId.NumberDefault, "reqList") '' The name of the target bookmark:ConstbmkNameAsString = "reqBookmark" Dim bookmarkedItem AsParagraph = NothingFor i AsInteger = 1To5Dim p = doc.Body.AddParagraph($"Requirement {i}: the system shall do thing #{i}.") p.ListFormat.Template = listTemplate p.ListFormat.LevelNumber = 0'' This ensures item spacing consistent with MS Word: p.Style = doc.Styles(BuiltInStyleId.ListParagraph)If i = 3Then bookmarkedItem = pEndIfNext'' Bookmark the 3rd requirement so it can be referenced elsewhere: bookmarkedItem.GetRange().Bookmarks.Add(bmkName) '' The RefFieldOptions class provides a convenient strong-typed access'' to options specific to the 'REF' MS Word field. This one pulls in'' the bookmarked item's own list number:Dim refByNumber = NewRefFieldOptions(doc, bmkName) With { .DisplayListNumber = DisplayListNumber.AllLevels, .Hyperlink = True }Dim p1 = doc.Body.AddParagraph("As specified in item ").AddComplexField(refByNumber) p1.GetRange().Runs.Add(" above, the system shall comply.") '' This REF pulls in the bookmarked item's text instead, upper-cased:Dim refByText = NewRefFieldOptions(doc, bmkName) With { .StringStyle = StringStyle.Upper } doc.Body.AddParagraph("For emphasis: ").AddComplexField(refByText) '' Update fields using a specific culture: doc.UpdateFields(NewGrapeCity.Documents.Word.Layout.WordLayoutSettings() With { .FontCollection = Util.FontCollection, .Culture = CultureInfo.GetCultureInfo("en-US") }) '' Done:Return docEndFunctionEndClass