-
Notifications
You must be signed in to change notification settings - Fork 9
/
RangeActions.cs
102 lines (82 loc) · 3.97 KB
/
RangeActions.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 System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
namespace RichEditDocumentServerAPIExample.CodeExamples
{
class RangeActions
{
public static Action<RichEditDocumentServer> InsertTextInRangeAction = InsertTextInRange;
public static Action<RichEditDocumentServer> AppendTextToRangeAction = AppendTextToRange;
public static Action<RichEditDocumentServer> AppendToParagraphAction = AppendToParagraph;
static void InsertTextInRange(RichEditDocumentServer wordProcessor)
{
#region #InsertTextInRange
// Access a document.
Document document = wordProcessor.Document;
// Append text to the document.
document.AppendText("ABCDEFGH");
// Create the first document range.
DocumentRange range1 = document.CreateRange(1, 3);
// Insert text into the first document range
// and access the range of the inserted text.
DocumentRange range2 = document.InsertText(range1.End, ">>NewText<<");
// Output the start and end positions of the first document range.
string text1 = String.Format("Range range1 starts at {0}, ends at {1}", range1.Start, range1.End);
document.Paragraphs.Append();
document.AppendText(text1);
// Output the start and end positions of the second document range.
string text2 = String.Format("Range range2 starts at {0}, ends at {1}", range2.Start, range2.End);
document.Paragraphs.Append();
document.AppendText(text2);
#endregion #InsertTextInRange
}
static void AppendTextToRange(RichEditDocumentServer wordProcessor)
{
#region #AppendTextToRange
// Access a document.
Document document = wordProcessor.Document;
// Append text to the document.
document.AppendText("abcdefgh");
// Append text and access the range of the added text.
DocumentRange r1 = document.AppendText("X");
string s1 = String.Format("Range r1 starts at {0}, ends at {1}", r1.Start, r1.End);
// Append text and access the updated range of the added text.
document.AppendText("Y");
document.AppendText("Z");
string s2 = String.Format("Currently range r1 starts at {0}, ends at {1}", r1.Start, r1.End);
// Output the start and end positions of the document range.
document.Paragraphs.Append();
document.AppendText(s1);
// Output the updated start and end positions of the document range.
document.Paragraphs.Append();
document.AppendText(s2);
#endregion #AppendTextToRange
}
static void AppendToParagraph(RichEditDocumentServer wordProcessor)
{
#region #AppendToParagraph
// Access a document.
Document document = wordProcessor.Document;
// Start to edit the document.
document.BeginUpdate();
// Append text to the end of each paragraph.
document.AppendText("First Paragraph\nSecond Paragraph\nThird Paragraph");
// Finalize to edit the document.
document.EndUpdate();
// Access the end position of the document range.
DocumentPosition pos = document.Range.End;
// Append text to the end of the last paragraph.
SubDocument doc = pos.BeginUpdateDocument();
Paragraph par = doc.Paragraphs.Get(pos);
DocumentPosition newPos = doc.CreatePosition(par.Range.End.ToInt() - 1);
doc.InsertText(newPos, "<<Appended to Paragraph End>>");
pos.EndUpdateDocument(doc);
#endregion #AppendToParagraph
}
}
}