-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommentsActions.cs
101 lines (94 loc) · 3.97 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
using DevExpress.XtraRichEdit.API.Native;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DXRichEditControlAPISample.CodeExamples
{
class CommentsActions {
static void CreateComment(Document document)
{
#region #CreateComment
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
DocumentRange docRange = document.Paragraphs[1].Range;
string commentAuthor = "Maryland B. Clopton";
document.Comments.Create(docRange, commentAuthor, DateTime.Now);
#endregion #CreateComment
}
static void CreateNestedComment(Document document) {
#region #CreateNestedComment
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
if (document.Comments.Count > 0) {
DocumentRange[] resRanges = document.FindAll("trump", SearchOptions.None, document.Comments[1].Range);
if (resRanges.Length > 0) {
Comment newComment = document.Comments.Create("Vicars Anny", document.Comments[1]);
newComment.Date = DateTime.Now;
}
}
#endregion #CreateNestedComment
}
static void DeleteComment(Document document)
{
#region #DeleteComment
CommentHelper.CreateComment(document);
int commentCount = document.Comments.Count;
if (document.Comments.Count > 0)
{
// Uncomment the line below to delete a comment.
//document.Comments.Remove(document.Comments[0]);
}
#endregion #DeleteComment
}
#region #@DeleteComment
class CommentHelper
{
public static void CreateComment(Document document)
{
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
DocumentRange docRange = document.Paragraphs[1].Range;
string commentAuthor = "Maryland B. Clopton";
document.Comments.Create(docRange, commentAuthor);
}
}
#endregion #@DeleteComment
static void EditCommentProperties(Document document)
{
#region #EditCommentProperties
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
int commentCount = document.Comments.Count;
if (commentCount > 0)
{
document.BeginUpdate();
DevExpress.XtraRichEdit.API.Native.Comment comment = document.Comments[document.Comments.Count - 1];
comment.Name = "New Name";
comment.Date = DateTime.Now;
comment.Author = "New Author";
document.EndUpdate();
}
#endregion #EditCommentProperties
}
static void EditCommentContent(Document document)
{
#region #EditCommentContent
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
int commentCount = document.Comments.Count;
if (commentCount > 0)
{
DevExpress.XtraRichEdit.API.Native.Comment comment = document.Comments[document.Comments.Count - 1];
if (comment != null)
{
SubDocument commentDocument = comment.BeginUpdate();
commentDocument.InsertText(commentDocument.CreatePosition(0), "comment text");
commentDocument.Tables.Create(commentDocument.CreatePosition(13), 5, 4);
comment.EndUpdate(commentDocument);
}
}
#endregion #EditCommentContent
}
}
}