forked from EvotecIT/OfficeIMO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWordStructuredDocumentTag.cs
58 lines (52 loc) · 1.71 KB
/
WordStructuredDocumentTag.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
using DocumentFormat.OpenXml.Wordprocessing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OfficeIMO.Word {
public class WordStructuredDocumentTag {
private WordDocument _document;
private Paragraph _paragraph;
private SdtRun _stdRun;
public string Alias {
get {
var sdtAlias = _stdRun.SdtProperties.OfType<SdtAlias>().FirstOrDefault();
if (sdtAlias != null) {
return sdtAlias.Val;
}
return null;
}
}
public string Text {
get {
var run = _stdRun.SdtContentRun.ChildElements.OfType<Run>().FirstOrDefault();
if (run != null) {
var text = run.OfType<Text>().FirstOrDefault();
if (text != null) {
return text.Text;
}
}
return null;
}
set {
var run = _stdRun.SdtContentRun.ChildElements.OfType<Run>().FirstOrDefault();
if (run != null) {
var text = run.OfType<Text>().FirstOrDefault();
if (text != null) {
text.Text = value;
}
}
}
}
public WordStructuredDocumentTag(WordDocument document, Paragraph paragraph, SdtRun stdRun) {
this._document = document;
this._paragraph = paragraph;
this._stdRun = stdRun;
}
public void Remove() {
if (this._stdRun != null) {
this._stdRun.Remove();
}
}
}
}