-
Notifications
You must be signed in to change notification settings - Fork 9
/
ListsActions.cs
176 lines (137 loc) · 6.95 KB
/
ListsActions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
namespace RichEditDocumentServerAPIExample.CodeExamples
{
class ListsActions
{
public static Action<RichEditDocumentServer> CreateBulletedListAction = CreateBulletedList;
public static Action<RichEditDocumentServer> CreateNumberedListAction = CreateNumberedList;
public static Action<RichEditDocumentServer> CreateMultilevelListAction = CreateMultilevelList;
static void CreateBulletedList(RichEditDocumentServer wordProcessor)
{
#region #CreateBulletedList
// Load a document from a file.
wordProcessor.LoadDocument("Documents//List.docx", DocumentFormat.OpenXml);
// Access a document.
Document document = wordProcessor.Document;
// Start to edit the document.
document.BeginUpdate();
// Create a new list pattern object.
AbstractNumberingList list = document.AbstractNumberingLists.Add();
// Specify the list type.
list.NumberingType = NumberingType.Bullet;
// Access the first list level.
ListLevel level = list.Levels[0];
// Specify the left indent of the level's paragraph.
level.ParagraphProperties.LeftIndent = 100;
// Specify the format of bullets.
// Without this step, the list is considered as numbered.
level.DisplayFormatString = "\u00B7";
level.CharacterProperties.FontName = "Symbol";
// Create a new list based on the specified pattern.
NumberingList bulletedList = document.NumberingLists.Add(0);
// Access the collection of paragraphs.
ParagraphCollection paragraphs = document.Paragraphs;
// Apply the numbering list format to the document paragraphs.
paragraphs.AddParagraphsToList(document.Range, bulletedList, 0);
// Finalize to edit the document.
document.EndUpdate();
#endregion #CreateBulletedList
}
static void CreateNumberedList(RichEditDocumentServer wordProcessor)
{
#region #CreateNumberedList
// Load a document from a file.
wordProcessor.LoadDocument("Documents//List.docx", DocumentFormat.OpenXml);
// Access a document.
Document document = wordProcessor.Document;
// Start to edit the document.
document.BeginUpdate();
// Create a new list pattern object.
AbstractNumberingList abstractListNumberingRoman = document.AbstractNumberingLists.Add();
// Specify the list type.
abstractListNumberingRoman.NumberingType = NumberingType.Simple;
// Specify properties of the first list level.
ListLevel level = abstractListNumberingRoman.Levels[0];
level.ParagraphProperties.LeftIndent = 150;
level.ParagraphProperties.FirstLineIndentType = ParagraphFirstLineIndent.Hanging;
level.ParagraphProperties.FirstLineIndent = 75;
level.Start = 1;
// Specify the numbering style for the list level.
level.NumberingFormat = NumberingFormat.LowerRoman;
level.DisplayFormatString = "{0}.";
// Create a new list based on the specified pattern.
NumberingList numberingList = document.NumberingLists.Add(0);
// Finalize to edit the document.
document.EndUpdate();
// Start to edit the document.
document.BeginUpdate();
// Access the collection of paragraphs.
ParagraphCollection paragraphs = document.Paragraphs;
// Apply the numbering list format to the document paragraphs.
paragraphs.AddParagraphsToList(document.Range, numberingList, 0);
// Finalize to edit the document.
document.EndUpdate();
#endregion #CreateNumberedList
}
static void CreateMultilevelList(RichEditDocumentServer wordProcessor)
{
#region #CreateMultilevelList
// Load a document from a file.
wordProcessor.LoadDocument("Documents//List.docx", DocumentFormat.OpenXml);
// Access a document.
Document document = wordProcessor.Document;
// Start to edit the document.
document.BeginUpdate();
// Create a new list pattern object.
AbstractNumberingList list = document.AbstractNumberingLists.Add();
// Specify the list type.
list.NumberingType = NumberingType.MultiLevel;
// Specify parameters for the first list level.
ListLevel level = list.Levels[0];
level.ParagraphProperties.LeftIndent = 105;
level.ParagraphProperties.FirstLineIndentType = ParagraphFirstLineIndent.Hanging;
level.ParagraphProperties.FirstLineIndent = 55;
level.Start = 1;
level.NumberingFormat = NumberingFormat.UpperRoman;
level.DisplayFormatString = "{0}";
// Specify parameters for the second list level.
level = list.Levels[1];
level.ParagraphProperties.LeftIndent = 125;
level.ParagraphProperties.FirstLineIndentType = ParagraphFirstLineIndent.Hanging;
level.ParagraphProperties.FirstLineIndent = 65;
level.Start = 1;
level.NumberingFormat = NumberingFormat.LowerRoman;
level.DisplayFormatString = "{1})";
// Specify parameters for the third list level.
level = list.Levels[2];
level.ParagraphProperties.LeftIndent = 145;
level.ParagraphProperties.FirstLineIndentType = ParagraphFirstLineIndent.Hanging;
level.ParagraphProperties.FirstLineIndent = 75;
level.Start = 1;
level.NumberingFormat = NumberingFormat.LowerLetter;
level.DisplayFormatString = "{2}.";
// Create a new list based on the specified pattern.
document.NumberingLists.Add(0);
// Finalize to edit the document.
document.EndUpdate();
// Start to edit the document.
document.BeginUpdate();
// Convert all paragraphs to list items.
ParagraphCollection paragraphs = document.Paragraphs;
foreach (Paragraph pgf in paragraphs)
{
pgf.ListIndex = 0;
pgf.ListLevel = pgf.Index;
}
// Finalize to edit the document.
document.EndUpdate();
#endregion #CreateMultilevelList
}
}
}