1 | /*******************************************************************************
|
---|
2 | * You may amend and distribute as you like, but don't remove this header!
|
---|
3 | *
|
---|
4 | * EPPlus provides server-side generation of Excel 2007/2010 spreadsheets.
|
---|
5 | * See http://www.codeplex.com/EPPlus for details.
|
---|
6 | *
|
---|
7 | * Copyright (C) 2011 Jan Källman
|
---|
8 | *
|
---|
9 | * This library is free software; you can redistribute it and/or
|
---|
10 | * modify it under the terms of the GNU Lesser General Public
|
---|
11 | * License as published by the Free Software Foundation; either
|
---|
12 | * version 2.1 of the License, or (at your option) any later version.
|
---|
13 |
|
---|
14 | * This library is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
---|
17 | * See the GNU Lesser General Public License for more details.
|
---|
18 | *
|
---|
19 | * The GNU Lesser General Public License can be viewed at http://www.opensource.org/licenses/lgpl-license.php
|
---|
20 | * If you unfamiliar with this license or have questions about it, here is an http://www.gnu.org/licenses/gpl-faq.html
|
---|
21 | *
|
---|
22 | * All code and executables are provided "as is" with no warranty either express or implied.
|
---|
23 | * The author accepts no liability for any damage or loss of business that this product may cause.
|
---|
24 | *
|
---|
25 | * Code change notes:
|
---|
26 | *
|
---|
27 | * Author Change Date
|
---|
28 | * ******************************************************************************
|
---|
29 | * Jan Källman Initial Release 2010-06-01
|
---|
30 | * Jan Källman License changed GPL-->LGPL 2011-12-16
|
---|
31 | *******************************************************************************/
|
---|
32 | using System;
|
---|
33 | using System.Collections.Generic;
|
---|
34 | using System.Text;
|
---|
35 | using System.Xml;
|
---|
36 | using System.Globalization;
|
---|
37 | using System.Drawing;
|
---|
38 |
|
---|
39 | namespace OfficeOpenXml.Drawing.Vml
|
---|
40 | {
|
---|
41 | /// <summary>
|
---|
42 | /// Drawing object used for comments
|
---|
43 | /// </summary>
|
---|
44 | public class ExcelVmlDrawingComment : ExcelVmlDrawingBase, IRangeID
|
---|
45 | {
|
---|
46 | internal ExcelVmlDrawingComment(XmlNode topNode, ExcelRangeBase range, XmlNamespaceManager ns) :
|
---|
47 | base(topNode, ns)
|
---|
48 | {
|
---|
49 | Range = range;
|
---|
50 | SchemaNodeOrder = new string[] { "fill", "stroke", "shadow", "path", "textbox", "ClientData", "MoveWithCells", "SizeWithCells", "Anchor", "Locked", "AutoFill", "LockText", "TextHAlign", "TextVAlign", "Row", "Column", "Visible" };
|
---|
51 | }
|
---|
52 | internal ExcelRangeBase Range { get; set; }
|
---|
53 | //public string Id
|
---|
54 | //{
|
---|
55 | // get
|
---|
56 | // {
|
---|
57 | // return GetXmlNodeString("@id");
|
---|
58 | // }
|
---|
59 | // set
|
---|
60 | // {
|
---|
61 | // SetXmlNodeString("@id",value);
|
---|
62 | // }
|
---|
63 | //}
|
---|
64 | const string VERTICAL_ALIGNMENT_PATH="x:ClientData/x:TextVAlign";
|
---|
65 | /// <summary>
|
---|
66 | /// Vertical alignment for text
|
---|
67 | /// </summary>
|
---|
68 | public eTextAlignVerticalVml VerticalAlignment
|
---|
69 | {
|
---|
70 | get
|
---|
71 | {
|
---|
72 | switch (GetXmlNodeString(VERTICAL_ALIGNMENT_PATH))
|
---|
73 | {
|
---|
74 | case "Center":
|
---|
75 | return eTextAlignVerticalVml.Center;
|
---|
76 | case "Bottom":
|
---|
77 | return eTextAlignVerticalVml.Bottom;
|
---|
78 | default:
|
---|
79 | return eTextAlignVerticalVml.Top;
|
---|
80 | }
|
---|
81 | }
|
---|
82 | set
|
---|
83 | {
|
---|
84 | switch (value)
|
---|
85 | {
|
---|
86 | case eTextAlignVerticalVml.Center:
|
---|
87 | SetXmlNodeString(VERTICAL_ALIGNMENT_PATH, "Center");
|
---|
88 | break;
|
---|
89 | case eTextAlignVerticalVml.Bottom:
|
---|
90 | SetXmlNodeString(VERTICAL_ALIGNMENT_PATH, "Bottom");
|
---|
91 | break;
|
---|
92 | default:
|
---|
93 | DeleteNode(VERTICAL_ALIGNMENT_PATH);
|
---|
94 | break;
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|
98 | const string HORIZONTAL_ALIGNMENT_PATH="x:ClientData/x:TextHAlign";
|
---|
99 | /// <summary>
|
---|
100 | /// Horizontal alignment for text
|
---|
101 | /// </summary>
|
---|
102 | public eTextAlignHorizontalVml HorizontalAlignment
|
---|
103 | {
|
---|
104 | get
|
---|
105 | {
|
---|
106 | switch (GetXmlNodeString(HORIZONTAL_ALIGNMENT_PATH))
|
---|
107 | {
|
---|
108 | case "Center":
|
---|
109 | return eTextAlignHorizontalVml.Center;
|
---|
110 | case "Right":
|
---|
111 | return eTextAlignHorizontalVml.Right;
|
---|
112 | default:
|
---|
113 | return eTextAlignHorizontalVml.Left;
|
---|
114 | }
|
---|
115 | }
|
---|
116 | set
|
---|
117 | {
|
---|
118 | switch (value)
|
---|
119 | {
|
---|
120 | case eTextAlignHorizontalVml.Center:
|
---|
121 | SetXmlNodeString(HORIZONTAL_ALIGNMENT_PATH, "Center");
|
---|
122 | break;
|
---|
123 | case eTextAlignHorizontalVml.Right:
|
---|
124 | SetXmlNodeString(HORIZONTAL_ALIGNMENT_PATH, "Right");
|
---|
125 | break;
|
---|
126 | default:
|
---|
127 | DeleteNode(HORIZONTAL_ALIGNMENT_PATH);
|
---|
128 | break;
|
---|
129 | }
|
---|
130 | }
|
---|
131 | }
|
---|
132 | const string VISIBLE_PATH = "x:ClientData/x:Visible";
|
---|
133 | /// <summary>
|
---|
134 | /// If the drawing object is visible.
|
---|
135 | /// </summary>
|
---|
136 | public bool Visible
|
---|
137 | {
|
---|
138 | get
|
---|
139 | {
|
---|
140 | return (TopNode.SelectSingleNode(VISIBLE_PATH, NameSpaceManager)!=null);
|
---|
141 | }
|
---|
142 | set
|
---|
143 | {
|
---|
144 | if (value)
|
---|
145 | {
|
---|
146 | CreateNode(VISIBLE_PATH);
|
---|
147 | Style = SetStyle(Style,"visibility", "visible");
|
---|
148 | }
|
---|
149 | else
|
---|
150 | {
|
---|
151 | DeleteNode(VISIBLE_PATH);
|
---|
152 | Style = SetStyle(Style,"visibility", "hidden");
|
---|
153 | }
|
---|
154 | }
|
---|
155 | }
|
---|
156 | const string BACKGROUNDCOLOR_PATH = "@fillcolor";
|
---|
157 | const string BACKGROUNDCOLOR2_PATH = "v:fill/@color2";
|
---|
158 | /// <summary>
|
---|
159 | /// Background color
|
---|
160 | /// </summary>
|
---|
161 | public Color BackgroundColor
|
---|
162 | {
|
---|
163 | get
|
---|
164 | {
|
---|
165 | string col = GetXmlNodeString(BACKGROUNDCOLOR_PATH);
|
---|
166 | if (col == "")
|
---|
167 | {
|
---|
168 | return Color.FromArgb(0xff, 0xff, 0xe1);
|
---|
169 | }
|
---|
170 | else
|
---|
171 | {
|
---|
172 | if(col.StartsWith("#")) col=col.Substring(1,col.Length-1);
|
---|
173 | int res;
|
---|
174 | if (int.TryParse(col,System.Globalization.NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out res))
|
---|
175 | {
|
---|
176 | return Color.FromArgb(res);
|
---|
177 | }
|
---|
178 | else
|
---|
179 | {
|
---|
180 | return Color.Empty;
|
---|
181 | }
|
---|
182 | }
|
---|
183 | }
|
---|
184 | set
|
---|
185 | {
|
---|
186 | string color = "#" + value.ToArgb().ToString("X").Substring(2, 6);
|
---|
187 | SetXmlNodeString(BACKGROUNDCOLOR_PATH, color);
|
---|
188 | //SetXmlNode(BACKGROUNDCOLOR2_PATH, color);
|
---|
189 | }
|
---|
190 | }
|
---|
191 | const string LINESTYLE_PATH="v:stroke/@dashstyle";
|
---|
192 | const string ENDCAP_PATH = "v:stroke/@endcap";
|
---|
193 | /// <summary>
|
---|
194 | /// Linestyle for border
|
---|
195 | /// </summary>
|
---|
196 | public eLineStyleVml LineStyle
|
---|
197 | {
|
---|
198 | get
|
---|
199 | {
|
---|
200 | string v=GetXmlNodeString(LINESTYLE_PATH);
|
---|
201 | if (v == "")
|
---|
202 | {
|
---|
203 | return eLineStyleVml.Solid;
|
---|
204 | }
|
---|
205 | else if (v == "1 1")
|
---|
206 | {
|
---|
207 | v = GetXmlNodeString(ENDCAP_PATH);
|
---|
208 | return (eLineStyleVml)Enum.Parse(typeof(eLineStyleVml), v, true);
|
---|
209 | }
|
---|
210 | else
|
---|
211 | {
|
---|
212 | return (eLineStyleVml)Enum.Parse(typeof(eLineStyleVml), v, true);
|
---|
213 | }
|
---|
214 | }
|
---|
215 | set
|
---|
216 | {
|
---|
217 | if (value == eLineStyleVml.Round || value == eLineStyleVml.Square)
|
---|
218 | {
|
---|
219 | SetXmlNodeString(LINESTYLE_PATH, "1 1");
|
---|
220 | if (value == eLineStyleVml.Round)
|
---|
221 | {
|
---|
222 | SetXmlNodeString(ENDCAP_PATH, "round");
|
---|
223 | }
|
---|
224 | else
|
---|
225 | {
|
---|
226 | DeleteNode(ENDCAP_PATH);
|
---|
227 | }
|
---|
228 | }
|
---|
229 | else
|
---|
230 | {
|
---|
231 | string v = value.ToString();
|
---|
232 | v = v.Substring(0, 1).ToLower(CultureInfo.InvariantCulture) + v.Substring(1, v.Length - 1);
|
---|
233 | SetXmlNodeString(LINESTYLE_PATH, v);
|
---|
234 | DeleteNode(ENDCAP_PATH);
|
---|
235 | }
|
---|
236 | }
|
---|
237 | }
|
---|
238 | const string LINECOLOR_PATH="@strokecolor";
|
---|
239 | /// <summary>
|
---|
240 | /// Line color
|
---|
241 | /// </summary>
|
---|
242 | public Color LineColor
|
---|
243 | {
|
---|
244 | get
|
---|
245 | {
|
---|
246 | string col = GetXmlNodeString(LINECOLOR_PATH);
|
---|
247 | if (col == "")
|
---|
248 | {
|
---|
249 | return Color.Black;
|
---|
250 | }
|
---|
251 | else
|
---|
252 | {
|
---|
253 | if (col.StartsWith("#")) col = col.Substring(1, col.Length - 1);
|
---|
254 | int res;
|
---|
255 | if (int.TryParse(col, System.Globalization.NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out res))
|
---|
256 | {
|
---|
257 | return Color.FromArgb(res);
|
---|
258 | }
|
---|
259 | else
|
---|
260 | {
|
---|
261 | return Color.Empty;
|
---|
262 | }
|
---|
263 | }
|
---|
264 | }
|
---|
265 | set
|
---|
266 | {
|
---|
267 | string color = "#" + value.ToArgb().ToString("X").Substring(2, 6);
|
---|
268 | SetXmlNodeString(LINECOLOR_PATH, color);
|
---|
269 | }
|
---|
270 | }
|
---|
271 | const string LINEWIDTH_PATH="@strokeweight";
|
---|
272 | /// <summary>
|
---|
273 | /// Width of the border
|
---|
274 | /// </summary>
|
---|
275 | public Single LineWidth
|
---|
276 | {
|
---|
277 | get
|
---|
278 | {
|
---|
279 | string wt=GetXmlNodeString(LINEWIDTH_PATH);
|
---|
280 | if (wt == "") return (Single).75;
|
---|
281 | if(wt.EndsWith("pt")) wt=wt.Substring(0,wt.Length-2);
|
---|
282 |
|
---|
283 | Single ret;
|
---|
284 | if(Single.TryParse(wt,System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out ret))
|
---|
285 | {
|
---|
286 | return ret;
|
---|
287 | }
|
---|
288 | else
|
---|
289 | {
|
---|
290 | return 0;
|
---|
291 | }
|
---|
292 | }
|
---|
293 | set
|
---|
294 | {
|
---|
295 | SetXmlNodeString(LINEWIDTH_PATH, value.ToString(CultureInfo.InvariantCulture) + "pt");
|
---|
296 | }
|
---|
297 | }
|
---|
298 | ///// <summary>
|
---|
299 | ///// Width of the Comment
|
---|
300 | ///// </summary>
|
---|
301 | //public Single Width
|
---|
302 | //{
|
---|
303 | // get
|
---|
304 | // {
|
---|
305 | // string v;
|
---|
306 | // GetStyle("width", out v);
|
---|
307 | // if(v.EndsWith("pt"))
|
---|
308 | // {
|
---|
309 | // v = v.Substring(0, v.Length - 2);
|
---|
310 | // }
|
---|
311 | // short ret;
|
---|
312 | // if (short.TryParse(v,System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out ret))
|
---|
313 | // {
|
---|
314 | // return ret;
|
---|
315 | // }
|
---|
316 | // else
|
---|
317 | // {
|
---|
318 | // return 0;
|
---|
319 | // }
|
---|
320 | // }
|
---|
321 | // set
|
---|
322 | // {
|
---|
323 | // SetStyle("width", value.ToString("N2",CultureInfo.InvariantCulture) + "pt");
|
---|
324 | // }
|
---|
325 | //}
|
---|
326 | ///// <summary>
|
---|
327 | ///// Height of the Comment
|
---|
328 | ///// </summary>
|
---|
329 | //public Single Height
|
---|
330 | //{
|
---|
331 | // get
|
---|
332 | // {
|
---|
333 | // string v;
|
---|
334 | // GetStyle("height", out v);
|
---|
335 | // if (v.EndsWith("pt"))
|
---|
336 | // {
|
---|
337 | // v = v.Substring(0, v.Length - 2);
|
---|
338 | // }
|
---|
339 | // short ret;
|
---|
340 | // if (short.TryParse(v, System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out ret))
|
---|
341 | // {
|
---|
342 | // return ret;
|
---|
343 | // }
|
---|
344 | // else
|
---|
345 | // {
|
---|
346 | // return 0;
|
---|
347 | // }
|
---|
348 | // }
|
---|
349 | // set
|
---|
350 | // {
|
---|
351 | // SetStyle("height", value.ToString("N2", CultureInfo.InvariantCulture) + "pt");
|
---|
352 | // }
|
---|
353 | //}
|
---|
354 | const string TEXTBOX_STYLE_PATH = "v:textbox/@style";
|
---|
355 | /// <summary>
|
---|
356 | /// Autofits the drawingobject
|
---|
357 | /// </summary>
|
---|
358 | public bool AutoFit
|
---|
359 | {
|
---|
360 | get
|
---|
361 | {
|
---|
362 | string value;
|
---|
363 | GetStyle(GetXmlNodeString(TEXTBOX_STYLE_PATH), "mso-fit-shape-to-text", out value);
|
---|
364 | return value=="t";
|
---|
365 | }
|
---|
366 | set
|
---|
367 | {
|
---|
368 | SetXmlNodeString(TEXTBOX_STYLE_PATH, SetStyle(GetXmlNodeString(TEXTBOX_STYLE_PATH),"mso-fit-shape-to-text", value?"t":""));
|
---|
369 | }
|
---|
370 | }
|
---|
371 | const string LOCKED_PATH = "x:ClientData/x:Locked";
|
---|
372 | /// <summary>
|
---|
373 | /// If the object is locked when the sheet is protected
|
---|
374 | /// </summary>
|
---|
375 | public bool Locked
|
---|
376 | {
|
---|
377 | get
|
---|
378 | {
|
---|
379 | return GetXmlNodeBool(LOCKED_PATH, false);
|
---|
380 | }
|
---|
381 | set
|
---|
382 | {
|
---|
383 | SetXmlNodeBool(LOCKED_PATH, value, false);
|
---|
384 | }
|
---|
385 | }
|
---|
386 | const string LOCK_TEXT_PATH = "x:ClientData/x:LockText";
|
---|
387 | /// <summary>
|
---|
388 | /// Specifies that the object's text is locked
|
---|
389 | /// </summary>
|
---|
390 | public bool LockText
|
---|
391 | {
|
---|
392 | get
|
---|
393 | {
|
---|
394 | return GetXmlNodeBool(LOCK_TEXT_PATH, false);
|
---|
395 | }
|
---|
396 | set
|
---|
397 | {
|
---|
398 | SetXmlNodeBool(LOCK_TEXT_PATH, value, false);
|
---|
399 | }
|
---|
400 | }
|
---|
401 | ExcelVmlDrawingPosition _from = null;
|
---|
402 | /// <summary>
|
---|
403 | /// From position. For comments only when Visible=true.
|
---|
404 | /// </summary>
|
---|
405 | public ExcelVmlDrawingPosition From
|
---|
406 | {
|
---|
407 | get
|
---|
408 | {
|
---|
409 | if (_from == null)
|
---|
410 | {
|
---|
411 | _from = new ExcelVmlDrawingPosition(NameSpaceManager, TopNode.SelectSingleNode("x:ClientData", NameSpaceManager), 0);
|
---|
412 | }
|
---|
413 | return _from;
|
---|
414 | }
|
---|
415 | }
|
---|
416 | ExcelVmlDrawingPosition _to = null;
|
---|
417 | /// <summary>
|
---|
418 | /// To position. For comments only when Visible=true.
|
---|
419 | /// </summary>
|
---|
420 | public ExcelVmlDrawingPosition To
|
---|
421 | {
|
---|
422 | get
|
---|
423 | {
|
---|
424 | if (_to == null)
|
---|
425 | {
|
---|
426 | _to = new ExcelVmlDrawingPosition(NameSpaceManager, TopNode.SelectSingleNode("x:ClientData", NameSpaceManager), 4);
|
---|
427 | }
|
---|
428 | return _to;
|
---|
429 | }
|
---|
430 | }
|
---|
431 | const string STYLE_PATH = "@style";
|
---|
432 | internal string Style
|
---|
433 | {
|
---|
434 | get
|
---|
435 | {
|
---|
436 | return GetXmlNodeString(STYLE_PATH);
|
---|
437 | }
|
---|
438 | set
|
---|
439 | {
|
---|
440 | SetXmlNodeString(STYLE_PATH, value);
|
---|
441 | }
|
---|
442 | }
|
---|
443 | #region IRangeID Members
|
---|
444 |
|
---|
445 | ulong IRangeID.RangeID
|
---|
446 | {
|
---|
447 | get
|
---|
448 | {
|
---|
449 | return ExcelCellBase.GetCellID(Range.Worksheet.SheetID, Range.Start.Row, Range.Start.Column);
|
---|
450 | }
|
---|
451 | set
|
---|
452 | {
|
---|
453 |
|
---|
454 | }
|
---|
455 | }
|
---|
456 |
|
---|
457 | #endregion
|
---|
458 | }
|
---|
459 | }
|
---|