//// This code is part of Document Solutions for Word demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.Globalization;usingGrapeCity.Documents.Word;usingGrapeCity.Documents.Word.Fields; namespaceDsWordWeb.Demos{// 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.publicclassRefFieldOpts {publicGcWordDocumentCreateDocx() {var doc = newGcWordDocument(); doc.Body.AddParagraph("A numbered list of requirements:"); // A ListTemplate is used to make paragraphs part of a numbered list:var listTemplate = doc.ListTemplates.Add(BuiltInListTemplateId.NumberDefault, "reqList"); // The name of the target bookmark:conststringbmkName = "reqBookmark"; Paragraph bookmarkedItem = null;for (int i = 1; i <= 5; i++) {var 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 == 3) bookmarkedItem = p; }// 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:var refByNumber = newRefFieldOptions(doc, bmkName) {DisplayListNumber = DisplayListNumber.AllLevels,Hyperlink = true }; doc.Body.AddParagraph("As specified in item ").AddComplexField(refByNumber) .GetRange().Runs.Add(" above, the system shall comply."); // This REF pulls in the bookmarked item's text instead, upper-cased:var refByText = newRefFieldOptions(doc, bmkName) {StringStyle = StringStyle.Upper }; doc.Body.AddParagraph("For emphasis: ").AddComplexField(refByText); // Update fields using a specific culture: doc.UpdateFields(newGrapeCity.Documents.Word.Layout.WordLayoutSettings() { FontCollection = Util.FontCollection, Culture = CultureInfo.GetCultureInfo("en-US") }); // Done:return doc; } }}