Word Indent is one function for setting paragraph format, which is used to adjust distance between body and page. There are three kinds of indentation, left indentation, right indentation and special indentation. Left and right indentation can set whole paragraph to be indented from left or right. Special indentation includes first line indentation and hanging. Firstline indentation is used to set indentation for first line in a paragraph and hanging to set lines in paragraph to indent except first line. Besides, paragraphs with bullets or numberings will be indented automatically.

Why to set Word indent? Firstly, document layout will be more wonderful with well indentation, especially for printing. Secondly, if there are a special paragraph between body, such as reference or quote paragraph, users can set indentation for whole paragraph to tell readers to pay attention to this paragraph.

In this post, I will introduce a method to set Word indent through adding bullets for paragraphs with C#/VB.NET.

Before starting with coding, I want to notice you that I use a third-party component, Spire.Doc to help me realize this function. If you want to use the following code, please Download Spire.Doc and install it on your computer. Then, add its dll file as reference in your project.


I. Create a new word document. Then, add section and paragraph in this document.


            Document document = new Document();
            Section section = document.AddSection();
            Paragraph paragraph = section.AddParagraph();


            Dim document As New Document()
            Dim section As Section = document.AddSection()
            Dim paragraph As Paragraph = section.AddParagraph()

II. Append text in this  added paragraph to show readers what this example shows. Then, set style for this paragraph. I use built-in style heading 3.


            paragraph.AppendText(“Using items list to show Indent demo.”);
            paragraph = section.AddParagraph();

            paragraph.AppendText(“Using items list to show Indent demo.”)
            paragraph = section.AddParagraph()

III. Set indent. Because indent will be set automatically by adding bullets, so I use a for loop to add bullets. Bullets will be added until the number equals to 10. Firstly, add paragraph and append text in for loop. When appending text, there are two parameters passed, string format and i, which is a variable to control loop times. Secondly, add bullets. If the paragraph is the first one, apply its style as bullets. If not, set list format continuing with first paragraph. Thirdly, set distance between bullets symbol and paragraph string.


            for (int i = 0; i < 10; i++)
                paragraph = section.AddParagraph();
                paragraph.AppendText(String.Format(“Indent Demo Node{0}”, i));
                if (i == 0)
                paragraph.ListFormat.CurrentListLevel.NumberPosition = -10;


            For i As Integer = 0 To 9
                paragraph = section.AddParagraph()
                paragraph.AppendText(String.Format(“Indent Demo Node{0}”, i))
                If i = 0 Then
                End If
                paragraph.ListFormat.CurrentListLevel.NumberPosition = -10
            Next i

IV. Save and Launch file.


            document.SaveToFile(“Indent.docx”, FileFormat.Docx);


            document.SaveToFile(“Indent.docx”, FileFormat.Docx)



For learning more information about Spire.Doc, please Click Here.


One Response

  1. KIelce on 09 Feb 2012

    I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite sure I’ll learn many new stuff right here! Best of luck for the next!

Leave a Reply