npoi
231 строка · 7.5 Кб
1using NPOI.OpenXml4Net.Util;
2using System;
3using System.ComponentModel;
4using System.IO;
5using System.Xml;
6using System.Xml.Serialization;
7
8namespace NPOI.OpenXmlFormats.Dml.Spreadsheet
9{
10
11[Serializable]
12[XmlType(Namespace = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing")]
13public class CT_Picture // empty interface: EG_ObjectChoices
14{
15private CT_PictureNonVisual nvPicPrField = new CT_PictureNonVisual(); // draw-ssdraw: 1..1
16private CT_BlipFillProperties blipFillField = new CT_BlipFillProperties(); // draw-ssdraw: 1..1
17private CT_ShapeProperties spPrField = new CT_ShapeProperties(); // draw-ssdraw: 1..1
18private CT_ShapeStyle styleField = null; // 0..1
19
20private string macroField = null;
21private bool fPublishedField = false;
22public static CT_Picture Parse(XmlNode node, XmlNamespaceManager namespaceManager)
23{
24if (node == null)
25return null;
26CT_Picture ctObj = new CT_Picture();
27ctObj.macro = XmlHelper.ReadString(node.Attributes["macro"]);
28ctObj.fPublished = XmlHelper.ReadBool(node.Attributes["fPublished"]);
29foreach (XmlNode childNode in node.ChildNodes)
30{
31if (childNode.LocalName == "nvPicPr")
32ctObj.nvPicPr = CT_PictureNonVisual.Parse(childNode, namespaceManager);
33else if (childNode.LocalName == "blipFill")
34ctObj.blipFill = CT_BlipFillProperties.Parse(childNode, namespaceManager);
35else if (childNode.LocalName == "spPr")
36ctObj.spPr = CT_ShapeProperties.Parse(childNode, namespaceManager);
37else if (childNode.LocalName == "style")
38ctObj.style = CT_ShapeStyle.Parse(childNode, namespaceManager);
39}
40return ctObj;
41}
42
43
44
45internal void Write(StreamWriter sw, string nodeName)
46{
47sw.Write(string.Format("<xdr:{0}", nodeName));
48XmlHelper.WriteAttribute(sw, "macro", this.macro);
49if (this.fPublished)
50XmlHelper.WriteAttribute(sw, "fPublished", this.fPublished);
51sw.Write(">");
52if (this.nvPicPr != null)
53this.nvPicPr.Write(sw, "nvPicPr");
54if (this.blipFill != null)
55this.blipFill.Write(sw, "blipFill");
56if (this.spPr != null)
57this.spPr.Write(sw, "spPr");
58if (this.style != null)
59this.style.Write(sw, "style");
60sw.Write(string.Format("</xdr:{0}>", nodeName));
61}
62
63[XmlElement]
64public CT_PictureNonVisual nvPicPr
65{
66get { return this.nvPicPrField; }
67set { this.nvPicPrField = value; }
68}
69
70[XmlElement]
71public CT_BlipFillProperties blipFill
72{
73get { return this.blipFillField; }
74set { this.blipFillField = value; }
75}
76
77[XmlElement]
78public CT_ShapeProperties spPr
79{
80get { return this.spPrField; }
81set { this.spPrField = value; }
82}
83
84[XmlElement]
85public CT_ShapeStyle style
86{
87get
88{
89return this.styleField;
90}
91set
92{
93this.styleField = value;
94}
95}
96private bool styleSpecifiedField = false;
97[XmlIgnore]
98public bool styleSpecified
99{
100get { return styleSpecifiedField; }
101set { styleSpecifiedField = value; }
102}
103
104[XmlAttribute]
105public string macro
106{
107get { return macroField; }
108set { macroField = value; }
109}
110private bool macroSpecifiedField = false;
111[XmlIgnore]
112public bool macroSpecified
113{
114get { return macroSpecifiedField; }
115set { macroSpecifiedField = value; }
116}
117
118[XmlAttribute]
119public bool fPublished
120{
121get { return fPublishedField; }
122set { fPublishedField = value; }
123}
124private bool fPublishedSpecifiedField = false;
125[XmlIgnore]
126public bool fPublishedSpecified
127{
128get { return fPublishedSpecifiedField; }
129set { fPublishedSpecifiedField = value; }
130}
131
132public CT_PictureNonVisual AddNewNvPicPr()
133{
134nvPicPrField = new CT_PictureNonVisual();
135return this.nvPicPrField;
136}
137
138public CT_BlipFillProperties AddNewBlipFill()
139{
140blipFillField = new CT_BlipFillProperties();
141return this.blipFillField;
142}
143
144public CT_ShapeProperties AddNewSpPr()
145{
146spPrField = new CT_ShapeProperties();
147return this.spPrField;
148}
149
150public void Set(CT_Picture pict)
151{
152this.nvPicPr = pict.nvPicPr;
153this.spPr = pict.spPr;
154this.macro = pict.macro;
155this.macroSpecified = this.macroSpecified;
156this.style = pict.style;
157this.styleSpecified = pict.styleSpecified;
158this.fPublished = pict.fPublished;
159this.fPublishedSpecified = pict.fPublishedSpecified;
160this.blipFill = pict.blipFill;
161
162
163}
164
165}
166
167// see same class in different name space in Picture.cs
168[Serializable]
169[XmlType(Namespace = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing")]
170public class CT_PictureNonVisual
171{
172
173private CT_NonVisualDrawingProps cNvPrField = new CT_NonVisualDrawingProps(); // 1..1
174private CT_NonVisualPictureProperties cNvPicPrField = new CT_NonVisualPictureProperties(); // 1..1
175
176public static CT_PictureNonVisual Parse(XmlNode node, XmlNamespaceManager namespaceManager)
177{
178if (node == null)
179return null;
180CT_PictureNonVisual ctObj = new CT_PictureNonVisual();
181foreach (XmlNode childNode in node.ChildNodes)
182{
183if (childNode.LocalName == "cNvPr")
184ctObj.cNvPr = CT_NonVisualDrawingProps.Parse(childNode, namespaceManager);
185else if (childNode.LocalName == "cNvPicPr")
186ctObj.cNvPicPr = CT_NonVisualPictureProperties.Parse(childNode, namespaceManager);
187}
188return ctObj;
189}
190
191
192
193internal void Write(StreamWriter sw, string nodeName)
194{
195sw.Write(string.Format("<xdr:{0}", nodeName));
196sw.Write(">");
197if (this.cNvPr != null)
198this.cNvPr.Write(sw, "cNvPr");
199if (this.cNvPicPr != null)
200this.cNvPicPr.Write(sw, "cNvPicPr");
201sw.Write(string.Format("</xdr:{0}>", nodeName));
202}
203public CT_NonVisualDrawingProps AddNewCNvPr()
204{
205this.cNvPrField = new CT_NonVisualDrawingProps();
206return this.cNvPrField;
207}
208public CT_NonVisualPictureProperties AddNewCNvPicPr()
209{
210this.cNvPicPrField = new CT_NonVisualPictureProperties();
211return this.cNvPicPrField;
212}
213
214[XmlElement]
215public CT_NonVisualDrawingProps cNvPr
216{
217get { return this.cNvPrField; }
218set { this.cNvPrField = value; }
219}
220
221
222[XmlElement]
223public CT_NonVisualPictureProperties cNvPicPr
224{
225get { return this.cNvPicPrField; }
226set { this.cNvPicPrField = value; }
227}
228
229}
230
231}
232