Lists

GemBox.Document supports all common lists: ordered and unordered with various bullet styles and numbering formats.

Following sample demonstrates how to create list (numbering) styles and apply them to paragraphs with different list (indentation) levels.

Screenshot

Lists Screenshot

See the full code below, use RUN EXAMPLE to execute.


1using System;
2using System.Globalization;
3using GemBox.Document;
4
5class Sample
6{
7    [STAThread]
8    static void Main(string[] args)
9    {
10        // If using Professional version, put your serial key below.
11        ComponentInfo.SetLicense("FREE-LIMITED-KEY");
12
13        DocumentModel document = new DocumentModel();
14
15        // First create list style.
16        ListStyle numberList = new ListStyle(ListTemplateType.NumberWithDot);
17
18        // Then set Paragraph.ListFormat.Style and ParagraphListFormat.ListLevelNumber.
19        Paragraph para1 = new Paragraph(document, "First item.");
20        para1.ListFormat.Style = numberList;
21        para1.ParagraphFormat.NoSpaceBetweenParagraphsOfSameStyle = true;
22
23        Paragraph para2 = new Paragraph(document, "Second item.");
24        para2.ListFormat.Style = numberList;
25        para2.ParagraphFormat.NoSpaceBetweenParagraphsOfSameStyle = true;
26
27        Paragraph para2a = new Paragraph(document, "Sub item 2a.");
28        para2a.ListFormat.Style = numberList;
29        para2a.ListFormat.ListLevelNumber++;
30        para2a.ParagraphFormat.NoSpaceBetweenParagraphsOfSameStyle = true;
31
32        Paragraph para2b = new Paragraph(document, "Sub item 2b.");
33        para2b.ListFormat.Style = numberList;
34        para2b.ListFormat.ListLevelNumber++;
35        para2b.ParagraphFormat.NoSpaceBetweenParagraphsOfSameStyle = true;
36
37        Paragraph para3 = new Paragraph(document, "Third item.");
38        para3.ListFormat.Style = numberList;
39        para3.ParagraphFormat.NoSpaceBetweenParagraphsOfSameStyle = true;
40
41        Section section = new Section(document, para1, para2, para2a, para2b, para3);
42        document.Sections.Add(section);
43
44        section.Blocks.Add(new Paragraph(document));
45
46        // Create list style.
47        ListStyle bulletList = new ListStyle(ListTemplateType.Bullet);
48
49        // Use it.
50        section.Blocks.Add(
51            new Paragraph(document, "First item.")
52            {
53                ParagraphFormat = new ParagraphFormat() { NoSpaceBetweenParagraphsOfSameStyle = true },
54                ListFormat = new ListFormat() { Style = bulletList }
55            });
56
57        section.Blocks.Add(
58            new Paragraph(document, "Second item.")
59            {
60                ParagraphFormat = new ParagraphFormat() { NoSpaceBetweenParagraphsOfSameStyle = true },
61                ListFormat = new ListFormat() { Style = bulletList }
62            });
63
64        section.Blocks.Add(
65            new Paragraph(document, "Sub item 2a.")
66            {
67                ParagraphFormat = new ParagraphFormat() { NoSpaceBetweenParagraphsOfSameStyle = true },
68                ListFormat = new ListFormat() { Style = bulletList, ListLevelNumber = 1 }
69            });
70
71        section.Blocks.Add(
72            new Paragraph(document, "Item below sub item 2a.")
73            {
74                ParagraphFormat = new ParagraphFormat() { NoSpaceBetweenParagraphsOfSameStyle = true },
75                ListFormat = new ListFormat() { Style = bulletList, ListLevelNumber = 2 }
76            });
77
78        section.Blocks.Add(
79            new Paragraph(document, "Third item.")
80            {
81                ParagraphFormat = new ParagraphFormat() { NoSpaceBetweenParagraphsOfSameStyle = true },
82                ListFormat = new ListFormat() { Style = bulletList }
83            });
84
85        document.Save("Lists.docx");
86    }
87}
1Imports System
2Imports System.Globalization
3Imports GemBox.Document
4
5Module Samples
6
7    Sub Main()
8
9        ' If using Professional version, put your serial key below.
10        ComponentInfo.SetLicense("FREE-LIMITED-KEY")
11
12        Dim document As DocumentModel = New DocumentModel
13
14        ' First create list style.
15        Dim numberList As New ListStyle(ListTemplateType.NumberWithDot)
16
17        ' Then set Paragraph.ListFormat.Style and ParagraphListFormat.ListLevelNumber.
18        Dim para1 As New Paragraph(document, "First item.")
19        para1.ListFormat.Style = numberList
20        para1.ParagraphFormat.NoSpaceBetweenParagraphsOfSameStyle = True
21
22        Dim para2 As New Paragraph(document, "Second item.")
23        para2.ListFormat.Style = numberList
24        para2.ParagraphFormat.NoSpaceBetweenParagraphsOfSameStyle = True
25
26        Dim para2a As New Paragraph(document, "Sub item 2a.")
27        para2a.ListFormat.Style = numberList
28        para2a.ListFormat.ListLevelNumber += 1
29        para2a.ParagraphFormat.NoSpaceBetweenParagraphsOfSameStyle = True
30
31        Dim para2b As New Paragraph(document, "Sub item 2b.")
32        para2b.ListFormat.Style = numberList
33        para2b.ListFormat.ListLevelNumber += 1
34        para2b.ParagraphFormat.NoSpaceBetweenParagraphsOfSameStyle = True
35
36        Dim para3 As New Paragraph(document, "Third item.")
37        para3.ListFormat.Style = numberList
38        para3.ParagraphFormat.NoSpaceBetweenParagraphsOfSameStyle = True
39
40        Dim section As New Section(document, para1, para2, para2a, para2b, para3)
41        document.Sections.Add(section)
42
43        section.Blocks.Add(New Paragraph(document))
44
45        ' Create list style.
46        Dim bulletList As New ListStyle(ListTemplateType.Bullet)
47
48        ' Use it.
49        section.Blocks.Add(
50            New Paragraph(document, "First item.") With {
51                .ParagraphFormat = New ParagraphFormat() With {
52                    .NoSpaceBetweenParagraphsOfSameStyle = True
53                },
54                .ListFormat = New ListFormat() With {
55                    .Style = bulletList
56                }})
57
58        section.Blocks.Add(
59            New Paragraph(document, "Second item.") With {
60                .ParagraphFormat = New ParagraphFormat() With {
61                    .NoSpaceBetweenParagraphsOfSameStyle = True
62                },
63                .ListFormat = New ListFormat() With {
64                    .Style = bulletList
65                }})
66
67        section.Blocks.Add(
68            New Paragraph(document, "Sub item 2a.") With {
69                .ParagraphFormat = New ParagraphFormat() With {
70                    .NoSpaceBetweenParagraphsOfSameStyle = True
71                },
72                .ListFormat = New ListFormat() With {
73                    .Style = bulletList,
74                    .ListLevelNumber = 1
75                }})
76
77        section.Blocks.Add(
78            New Paragraph(document, "Item below sub item 2a.") With {
79                .ParagraphFormat = New ParagraphFormat() With {
80                    .NoSpaceBetweenParagraphsOfSameStyle = True
81                },
82                .ListFormat = New ListFormat() With {
83                    .Style = bulletList,
84                    .ListLevelNumber = 2
85                }})
86
87        section.Blocks.Add(
88            New Paragraph(document, "Third item.") With {
89                .ParagraphFormat = New ParagraphFormat() With {
90                    .NoSpaceBetweenParagraphsOfSameStyle = True
91                },
92                .ListFormat = New ListFormat() With {
93                    .Style = bulletList
94                }})
95
96        document.Save("Lists.docx")
97
98    End Sub
99
100End Module

Check next sample or find out more about GemBox.Document and GemBox Software.