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 2009-10-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 OfficeOpenXml.Style;
|
---|
37 | namespace OfficeOpenXml.Style.XmlAccess
|
---|
38 | {
|
---|
39 | /// <summary>
|
---|
40 | /// Xml access class for border items
|
---|
41 | /// </summary>
|
---|
42 | public sealed class ExcelBorderItemXml : StyleXmlHelper
|
---|
43 | {
|
---|
44 | internal ExcelBorderItemXml(XmlNamespaceManager nameSpaceManager) : base(nameSpaceManager)
|
---|
45 | {
|
---|
46 | _borderStyle=ExcelBorderStyle.None;
|
---|
47 | _color = new ExcelColorXml(NameSpaceManager);
|
---|
48 | }
|
---|
49 | internal ExcelBorderItemXml(XmlNamespaceManager nsm, XmlNode topNode) :
|
---|
50 | base(nsm, topNode)
|
---|
51 | {
|
---|
52 | if (topNode != null)
|
---|
53 | {
|
---|
54 | _borderStyle = GetBorderStyle(GetXmlNodeString("@style"));
|
---|
55 | _color = new ExcelColorXml(nsm, topNode.SelectSingleNode(_colorPath, nsm));
|
---|
56 | Exists = true;
|
---|
57 | }
|
---|
58 | else
|
---|
59 | {
|
---|
60 | Exists = false;
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | private ExcelBorderStyle GetBorderStyle(string style)
|
---|
65 | {
|
---|
66 | if(style=="") return ExcelBorderStyle.None;
|
---|
67 | string sInStyle = style.Substring(0, 1).ToUpper() + style.Substring(1, style.Length - 1);
|
---|
68 | try
|
---|
69 | {
|
---|
70 | return (ExcelBorderStyle)Enum.Parse(typeof(ExcelBorderStyle), sInStyle);
|
---|
71 | }
|
---|
72 | catch
|
---|
73 | {
|
---|
74 | return ExcelBorderStyle.None;
|
---|
75 | }
|
---|
76 |
|
---|
77 | }
|
---|
78 | ExcelBorderStyle _borderStyle = ExcelBorderStyle.None;
|
---|
79 | /// <summary>
|
---|
80 | /// Cell Border style
|
---|
81 | /// </summary>
|
---|
82 | public ExcelBorderStyle Style
|
---|
83 | {
|
---|
84 | get
|
---|
85 | {
|
---|
86 | return _borderStyle;
|
---|
87 | }
|
---|
88 | set
|
---|
89 | {
|
---|
90 | _borderStyle = value;
|
---|
91 | Exists = true;
|
---|
92 | }
|
---|
93 | }
|
---|
94 | ExcelColorXml _color = null;
|
---|
95 | const string _colorPath = "d:color";
|
---|
96 | /// <summary>
|
---|
97 | /// Border style
|
---|
98 | /// </summary>
|
---|
99 | public ExcelColorXml Color
|
---|
100 | {
|
---|
101 | get
|
---|
102 | {
|
---|
103 | return _color;
|
---|
104 | }
|
---|
105 | internal set
|
---|
106 | {
|
---|
107 | _color = value;
|
---|
108 | }
|
---|
109 | }
|
---|
110 | internal override string Id
|
---|
111 | {
|
---|
112 | get
|
---|
113 | {
|
---|
114 | if (Exists)
|
---|
115 | {
|
---|
116 | return Style + Color.Id;
|
---|
117 | }
|
---|
118 | else
|
---|
119 | {
|
---|
120 | return "None";
|
---|
121 | }
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | internal ExcelBorderItemXml Copy()
|
---|
126 | {
|
---|
127 | ExcelBorderItemXml borderItem = new ExcelBorderItemXml(NameSpaceManager);
|
---|
128 | borderItem.Style = _borderStyle;
|
---|
129 | borderItem.Color = _color.Copy();
|
---|
130 | return borderItem;
|
---|
131 | }
|
---|
132 |
|
---|
133 | internal override XmlNode CreateXmlNode(XmlNode topNode)
|
---|
134 | {
|
---|
135 | TopNode = topNode;
|
---|
136 |
|
---|
137 | if (Style != ExcelBorderStyle.None)
|
---|
138 | {
|
---|
139 | SetXmlNodeString("@style", SetBorderString(Style));
|
---|
140 | if (Color.Exists)
|
---|
141 | {
|
---|
142 | CreateNode(_colorPath);
|
---|
143 | topNode.AppendChild(Color.CreateXmlNode(TopNode.SelectSingleNode(_colorPath,NameSpaceManager)));
|
---|
144 | }
|
---|
145 | }
|
---|
146 | return TopNode;
|
---|
147 | }
|
---|
148 |
|
---|
149 | private string SetBorderString(ExcelBorderStyle Style)
|
---|
150 | {
|
---|
151 | string newName=Enum.GetName(typeof(ExcelBorderStyle), Style);
|
---|
152 | return newName.Substring(0, 1).ToLower() + newName.Substring(1, newName.Length - 1);
|
---|
153 | }
|
---|
154 | public bool Exists { get; private set; }
|
---|
155 | }
|
---|
156 | }
|
---|