ListNumFieldOpts.cs
C# VB
//// This code is part of Document Solutions for Word demos.// Copyright (c) MESCIUS inc. All rights reserved.//using System.Globalization;using GrapeCity.Documents.Word;using GrapeCity.Documents.Word.Fields;
namespace DsWordWeb.Demos{ // This sample shows how to add a LISTNUM (List Number) field to a Word document, // and specify its options. public class ListNumFieldOpts { public GcWordDocument CreateDocx() { GcWordDocument doc = new();
// Create a new list template: string listName = "MyList"; _ = doc.ListTemplates.Add(BuiltInListTemplateId.OutlineLegal, listName);
// Create options for LISTNUM fields: ListNumFieldOptions options = new(doc) { Name = listName, Level = 1 };
// Create a table: Table table = doc.Body.AddTable( [ ["Step" , "Description"] , [null, "Open the Settings menu."], [null, "Select \"Preferences\" from the list."], [null, "Click \"Save\" to apply changes."], ], doc.Styles[BuiltInStyleId.GridTable1Light]);
// Header style: table.Format.StyleOptions |= TableStyleOptions.FirstRow;
// including LISTNUM fields in the left column table[1, 0].GetRange().Paragraphs.First.GetRange().ComplexFields.Add(options); table[2, 0].GetRange().Paragraphs.First.GetRange().ComplexFields.Add(options); table[3, 0].GetRange().Paragraphs.First.GetRange().ComplexFields.Add(options);
// 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; } }}