//
// 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 GrapeCity.Documents.Word;
namespace DsWordWeb.Demos
{
// This sample demonstrates how to create a numbered list
// with three levels.
// See the Bullets sample for how to create a bullet list.
public class NumberedList
{
public GcWordDocument CreateDocx()
{
GcWordDocument doc = new GcWordDocument();
var pars = doc.Body.Sections.First.GetRange().Paragraphs;
pars.Add("A numbered list with 3 levels:");
// A ListTemplate is used to make paragraphs part of a list:
var myListTemplate = doc.ListTemplates.Add(BuiltInListTemplateId.NumberDefault, "myListTemplate");
// Add a 3-level numbered nested list:
addItem("Top item 1", 0);
addItem("Top item 2", 0);
addItem("Top item 3", 0);
addItem("Nested item 1", 1);
addItem("Nested item 2", 1);
addItem("Double nested item 1", 2);
addItem("Double nested item 2", 2);
addItem("Double nested item 3", 2);
addItem("Nested item 3", 1);
addItem("Nested item 4", 1);
addItem("Top item 4", 0);
addItem("Top item 5", 0);
// Done:
return doc;
void addItem(string t_, int l_)
{
var p_ = pars.Add(t_);
// This makes a paragraph a list item:
p_.ListFormat.Template = myListTemplate;
// Set the item's nesting level (first level is 0):
p_.ListFormat.LevelNumber = l_;
// This ensures item spacing consistent with MS Word:
p_.Style = doc.Styles[BuiltInStyleId.ListParagraph];
}
}
}
}