//// 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 SECTION and SECTIONPAGES field options// to insert the number of the current section and the number of pages in// the current section into the document.publicclassSectionFieldOpts {publicGcWordDocumentCreateDocx() {var doc = newGcWordDocument(); // SectionFieldOptions provides access to properties specific to the SECTION field:var sectionFldOpts = newSectionFieldOptions(doc); sectionFldOpts.NumberStyle = NumberStyle.UpperRoman; // SectionPagesFieldOptions provides access to properties specific to the SECTIONPAGES field:var sectionPagesFldOpts = newSectionPagesFieldOptions(doc); sectionPagesFldOpts.NumberFormat = "', '0' page(s)'"; // Add a few sections with random content:var rnd = Util.NewRandom();var numSections = rnd.Next(3, 6);for (int i = 0; i < numSections; i++) {var p = doc.Body.AddParagraph("Section ", doc.Styles[BuiltInStyleId.Heading1]); p.AddComplexField(sectionFldOpts); p.AddComplexField(sectionPagesFldOpts);for (int j = 0; j < rnd.Next(5, 10); j++) {var par = Util.LoremIpsumPar(); doc.Body.AddParagraph(par); }if (i < numSections - 1) doc.Body.Paragraphs.Last.AddSectionBreak(SectionStart.Continuous); } // For reference add a simple page header with page number to the document:var phdr = doc.Body.Sections.First.Headers[HeaderFooterType.Primary].Body.AddParagraph(doc.Styles[BuiltInStyleId.Closing]); phdr.AddComplexField(newPageFieldOptions(doc) { NumberFormat = "'Page '0" }); // Update fields using a specific culture: doc.UpdateFields(newGrapeCity.Documents.Word.Layout.WordLayoutSettings() { FontCollection = Util.FontCollection, Culture = CultureInfo.GetCultureInfo("en-US") }); // Done:return doc; } }}