Document Solutions for Word
Features / Paragraph / Paragraph Numbering
In This Topic
    Paragraph Numbering
    In This Topic

    DsWord allows you to specify paragraph numbering using the ListTemplate class which can be accessed using ListTemplates property of the DocumentBase class.

    Get Paragraph Numbering

    To get the paragraph numbering:

    1. Access a paragraph from the paragraph collection using Paragraphs property of the RangeBase class.
    2. Get the list formatting specified for the paragraph using ListFormat property of the Paragraph class.
    3. Access list template of the paragraph using Template property of the ListFormat class.
    4. Get the name of the list template using Name property of the ListTemplate class.
    5. Display the paragraph numbering on the console.
      C#
      Copy Code
      //Get paragraph numbering
      ParagraphCollection pars = doc.Body.Sections.First.GetRange().Paragraphs;
      Console.WriteLine("Numbering template for the first paragraph: " + 
          pars[0].ListFormat.Template.Name);
    Back to Top

    Set Paragraph Numbering

    To set the paragraph numbering:

    1. Access the collection of list templates using ListTemplates property of the GcWordDocument class.
    2. Add a new list template to the collection of list templates using Add method of the ListTemplateCollection class.
    3. Access a paragraph from the paragraph collection using Paragraphs property of the RangeBase class.
    4. Get the list formatting specified for the paragraph using ListFormat property of the Paragraph class.
    5. Set list template of the paragraph using Template property of the ListFormat class.
      C#
      Copy Code
      //Set paragraph numbering
      ParagraphCollection pars = doc.Body.Sections.First.GetRange().Paragraphs;
      // A ListTemplate is used to assign ListFormat/numbering to paragraphs
      ListTemplate myListTemplate = doc.ListTemplates.Add(
          BuiltInListTemplateId.NumberArabicParenthesis, "myListTemplate");
      //Set the ListFormat for the paragraphs
      Paragraph p1 = pars[0];
      p1.ListFormat.Template = myListTemplate;
      Paragraph p2 = pars[1];
      p2.ListFormat.Template = myListTemplate;
    Back to Top

    For more information on how to implement paragraph numbering using DsWord, see DsWord sample browser.