SeqFieldOpts.cs
//
// This code is part of Document Solutions for Word demos.
// Copyright (c) MESCIUS inc. All rights reserved.
//
using System;
using System.IO;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
using GrapeCity.Documents.Word;
using GrapeCity.Documents.Word.Fields;

namespace DsWordWeb.Demos
{
    // This sample shows how to use the SEQ field options
    // to enumerate arbitrary items in a DOCX Word document.
    public class SeqFieldOpts
    {
        public GcWordDocument CreateDocx()
        {
            var doc = new GcWordDocument();

            // Add a simple page header to the document:
            var phdr = doc.Body.Sections.First.Headers[HeaderFooterType.Primary].Body.AddParagraph(doc.Styles[BuiltInStyleId.Closing]);
            phdr.AddComplexField(new PageFieldOptions(doc) { NumberFormat = "'Page '0" });

            // SeqFieldOptions provides access to properties specific to the SEQ field:
            const string seqId = "paragraphs";
            var seqFldOpts = new SeqFieldOptions(doc, seqId);
            seqFldOpts.NumberFormat = "'Paragraph '0':'";

            // Add numbered paragraphs to the document using the SEQ field:
            var rnd = Util.NewRandom();
            for (int i = 0; i < rnd.Next(10, 20); i++)
            {
                doc.Body.AddParagraph(doc.Styles[BuiltInStyleId.Heading2]).AddComplexField(seqFldOpts);
                doc.Body.AddParagraph(Util.LoremIpsumPar());
            }

            // Update fields using a specific culture:
            doc.UpdateFields(new GrapeCity.Documents.Word.Layout.WordLayoutSettings() { FontCollection = Util.FontCollection, Culture = CultureInfo.GetCultureInfo("en-US") });

            // Done:
            return doc;
        }
    }
}