//
// 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 add an AUTONUM (Automatic Numbering) field to a Word document,
// and specify its options.
public class AutoNumFieldOpts
{
public GcWordDocument CreateDocx()
{
GcWordDocument doc = new();
// create options to insert AUTONUM fields in the document
AutoNumFieldOptions options = new(doc);
// create a structure of paragraphs with different outline level
// and insert AUTONUM field to the beginning of each paragraph
// to automatically number them
Paragraph p = doc.Body.AddParagraph("Heading 1", doc.Styles[BuiltInStyleId.Heading1]);
p.GetRange().ComplexFields.Insert(options, InsertLocation.Start);
p = doc.Body.AddParagraph("Heading 2", doc.Styles[BuiltInStyleId.Heading2]);
p.GetRange().ComplexFields.Insert(options, InsertLocation.Start);
p = doc.Body.AddParagraph("Heading 2", doc.Styles[BuiltInStyleId.Heading2]);
p.GetRange().ComplexFields.Insert(options, InsertLocation.Start);
p = doc.Body.AddParagraph("Heading 3", doc.Styles[BuiltInStyleId.Heading3]);
p.GetRange().ComplexFields.Insert(options, InsertLocation.Start);
p = doc.Body.AddParagraph("Heading 3", doc.Styles[BuiltInStyleId.Heading3]);
p.GetRange().ComplexFields.Insert(options, InsertLocation.Start);
p = doc.Body.AddParagraph("Heading 1", doc.Styles[BuiltInStyleId.Heading1]);
p.GetRange().ComplexFields.Insert(options, InsertLocation.Start);
p = doc.Body.AddParagraph("Heading 2", doc.Styles[BuiltInStyleId.Heading2]);
p.GetRange().ComplexFields.Insert(options, InsertLocation.Start);
// 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;
}
}
}