-
Notifications
You must be signed in to change notification settings - Fork 0
/
DocumentFieldActions.vb
65 lines (55 loc) · 2.14 KB
/
DocumentFieldActions.vb
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
Imports DevExpress.XtraRichEdit.API.Native
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Namespace DXRichEditControlAPISample.CodeExamples
Friend Class DocumentFieldActions
Private Shared Sub InsertField(ByVal document As Document)
' #Region "#InsertField"
document.BeginUpdate()
document.Fields.Create(document.CaretPosition, "DATE")
document.Fields.Update()
document.EndUpdate()
' #End Region ' #InsertField
End Sub
Private Shared Sub ModifyFieldCode(ByVal document As Document)
' #Region "#ModifyFieldCode"
Dim caretPosition As DocumentPosition = document.CaretPosition
Dim currentDocument As SubDocument = caretPosition.BeginUpdateDocument()
'Create a DATE field at the caret position
currentDocument.Fields.Create(caretPosition, "DATE")
currentDocument.EndUpdate()
For i As Integer = 0 To currentDocument.Fields.Count - 1
Dim fieldCode As String = document.GetText(currentDocument.Fields(i).CodeRange)
If fieldCode = "DATE" Then
'Retrieve the range obtained by the field code
Dim position As DocumentPosition = currentDocument.Fields(i).CodeRange.End
'Insert the format switch to the end of the field code range
currentDocument.InsertText(position, "\@ ""M/d/yyyy h:mm am/pm""")
End If
Next i
'Update all document fields
currentDocument.Fields.Update()
' #End Region ' #ModifyFieldCode
End Sub
Private Shared Sub CreateFieldFromRange(ByVal document As Document)
' #Region "#CreateFieldFromRange"
document.BeginUpdate()
document.AppendText("SYMBOL 0x54 \f Wingdings \s 24")
document.EndUpdate()
document.Fields.Create(document.Paragraphs(0).Range)
document.Fields.Update()
' #End Region ' #CreateFieldFromRange
End Sub
Private Shared Sub ShowFieldCodes(ByVal document As Document)
' #Region "#ShowFieldCodes"
document.LoadDocument("Documents//MailMergeSimple.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
For i As Integer = 0 To document.Fields.Count - 1
document.Fields(i).ShowCodes = True
Next i
' #End Region ' #ShowFieldCodes
End Sub
End Class
End Namespace