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 | namespace OfficeOpenXml.Style.XmlAccess
|
---|
37 | {
|
---|
38 | /// <summary>
|
---|
39 | /// Xml access class for named styles
|
---|
40 | /// </summary>
|
---|
41 | public sealed class ExcelNamedStyleXml : StyleXmlHelper
|
---|
42 | {
|
---|
43 | ExcelStyles _styles;
|
---|
44 | internal ExcelNamedStyleXml(XmlNamespaceManager nameSpaceManager, ExcelStyles styles)
|
---|
45 | : base(nameSpaceManager)
|
---|
46 | {
|
---|
47 | _styles = styles;
|
---|
48 | BuildInId = int.MinValue;
|
---|
49 | }
|
---|
50 | internal ExcelNamedStyleXml(XmlNamespaceManager NameSpaceManager, XmlNode topNode, ExcelStyles styles) :
|
---|
51 | base(NameSpaceManager, topNode)
|
---|
52 | {
|
---|
53 | StyleXfId = GetXmlNodeInt(idPath);
|
---|
54 | Name = GetXmlNodeString(namePath);
|
---|
55 | BuildInId = GetXmlNodeInt(buildInIdPath);
|
---|
56 | CustomBuildin = GetXmlNodeBool(customBuiltinPath);
|
---|
57 |
|
---|
58 | _styles = styles;
|
---|
59 | _style = new ExcelStyle(styles, styles.NamedStylePropertyChange, -1, Name, _styleXfId);
|
---|
60 | }
|
---|
61 | internal override string Id
|
---|
62 | {
|
---|
63 | get
|
---|
64 | {
|
---|
65 | return Name;
|
---|
66 | }
|
---|
67 | }
|
---|
68 | int _styleXfId=0;
|
---|
69 | const string idPath = "@xfId";
|
---|
70 | /// <summary>
|
---|
71 | /// Named style index
|
---|
72 | /// </summary>
|
---|
73 | public int StyleXfId
|
---|
74 | {
|
---|
75 | get
|
---|
76 | {
|
---|
77 | return _styleXfId;
|
---|
78 | }
|
---|
79 | set
|
---|
80 | {
|
---|
81 | _styleXfId = value;
|
---|
82 | }
|
---|
83 | }
|
---|
84 | int _xfId = int.MinValue;
|
---|
85 | /// <summary>
|
---|
86 | /// Style index
|
---|
87 | /// </summary>
|
---|
88 | internal int XfId
|
---|
89 | {
|
---|
90 | get
|
---|
91 | {
|
---|
92 | return _xfId;
|
---|
93 | }
|
---|
94 | set
|
---|
95 | {
|
---|
96 | _xfId = value;
|
---|
97 | }
|
---|
98 | }
|
---|
99 | const string buildInIdPath = "@builtinId";
|
---|
100 | public int BuildInId { get; set; }
|
---|
101 | const string customBuiltinPath = "@customBuiltin";
|
---|
102 | public bool CustomBuildin { get; set; }
|
---|
103 | const string namePath = "@name";
|
---|
104 | string _name;
|
---|
105 | /// <summary>
|
---|
106 | /// Name of the style
|
---|
107 | /// </summary>
|
---|
108 | public string Name
|
---|
109 | {
|
---|
110 | get
|
---|
111 | {
|
---|
112 | return _name;
|
---|
113 | }
|
---|
114 | internal set
|
---|
115 | {
|
---|
116 | _name = value;
|
---|
117 | }
|
---|
118 | }
|
---|
119 | ExcelStyle _style = null;
|
---|
120 | /// <summary>
|
---|
121 | /// The style object
|
---|
122 | /// </summary>
|
---|
123 | public ExcelStyle Style
|
---|
124 | {
|
---|
125 | get
|
---|
126 | {
|
---|
127 | return _style;
|
---|
128 | }
|
---|
129 | internal set
|
---|
130 | {
|
---|
131 | _style = value;
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | internal override XmlNode CreateXmlNode(XmlNode topNode)
|
---|
136 | {
|
---|
137 | TopNode = topNode;
|
---|
138 | SetXmlNodeString(namePath, _name);
|
---|
139 | SetXmlNodeString("@xfId", _styles.CellStyleXfs[StyleXfId].newID.ToString());
|
---|
140 | if (BuildInId>=0) SetXmlNodeString("@builtinId", BuildInId.ToString());
|
---|
141 | if(CustomBuildin) SetXmlNodeBool(customBuiltinPath, true);
|
---|
142 | return TopNode;
|
---|
143 | }
|
---|
144 | }
|
---|
145 | }
|
---|