npoi
171 строка · 6.9 Кб
1using NPOI.OpenXmlFormats.Vml.Spreadsheet;
2using NPOI.OpenXmlFormats.Vml.Wordprocessing;
3using System;
4using System.Collections.Generic;
5using System.IO;
6using System.Text;
7using System.Xml;
8
9namespace NPOI.OpenXmlFormats.Util
10{
11public static class XmlHelper
12{
13public static ST_TrueFalseBlank ReadTrueFalseBlank(string attrValue)
14{
15if (string.IsNullOrEmpty(attrValue))
16return ST_TrueFalseBlank.NONE;
17if (string.IsNullOrEmpty(attrValue))
18return ST_TrueFalseBlank.NONE;
19string value = attrValue.ToLower();
20if (value == "t" || value == "true")
21{
22return ST_TrueFalseBlank.@true;
23}
24else
25{
26return ST_TrueFalseBlank.@false;
27}
28}
29public static ST_TrueFalseBlank ReadTrueFalseBlank(XmlAttribute attr)
30{
31if (attr == null)
32return ST_TrueFalseBlank.NONE;
33if(string.IsNullOrEmpty(attr.Value))
34return ST_TrueFalseBlank.NONE;
35string value = attr.Value.ToLower();
36if (value == "t" || value == "true")
37{
38return ST_TrueFalseBlank.@true;
39}
40else
41{
42return ST_TrueFalseBlank.@false;
43}
44
45}
46public static NPOI.OpenXmlFormats.Vml.Office.ST_TrueFalse ReadTrueFalse(XmlAttribute attr)
47{
48if (attr == null)
49return NPOI.OpenXmlFormats.Vml.Office.ST_TrueFalse.@false;
50if (string.IsNullOrEmpty(attr.Value))
51return NPOI.OpenXmlFormats.Vml.Office.ST_TrueFalse.@false;
52
53string value = attr.Value.ToLower();
54if (value == "t" || value == "true")
55{
56return NPOI.OpenXmlFormats.Vml.Office.ST_TrueFalse.@true;
57}
58else
59{
60return NPOI.OpenXmlFormats.Vml.Office.ST_TrueFalse.@false;
61}
62}
63public static ST_BorderShadow ReadBorderShadow(XmlAttribute attr)
64{
65if (attr == null)
66return ST_BorderShadow.@false;
67
68if (string.IsNullOrEmpty(attr.Value))
69return ST_BorderShadow.@false;
70
71string value = attr.Value.ToLower();
72if (value == "t" || value == "true")
73{
74return ST_BorderShadow.@true;
75}
76else
77{
78return ST_BorderShadow.@false;
79}
80
81}
82public static NPOI.OpenXmlFormats.Vml.ST_TrueFalse ReadTrueFalse2(XmlAttribute attr)
83{
84if (attr == null)
85return NPOI.OpenXmlFormats.Vml.ST_TrueFalse.@false;
86if (string.IsNullOrEmpty(attr.Value))
87return NPOI.OpenXmlFormats.Vml.ST_TrueFalse.@false;
88
89string value = attr.Value.ToLower();
90if (value == "t" || value == "true")
91{
92return NPOI.OpenXmlFormats.Vml.ST_TrueFalse.@true;
93}
94else
95{
96return NPOI.OpenXmlFormats.Vml.ST_TrueFalse.@false;
97}
98}
99public static void WriteAttribute(StreamWriter sw, string attributeName, NPOI.OpenXmlFormats.Vml.Office.ST_TrueFalse value)
100{
101WriteAttribute(sw, attributeName, value, false);
102}
103public static void WriteAttribute(StreamWriter sw, string attributeName, NPOI.OpenXmlFormats.Vml.Office.ST_TrueFalse value, bool defaultValue)
104{
105if (defaultValue == true && (value == OpenXmlFormats.Vml.Office.ST_TrueFalse.t || value == OpenXmlFormats.Vml.Office.ST_TrueFalse.@true))
106return;
107
108if (defaultValue == false && (value == OpenXmlFormats.Vml.Office.ST_TrueFalse.f || value == OpenXmlFormats.Vml.Office.ST_TrueFalse.@false))
109return;
110
111if (value == OpenXmlFormats.Vml.Office.ST_TrueFalse.t || value == OpenXmlFormats.Vml.Office.ST_TrueFalse.@true)
112NPOI.OpenXml4Net.Util.XmlHelper.WriteAttribute(sw, attributeName, "t");
113else
114NPOI.OpenXml4Net.Util.XmlHelper.WriteAttribute(sw, attributeName, "f");
115}
116public static void WriteAttribute(StreamWriter sw, string attributeName, ST_BorderShadow value)
117{
118WriteAttribute(sw, attributeName, value, false);
119}
120public static void WriteAttribute(StreamWriter sw, string attributeName, ST_BorderShadow value, bool defaultValue)
121{
122if (defaultValue == true && (value ==ST_BorderShadow.t || value ==ST_BorderShadow.@true))
123return;
124
125if (defaultValue == false && (value ==ST_BorderShadow.f || value ==ST_BorderShadow.@false))
126return;
127
128if (value ==ST_BorderShadow.t || value ==ST_BorderShadow.@true)
129NPOI.OpenXml4Net.Util.XmlHelper.WriteAttribute(sw, attributeName, "t");
130else
131NPOI.OpenXml4Net.Util.XmlHelper.WriteAttribute(sw, attributeName, "f");
132}
133public static void WriteAttribute(StreamWriter sw, string attributeName, NPOI.OpenXmlFormats.Vml.ST_TrueFalse value)
134{
135WriteAttribute(sw, attributeName, value, false);
136}
137public static void WriteAttribute(StreamWriter sw, string attributeName, NPOI.OpenXmlFormats.Vml.ST_TrueFalse value, bool defaultValue)
138{
139if (defaultValue == true && (value == OpenXmlFormats.Vml.ST_TrueFalse.t || value == OpenXmlFormats.Vml.ST_TrueFalse.@true))
140return;
141
142if (defaultValue == false && (value == OpenXmlFormats.Vml.ST_TrueFalse.f || value == OpenXmlFormats.Vml.ST_TrueFalse.@false))
143return;
144
145if (value == OpenXmlFormats.Vml.ST_TrueFalse.t || value == OpenXmlFormats.Vml.ST_TrueFalse.@true)
146NPOI.OpenXml4Net.Util.XmlHelper.WriteAttribute(sw, attributeName, "t");
147else
148NPOI.OpenXml4Net.Util.XmlHelper.WriteAttribute(sw, attributeName, "f");
149}
150public static void WriteAttribute(StreamWriter sw, string attributeName, ST_TrueFalseBlank value)
151{
152WriteAttribute(sw, attributeName, value, null);
153}
154public static void WriteAttribute(StreamWriter sw, string attributeName, ST_TrueFalseBlank value, bool? defaultValue)
155{
156if (defaultValue == null&& value == ST_TrueFalseBlank.NONE)
157return;
158
159if (defaultValue == true && (value == ST_TrueFalseBlank.t || value == ST_TrueFalseBlank.@true))
160return;
161
162if (defaultValue == false && (value == ST_TrueFalseBlank.f || value == ST_TrueFalseBlank.@false))
163return;
164
165if (value == ST_TrueFalseBlank.t || value == ST_TrueFalseBlank.@true)
166NPOI.OpenXml4Net.Util.XmlHelper.WriteAttribute(sw, attributeName, "t");
167else
168NPOI.OpenXml4Net.Util.XmlHelper.WriteAttribute(sw, attributeName, "f");
169}
170}
171}
172