-
Notifications
You must be signed in to change notification settings - Fork 9
/
ContentControlsActions.cs
90 lines (76 loc) · 4.1 KB
/
ContentControlsActions.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
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using System;
using System.Drawing;
namespace RichEditDocumentServerAPIExample.CodeExamples
{
public static class ContentControlsActions
{
public static Action<RichEditDocumentServer> CreateContentControlsAction = CreateContentControls;
public static Action<RichEditDocumentServer> ChangeContentControlsAction = ChangeContentControls;
public static Action<RichEditDocumentServer> RemoveContentControlsAction = RemoveContentControls;
static void CreateContentControls(RichEditDocumentServer wordProcessor)
{
#region #CreateContentControls
wordProcessor.LoadDocument("Documents\\Simple Form.docx");
Document document = wordProcessor.Document;
var contentControls = document.ContentControls;
// Insert a form to enter a name:
var namePosition = document.CreatePosition(document.Paragraphs[0].Range.End.ToInt() - 1);
var nameControl = contentControls.InsertPlainTextControl(namePosition);
// Insert text in a content control:
var nameTextPosition = document.CreatePosition(nameControl.Range.Start.ToInt() + 1);
document.InsertText(nameTextPosition, "Click to enter a name");
// Insert a drop-down list to select the appointment type:
var listPosition = document.CreatePosition(document.Paragraphs[1].Range.End.ToInt() - 1);
var listControl = contentControls.InsertDropDownListControl(listPosition);
// Add items to the drop-down list:
listControl.AddItem("First Appointment", "First Appointment");
listControl.AddItem("Follow-Up Appointment", "Follow-Up Appointment");
listControl.AddItem("Laboratory Results Check", "Laboratory Results Check");
listControl.SelectedItemIndex = 1;
// Insert a date picker to select the appointment date:
var datePosition = document.CreatePosition(document.Paragraphs[2].Range.End.ToInt() - 1);
var datePicker = contentControls.InsertDatePickerControl(datePosition);
datePicker.DateFormat = "dddd, MMMM dd, yyyy";
// Insert a checkbox:
var checkboxControl = contentControls.InsertCheckboxControl(document.Paragraphs[3].Range.Start);
checkboxControl.Checked = false;
#endregion #CreateContentControls
}
private static void ChangeContentControls(RichEditDocumentServer wordProcessor)
{
#region #ChangeContentControlParameters
wordProcessor.LoadDocument("Documents\\Simple Form Filled.docx");
Document document = wordProcessor.Document;
var contentControls = document.ContentControls;
foreach (var contentControl in contentControls) {
contentControl.Color = Color.Red;
switch (contentControl.ControlType) {
case ContentControlType.RichText:
case ContentControlType.PlainText:
contentControl.IsTemporary = true;
break;
case ContentControlType.Checkbox:
ContentControlCheckbox checkbox = contentControl as ContentControlCheckbox;
checkbox.CheckedSymbolStyle.Character = '*';
break;
}
}
#endregion #ChangeContentControlParameters
}
private static void RemoveContentControls(RichEditDocumentServer wordProcessor)
{
#region #RemoveContentControls
wordProcessor.LoadDocument("Documents\\Simple Form Filled.docx");
Document document = wordProcessor.Document;
var contentControls = document.ContentControls;
for (var i = 0; i < contentControls.Count; i++) {
if (contentControls[i].ControlType == ContentControlType.Date) {
contentControls.Remove(contentControls[i], true);
}
}
#endregion #RemoveContentControls
}
}
}