npoi

Форк
0
/
XmlHelper.cs 
171 строка · 6.9 Кб
1
using NPOI.OpenXmlFormats.Vml.Spreadsheet;
2
using NPOI.OpenXmlFormats.Vml.Wordprocessing;
3
using System;
4
using System.Collections.Generic;
5
using System.IO;
6
using System.Text;
7
using System.Xml;
8

9
namespace NPOI.OpenXmlFormats.Util
10
{
11
    public static class XmlHelper
12
    {
13
        public static ST_TrueFalseBlank ReadTrueFalseBlank(string attrValue)
14
        {
15
            if (string.IsNullOrEmpty(attrValue))
16
                return ST_TrueFalseBlank.NONE;
17
            if (string.IsNullOrEmpty(attrValue))
18
                return ST_TrueFalseBlank.NONE;
19
            string value = attrValue.ToLower();
20
            if (value == "t" || value == "true")
21
            {
22
                return ST_TrueFalseBlank.@true;
23
            }
24
            else
25
            {
26
                return ST_TrueFalseBlank.@false;
27
            }
28
        }
29
        public static ST_TrueFalseBlank ReadTrueFalseBlank(XmlAttribute attr)
30
        {
31
            if (attr == null)
32
                return ST_TrueFalseBlank.NONE;
33
            if(string.IsNullOrEmpty(attr.Value))
34
                return ST_TrueFalseBlank.NONE;
35
            string value = attr.Value.ToLower();
36
            if (value == "t" || value == "true")
37
            {
38
                return ST_TrueFalseBlank.@true;
39
            }
40
            else
41
            {
42
                return ST_TrueFalseBlank.@false;
43
            }
44

45
        }
46
        public static NPOI.OpenXmlFormats.Vml.Office.ST_TrueFalse ReadTrueFalse(XmlAttribute attr)
47
        {
48
            if (attr == null)
49
                return NPOI.OpenXmlFormats.Vml.Office.ST_TrueFalse.@false;
50
            if (string.IsNullOrEmpty(attr.Value))
51
                return NPOI.OpenXmlFormats.Vml.Office.ST_TrueFalse.@false;
52

53
            string value = attr.Value.ToLower();
54
            if (value == "t" || value == "true")
55
            {
56
                return NPOI.OpenXmlFormats.Vml.Office.ST_TrueFalse.@true;
57
            }
58
            else
59
            {
60
                return NPOI.OpenXmlFormats.Vml.Office.ST_TrueFalse.@false;
61
            }
62
        }
63
        public static ST_BorderShadow ReadBorderShadow(XmlAttribute attr)
64
        {
65
            if (attr == null)
66
                return ST_BorderShadow.@false;
67

68
            if (string.IsNullOrEmpty(attr.Value))
69
                return ST_BorderShadow.@false;
70

71
            string value = attr.Value.ToLower();
72
            if (value == "t" || value == "true")
73
            {
74
                return ST_BorderShadow.@true;
75
            }
76
            else
77
            {
78
                return ST_BorderShadow.@false;
79
            }
80

81
        }
82
        public static NPOI.OpenXmlFormats.Vml.ST_TrueFalse ReadTrueFalse2(XmlAttribute attr)
83
        {
84
            if (attr == null)
85
                return NPOI.OpenXmlFormats.Vml.ST_TrueFalse.@false;
86
            if (string.IsNullOrEmpty(attr.Value))
87
                return NPOI.OpenXmlFormats.Vml.ST_TrueFalse.@false;
88

89
            string value = attr.Value.ToLower();
90
            if (value == "t" || value == "true")
91
            {
92
                return NPOI.OpenXmlFormats.Vml.ST_TrueFalse.@true;
93
            }
94
            else
95
            {
96
                return NPOI.OpenXmlFormats.Vml.ST_TrueFalse.@false;
97
            }
98
        }
99
        public static void WriteAttribute(StreamWriter sw, string attributeName, NPOI.OpenXmlFormats.Vml.Office.ST_TrueFalse value)
100
        {
101
            WriteAttribute(sw, attributeName, value, false);
102
        }
103
        public static void WriteAttribute(StreamWriter sw, string attributeName, NPOI.OpenXmlFormats.Vml.Office.ST_TrueFalse value, bool defaultValue)
104
        {
105
            if (defaultValue == true && (value == OpenXmlFormats.Vml.Office.ST_TrueFalse.t || value == OpenXmlFormats.Vml.Office.ST_TrueFalse.@true))
106
                return;
107

108
            if (defaultValue == false && (value == OpenXmlFormats.Vml.Office.ST_TrueFalse.f || value == OpenXmlFormats.Vml.Office.ST_TrueFalse.@false))
109
                return;
110

111
            if (value == OpenXmlFormats.Vml.Office.ST_TrueFalse.t || value == OpenXmlFormats.Vml.Office.ST_TrueFalse.@true)
112
                NPOI.OpenXml4Net.Util.XmlHelper.WriteAttribute(sw, attributeName, "t");
113
            else
114
                NPOI.OpenXml4Net.Util.XmlHelper.WriteAttribute(sw, attributeName, "f");
115
        }
116
        public static void WriteAttribute(StreamWriter sw, string attributeName, ST_BorderShadow value)
117
        {
118
            WriteAttribute(sw, attributeName, value, false);
119
        }
120
        public static void WriteAttribute(StreamWriter sw, string attributeName, ST_BorderShadow value, bool defaultValue)
121
        {
122
            if (defaultValue == true && (value ==ST_BorderShadow.t || value ==ST_BorderShadow.@true))
123
                return;
124

125
            if (defaultValue == false && (value ==ST_BorderShadow.f || value ==ST_BorderShadow.@false))
126
                return;
127

128
            if (value ==ST_BorderShadow.t || value ==ST_BorderShadow.@true)
129
                NPOI.OpenXml4Net.Util.XmlHelper.WriteAttribute(sw, attributeName, "t");
130
            else
131
                NPOI.OpenXml4Net.Util.XmlHelper.WriteAttribute(sw, attributeName, "f");
132
        }
133
        public static void WriteAttribute(StreamWriter sw, string attributeName, NPOI.OpenXmlFormats.Vml.ST_TrueFalse value)
134
        {
135
            WriteAttribute(sw, attributeName, value, false);
136
        }
137
        public static void WriteAttribute(StreamWriter sw, string attributeName, NPOI.OpenXmlFormats.Vml.ST_TrueFalse value, bool defaultValue)
138
        {
139
            if (defaultValue == true && (value == OpenXmlFormats.Vml.ST_TrueFalse.t || value == OpenXmlFormats.Vml.ST_TrueFalse.@true))
140
                return;
141

142
            if (defaultValue == false && (value == OpenXmlFormats.Vml.ST_TrueFalse.f || value == OpenXmlFormats.Vml.ST_TrueFalse.@false))
143
                return;
144

145
            if (value == OpenXmlFormats.Vml.ST_TrueFalse.t || value == OpenXmlFormats.Vml.ST_TrueFalse.@true)
146
                NPOI.OpenXml4Net.Util.XmlHelper.WriteAttribute(sw, attributeName, "t");
147
            else
148
                NPOI.OpenXml4Net.Util.XmlHelper.WriteAttribute(sw, attributeName, "f");
149
        }
150
        public static void WriteAttribute(StreamWriter sw, string attributeName, ST_TrueFalseBlank value)
151
        {
152
            WriteAttribute(sw, attributeName, value, null);
153
        }
154
        public static void WriteAttribute(StreamWriter sw, string attributeName, ST_TrueFalseBlank value, bool? defaultValue)
155
        {
156
            if (defaultValue == null&& value == ST_TrueFalseBlank.NONE)
157
                return;
158

159
            if (defaultValue == true && (value == ST_TrueFalseBlank.t || value == ST_TrueFalseBlank.@true))
160
                return;
161

162
            if (defaultValue == false && (value == ST_TrueFalseBlank.f || value == ST_TrueFalseBlank.@false))
163
                return;
164

165
            if (value == ST_TrueFalseBlank.t || value == ST_TrueFalseBlank.@true)
166
                NPOI.OpenXml4Net.Util.XmlHelper.WriteAttribute(sw, attributeName, "t");
167
            else
168
                NPOI.OpenXml4Net.Util.XmlHelper.WriteAttribute(sw, attributeName, "f");
169
        }
170
    }
171
}
172

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.