-
Notifications
You must be signed in to change notification settings - Fork 9
/
CommentsActions.cs
143 lines (118 loc) · 5.31 KB
/
CommentsActions.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.XtraRichEdit;
using System.Diagnostics;
namespace RichEditDocumentServerAPIExample.CodeExamples
{
public class CommentsActions
{
public static Action<RichEditDocumentServer> CreateCommentAction = CreateComment;
public static Action<RichEditDocumentServer> CreateNestedCommentAction = CreateNestedComment;
public static Action<RichEditDocumentServer> DeleteCommentAction = DeleteComment;
public static Action<RichEditDocumentServer> EditCommentPropertiesAction = EditCommentProperties;
public static Action<RichEditDocumentServer> EditCommentContentAction = EditCommentContent;
static void CreateComment(RichEditDocumentServer wordProcessor)
{
#region #CreateComment
// Load a document from a file.
wordProcessor.LoadDocument("Documents\\Grimm.docx", DocumentFormat.OpenXml);
// Access a document.
Document document = wordProcessor.Document;
if (document.Paragraphs.Count > 2)
{
// Access the range of the third paragraph.
DocumentRange docRange = document.Paragraphs[2].Range;
// Specify the comment's author name.
string commentAuthor = "Johnson Alphonso D";
// Create a comment.
document.Comments.Create(docRange, commentAuthor, DateTime.Now);
}
#endregion #CreateComment
}
static void CreateNestedComment(RichEditDocumentServer wordProcessor)
{
#region #CreateNestedComment
// Load a document from a file.
wordProcessor.LoadDocument("Documents\\Grimm.docx", DocumentFormat.OpenXml);
// Access a document.
Document document = wordProcessor.Document;
if (document.Comments.Count > 1)
{
// Create a new comment nested in the parent comment.
Comment newComment = document.Comments.Create("Vicars Anny", document.Comments[1]);
newComment.Date = DateTime.Now;
SubDocument commentDocument = newComment.BeginUpdate();
commentDocument.InsertText(commentDocument.Range.Start, "I agree");
newComment.EndUpdate(commentDocument);
}
#endregion #CreateNestedComment
}
static void DeleteComment(RichEditDocumentServer wordProcessor)
{
#region #DeleteComment
// Load a document from a file.
wordProcessor.LoadDocument("Documents\\Grimm.docx", DocumentFormat.OpenXml);
// Access a document.
Document document = wordProcessor.Document;
if (document.Comments.Count > 0)
{
// Delete the first comment.
document.Comments.Remove(document.Comments[0]);
}
#endregion #DeleteComment
}
static void EditCommentProperties(RichEditDocumentServer wordProcessor)
{
#region #EditCommentProperties
// Load a document from a file.
wordProcessor.LoadDocument("Documents\\Grimm.docx", DocumentFormat.OpenXml);
// Access a document.
Document document = wordProcessor.Document;
int commentCount = document.Comments.Count;
if (commentCount > 0)
{
// Start to edit the document.
document.BeginUpdate();
// Access a comment and edit its properties.
Comment comment = document.Comments[document.Comments.Count - 1];
comment.Name = "New Name";
comment.Date = DateTime.Now;
comment.Author = "New Author";
// Finalize to edit the document.
document.EndUpdate();
}
#endregion #EditCommentProperties
}
static void EditCommentContent(RichEditDocumentServer wordProcessor)
{
#region #EditCommentContent
// Load a document from a file.
wordProcessor.LoadDocument("Documents\\Grimm.docx", DocumentFormat.OpenXml);
// Access a document.
Document document = wordProcessor.Document;
int commentCount = document.Comments.Count;
if (commentCount > 0)
{
// Access a comment.
Comment comment = document.Comments[document.Comments.Count - 1];
if (comment != null)
{
// Start to edit the comment.
SubDocument commentDocument = comment.BeginUpdate();
// Insert a text to the comment.
commentDocument.Paragraphs.Insert(commentDocument.Range.Start);
commentDocument.InsertText(commentDocument.Range.Start, "some text");
// Insert a table to the comment.
commentDocument.Tables.Create(commentDocument.Range.End, 5, 4);
// Finalize to edit the comment.
comment.EndUpdate(commentDocument);
}
}
#endregion #EditCommentContent
}
}
}