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 Added 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 |
|
---|
38 | namespace OfficeOpenXml.Drawing.Chart
|
---|
39 | {
|
---|
40 | /// <summary>
|
---|
41 | /// The title of a chart
|
---|
42 | /// </summary>
|
---|
43 | public class ExcelChartTitle : XmlHelper
|
---|
44 | {
|
---|
45 | internal ExcelChartTitle(XmlNamespaceManager nameSpaceManager, XmlNode node) :
|
---|
46 | base(nameSpaceManager, node)
|
---|
47 | {
|
---|
48 | XmlNode topNode = node.SelectSingleNode("c:title", NameSpaceManager);
|
---|
49 | if (topNode == null)
|
---|
50 | {
|
---|
51 | topNode = node.OwnerDocument.CreateElement("c", "title", ExcelPackage.schemaChart);
|
---|
52 | node.InsertBefore(topNode, node.ChildNodes[0]);
|
---|
53 | topNode.InnerXml = "<c:tx><c:rich><a:bodyPr /><a:lstStyle /><a:p><a:pPr><a:defRPr sz=\"1800\" b=\"0\" /></a:pPr><a:r><a:t /></a:r></a:p></c:rich></c:tx><c:layout /><c:overlay val=\"0\" />";
|
---|
54 | }
|
---|
55 | TopNode = topNode;
|
---|
56 | SchemaNodeOrder = new string[] { "tx","bodyPr", "lstStyle", "layout", "overlay" };
|
---|
57 | }
|
---|
58 | const string titlePath = "c:tx/c:rich/a:p/a:r/a:t";
|
---|
59 | /// <summary>
|
---|
60 | /// The text
|
---|
61 | /// </summary>
|
---|
62 | public string Text
|
---|
63 | {
|
---|
64 | get
|
---|
65 | {
|
---|
66 | //return GetXmlNode(titlePath);
|
---|
67 | return RichText.Text;
|
---|
68 | }
|
---|
69 | set
|
---|
70 | {
|
---|
71 | //SetXmlNode(titlePath, value);
|
---|
72 | RichText.Text = value;
|
---|
73 | }
|
---|
74 | }
|
---|
75 | ExcelDrawingBorder _border = null;
|
---|
76 | /// <summary>
|
---|
77 | /// A reference to the border properties
|
---|
78 | /// </summary>
|
---|
79 | public ExcelDrawingBorder Border
|
---|
80 | {
|
---|
81 | get
|
---|
82 | {
|
---|
83 | if (_border == null)
|
---|
84 | {
|
---|
85 | _border = new ExcelDrawingBorder(NameSpaceManager, TopNode, "c:spPr/a:ln");
|
---|
86 | }
|
---|
87 | return _border;
|
---|
88 | }
|
---|
89 | }
|
---|
90 | ExcelDrawingFill _fill = null;
|
---|
91 | /// <summary>
|
---|
92 | /// A reference to the fill properties
|
---|
93 | /// </summary>
|
---|
94 | public ExcelDrawingFill Fill
|
---|
95 | {
|
---|
96 | get
|
---|
97 | {
|
---|
98 | if (_fill == null)
|
---|
99 | {
|
---|
100 | _fill = new ExcelDrawingFill(NameSpaceManager, TopNode, "c:spPr");
|
---|
101 | }
|
---|
102 | return _fill;
|
---|
103 | }
|
---|
104 | }
|
---|
105 | //ExcelTextFont _font = null;
|
---|
106 | /// <summary>
|
---|
107 | /// A reference to the font properties
|
---|
108 | /// </summary>
|
---|
109 | public ExcelTextFont Font
|
---|
110 | {
|
---|
111 | get
|
---|
112 | {
|
---|
113 | //if (_font == null)
|
---|
114 | //{
|
---|
115 | // _font = new ExcelTextFont(NameSpaceManager, TopNode, "c:tx/c:rich/a:p/a:r/a:rPr", new string[] { "rPr", "solidFill", "uFill", "latin", "cs", "r", "rPr", "t" });
|
---|
116 | //}
|
---|
117 | //return _font;
|
---|
118 | if (_richText==null || _richText.Count == 0)
|
---|
119 | {
|
---|
120 | RichText.Add("");
|
---|
121 | }
|
---|
122 | return _richText[0];
|
---|
123 | }
|
---|
124 | }
|
---|
125 | string[] paragraphNodeOrder = new string[] { "pPr", "defRPr", "solidFill", "uFill", "latin", "cs", "r", "rPr", "t" };
|
---|
126 | ExcelParagraphCollection _richText = null;
|
---|
127 | /// <summary>
|
---|
128 | /// Richtext
|
---|
129 | /// </summary>
|
---|
130 | public ExcelParagraphCollection RichText
|
---|
131 | {
|
---|
132 | get
|
---|
133 | {
|
---|
134 | if (_richText == null)
|
---|
135 | {
|
---|
136 | _richText = new ExcelParagraphCollection(NameSpaceManager, TopNode, "c:tx/c:rich/a:p", paragraphNodeOrder);
|
---|
137 | }
|
---|
138 | return _richText;
|
---|
139 | }
|
---|
140 | }
|
---|
141 | /// <summary>
|
---|
142 | /// Show without overlaping the chart.
|
---|
143 | /// </summary>
|
---|
144 | public bool Overlay
|
---|
145 | {
|
---|
146 | get
|
---|
147 | {
|
---|
148 | return GetXmlNodeBool("c:overlay/@val");
|
---|
149 | }
|
---|
150 | set
|
---|
151 | {
|
---|
152 | SetXmlNodeBool("c:overlay/@val", value);
|
---|
153 | }
|
---|
154 | }
|
---|
155 | /// <summary>
|
---|
156 | /// Specifies the centering of the text box.
|
---|
157 | /// The way it works fundamentally is to determine the smallest possible "bounds box" for the text and then to center that "bounds box" accordingly.
|
---|
158 | /// This is different than paragraph alignment, which aligns the text within the "bounds box" for the text.
|
---|
159 | /// This flag is compatible with all of the different kinds of anchoring.
|
---|
160 | /// If this attribute is omitted, then a value of 0 or false is implied.
|
---|
161 | /// </summary>
|
---|
162 | public bool AnchorCtr
|
---|
163 | {
|
---|
164 | get
|
---|
165 | {
|
---|
166 | return GetXmlNodeBool("c:tx/c:rich/a:bodyPr/@anchorCtr", false);
|
---|
167 | }
|
---|
168 | set
|
---|
169 | {
|
---|
170 | SetXmlNodeBool("c:tx/c:rich/a:bodyPr/@anchorCtr", value, false);
|
---|
171 | }
|
---|
172 | }
|
---|
173 | public eTextAnchoringType Anchor
|
---|
174 | {
|
---|
175 | get
|
---|
176 | {
|
---|
177 | return ExcelDrawing.GetTextAchoringEnum(GetXmlNodeString("c:tx/c:rich/a:bodyPr/@anchor"));
|
---|
178 | }
|
---|
179 | set
|
---|
180 | {
|
---|
181 | SetXmlNodeString("c:tx/c:rich/a:bodyPr/@anchorCtr", ExcelDrawing.GetTextAchoringText(value));
|
---|
182 | }
|
---|
183 | }
|
---|
184 | const string TextVerticalPath = "xdr:sp/xdr:txBody/a:bodyPr/@vert";
|
---|
185 | /// <summary>
|
---|
186 | /// Vertical text
|
---|
187 | /// </summary>
|
---|
188 | public eTextVerticalType TextVertical
|
---|
189 | {
|
---|
190 | get
|
---|
191 | {
|
---|
192 | return ExcelDrawing.GetTextVerticalEnum(GetXmlNodeString("c:tx/c:rich/a:bodyPr/@vert"));
|
---|
193 | }
|
---|
194 | set
|
---|
195 | {
|
---|
196 | SetXmlNodeString("c:tx/c:rich/a:bodyPr/@vert", ExcelDrawing.GetTextVerticalText(value));
|
---|
197 | }
|
---|
198 | }
|
---|
199 | /// <summary>
|
---|
200 | /// Rotation in degrees (0-360)
|
---|
201 | /// </summary>
|
---|
202 | public double Rotation
|
---|
203 | {
|
---|
204 | get
|
---|
205 | {
|
---|
206 | var i=GetXmlNodeInt("c:tx/c:rich/a:bodyPr/@rot");
|
---|
207 | if (i < 0)
|
---|
208 | {
|
---|
209 | return 360 - (i / 60000);
|
---|
210 | }
|
---|
211 | else
|
---|
212 | {
|
---|
213 | return (i / 60000);
|
---|
214 | }
|
---|
215 | }
|
---|
216 | set
|
---|
217 | {
|
---|
218 | int v;
|
---|
219 | if(value <0 || value > 360)
|
---|
220 | {
|
---|
221 | throw(new ArgumentOutOfRangeException("Rotation must be between 0 and 360"));
|
---|
222 | }
|
---|
223 |
|
---|
224 | if (value > 180)
|
---|
225 | {
|
---|
226 | v = (int)((value - 360) * 60000);
|
---|
227 | }
|
---|
228 | else
|
---|
229 | {
|
---|
230 | v = (int)(value * 60000);
|
---|
231 | }
|
---|
232 | SetXmlNodeString("c:tx/c:rich/a:bodyPr/@rot", v.ToString());
|
---|
233 | }
|
---|
234 | }
|
---|
235 | }
|
---|
236 | }
|
---|