This project has moved. For the latest updates, please go here.

Bulleting and numbering for headers from C#

Feb 28, 2012 at 5:06 PM


I am using docx library and i want to write a set of headers on a word file like this

1         This is level 1

1.1       This is level 1.1

1.2       This is level 1.2

2         This is level 2

2.1       This is level2.1

2.1.1       This is leve 2.1.1


If anyone know how to do it please reply to me.

This would be a great help for me from this community




Nov 15, 2012 at 6:22 PM

May not be the easiest way, but this works;

Create a document template that includes the section numbering set up the way you want it, using heading styles. Load the document, and use that as the starting point. When you add text, set the stylename to the appropriate style, and the numbering should be generated automatically. The correct stylename settings are "Heading1", "Heading2" and "Heading3". Here's the basic approach;


dim p1 as newdoc.insertparagraph

p1.stylename = "Heading1"

p1.append "This is level 1"

dim p2 as newdoc.insertparagraph

p2.stylename = "Heading2"

p2.append "This is level 1.1"

Mar 26, 2014 at 9:31 AM
Edited Mar 26, 2014 at 10:35 AM
I've just made this into an extension method
public static class ExtensionMethods
    public static Paragraph Heading1(this Paragraph paragraph)
        paragraph.StyleName = "Heading1";
        return paragraph;
Paragraph pTitle = document.InsertParagraph();