'''' This code is part of Document Solutions for Word demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.DrawingImportsSystem.GlobalizationImportsGrapeCity.Documents.WordImportsGrapeCity.Documents.Word.Fields '' This sample shows how to use the SEQ field options to enumerate arbitrary'' items in a DOCX Word document: numbered chapters, paragraphs numbered'' continuously across the whole document, and figures numbered independently'' within each chapter.PublicClassSeqFieldOptsFunctionCreateDocx() AsGcWordDocumentDim doc = NewGcWordDocument() '' Three independent SEQ counters are used together in this sample:'' "Chapter" numbers the chapters themselves, "paragraphs" numbers every'' paragraph across the whole document (it is never reset), and "Figure"'' numbers the figures within the current chapter only (it is reset at'' the start of each chapter, see below).Dim paragraphSeqOpts = NewSeqFieldOptions(doc, "paragraphs") With {.NumberFormat = "'Paragraph '0':'"}Dim figureColors() AsColor = {Color.SteelBlue, Color.IndianRed, Color.MediumSeaGreen, Color.Goldenrod}Dim colorIdx AsInteger = 0Dim rnd = Util.NewRandom() For c AsInteger = 1To2'' The chapter heading carries a hidden SEQ field: figure captions'' later in this chapter look this value up by identifier (see below):Dim chHdr = doc.Body.AddParagraph($"Chapter {c}", doc.Styles(BuiltInStyleId.Heading1)) chHdr.AddComplexField(NewSeqFieldOptions(doc, "Chapter") With {.Hidden = True}) '' A couple of numbered paragraphs, continuing the running count'' from the previous chapter:Dim i AsInteger = 0DoWhile i < rnd.Next(2, 4) doc.Body.AddParagraph(doc.Styles(BuiltInStyleId.Heading2)).AddComplexField(paragraphSeqOpts) doc.Body.AddParagraph(Util.LoremIpsumPar()) i += 1Loop '' A couple of figures, each a small placeholder graphic (a filled'' rectangle stands in for a real picture) followed by its caption.For fig AsInteger = 1To2 doc.Body.Paragraphs.Add("")Dim shape = doc.Body.Runs.Last.GetRange().Shapes.Add(120, 80, GeometryType.Rectangle) shape.Fill.Type = FillType.Solid shape.Fill.SolidFill.RGB = figureColors(colorIdx Mod figureColors.Length) colorIdx += 1 '' The NumberFormat picture below uses a `numbered-item` reference'' (backtick-delimited SEQ identifier, per ECMA-376 17.16.4.2): it'' looks backward for the nearest SEQ field with that identifier'' and inlines its number, so a single SEQ field combines the'' chapter number with its own running count to produce'' chapter-scoped captions: "Fig. 11", "Fig. 12" in chapter 1,'' then "Fig. 21", "Fig. 22" in chapter 2 -- without needing a'' separate REF field or a STYLEREF-based chapter lookup.'' Note: a literal separator character placed directly between'' the `identifier` reference and the following digit placeholder'' (e.g. a hyphen for "Fig. 1-1") currently renders as a single'' space instead of that literal character; placing the digit'' placeholder immediately next to the `identifier` (with no'' characters in between) avoids the issue.Dim figFld = doc.Body.AddParagraph().AddComplexField(NewSeqFieldOptions(doc, "Figure") With {.NumberFormat = "'Fig. '`Chapter`0"}) figFld.GetRange().Runs.Add(": a placeholder graphic.")Next'' Reset the figure counter before the next chapter: doc.Body.AddParagraph().AddComplexField(NewSeqFieldOptions(doc, "Figure") With {.Behavior = SeqFieldBehavior.ResetTo, .ResetTo = 0, .Hidden = True})Next '' For reference add a simple page header with page number to the document:Dim phdr = doc.Body.Sections.First.Headers(HeaderFooterType.Primary).Body.AddParagraph(doc.Styles(BuiltInStyleId.Closing)) phdr.AddComplexField(NewPageFieldOptions(doc) With {.NumberFormat = "'Page '0"}) '' 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