Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ExportSymbolicDataAnalysisSolutions/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/3.1.3/EPPlus-3.1.3/Drawing/ExcelShape.cs @ 9580

Last change on this file since 9580 was 9580, checked in by sforsten, 11 years ago

#1730:

  • added SymbolicDataAnalysisExpressionExcelFormatter
  • changed modifiers in SymbolicExpressionTreeChart of methods SaveImageAsBitmap and SaveImageAsEmf to public
  • added menu item ExportSymbolicSolutionToExcelMenuItem to export a symbolic solution to an excel file
  • added EPPlus-3.1.3 to ExtLibs
File size: 16.3 KB
Line 
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 *******************************************************************************/
32using System;
33using System.Collections.Generic;
34using System.Text;
35using System.Xml;
36using OfficeOpenXml.Style.XmlAccess;
37using OfficeOpenXml.Drawing;
38using OfficeOpenXml.Style;
39/// <summary>
40/// Shape style
41/// </summary>
42public enum eShapeStyle
43{
44    AccentBorderCallout1,
45    AccentBorderCallout2,
46    AccentBorderCallout3,
47    AccentCallout1,
48    AccentCallout2,
49    AccentCallout3,
50    ActionButtonBackPrevious,
51    ActionButtonBeginning,
52    ActionButtonBlank,
53    ActionButtonDocument,
54    ActionButtonEnd,
55    ActionButtonForwardNext,
56    ActionButtonHelp,
57    ActionButtonHome,
58    ActionButtonInformation,
59    ActionButtonMovie,
60    ActionButtonReturn,
61    ActionButtonSound,
62    Arc,
63    BentArrow,
64    BentConnector2,
65    BentConnector3,
66    BentConnector4,
67    BentConnector5,
68    BentUpArrow,
69    Bevel,
70    BlockArc,
71    BorderCallout1,
72    BorderCallout2,
73    BorderCallout3,
74    BracePair,
75    BracketPair,
76    Callout1,
77    Callout2,
78    Callout3,
79    Can,
80    ChartPlus,
81    ChartStar,
82    ChartX,
83    Chevron,
84    Chord,
85    CircularArrow,
86    Cloud,
87    CloudCallout,
88    Corner,
89    CornerTabs,
90    Cube,
91    CurvedConnector2,
92    CurvedConnector3,
93    CurvedConnector4,
94    CurvedConnector5,
95    CurvedDownArrow,
96    CurvedLeftArrow,
97    CurvedRightArrow,
98    CurvedUpArrow,
99    Decagon,
100    DiagStripe,
101    Diamond,
102    Dodecagon,
103    Donut,
104    DoubleWave,
105    DownArrow,
106    DownArrowCallout,
107    Ellipse,
108    EllipseRibbon,
109    EllipseRibbon2,
110    FlowChartAlternateProcess,
111    FlowChartCollate,
112    FlowChartConnector,
113    FlowChartDecision,
114    FlowChartDelay,
115    FlowChartDisplay,
116    FlowChartDocument,
117    FlowChartExtract,
118    FlowChartInputOutput,
119    FlowChartInternalStorage,
120    FlowChartMagneticDisk,
121    FlowChartMagneticDrum,
122    FlowChartMagneticTape,
123    FlowChartManualInput,
124    FlowChartManualOperation,
125    FlowChartMerge,
126    FlowChartMultidocument,
127    FlowChartOfflineStorage,
128    FlowChartOffpageConnector,
129    FlowChartOnlineStorage,
130    FlowChartOr,
131    FlowChartPredefinedProcess,
132    FlowChartPreparation,
133    FlowChartProcess,
134    FlowChartPunchedCard,
135    FlowChartPunchedTape,
136    FlowChartSort,
137    FlowChartSummingJunction,
138    FlowChartTerminator,
139    FoldedCorner,
140    Frame,
141    Funnel,
142    Gear6,
143    Gear9,
144    HalfFrame,
145    Heart,
146    Heptagon,
147    Hexagon,
148    HomePlate,
149    HorizontalScroll,
150    IrregularSeal1,
151    IrregularSeal2,
152    LeftArrow,
153    LeftArrowCallout,
154    LeftBrace,
155    LeftBracket,
156    LeftCircularArrow,
157    LeftRightArrow,
158    LeftRightArrowCallout,
159    LeftRightCircularArrow,
160    LeftRightRibbon,
161    LeftRightUpArrow,
162    LeftUpArrow,
163    LightningBolt,
164    Line,
165    LineInv,
166    MathDivide,
167    MathEqual,
168    MathMinus,
169    MathMultiply,
170    MathNotEqual,
171    MathPlus,
172    Moon,
173    NonIsoscelesTrapezoid,
174    NoSmoking,
175    NotchedRightArrow,
176    Octagon,
177    Parallelogram,
178    Pentagon,
179    Pie,
180    PieWedge,
181    Plaque,
182    PlaqueTabs,
183    Plus,
184    QuadArrow,
185    QuadArrowCallout,
186    Rect,
187    Ribbon,
188    Ribbon2,
189    RightArrow,
190    RightArrowCallout,
191    RightBrace,
192    RightBracket,
193    Round1Rect,
194    Round2DiagRect,
195    Round2SameRect,
196    RoundRect,
197    RtTriangle,
198    SmileyFace,
199    Snip1Rect,
200    Snip2DiagRect,
201    Snip2SameRect,
202    SnipRoundRect,
203    SquareTabs,
204    Star10,
205    Star12,
206    Star16,
207    Star24,
208    Star32,
209    Star4,
210    Star5,
211    Star6,
212    Star7,
213    Star8,
214    StraightConnector1,
215    StripedRightArrow,
216    Sun,
217    SwooshArrow,
218    Teardrop,
219    Trapezoid,
220    Triangle,
221    UpArrow,
222    UpArrowCallout,
223    UpDownArrow,
224    UpDownArrowCallout,
225    UturnArrow,
226    Wave,
227    WedgeEllipseCallout,
228    WedgeRectCallout,
229    WedgeRoundRectCallout,
230    VerticalScroll
231}
232/// <summary>
233/// Text alignment
234/// </summary>
235public enum eTextAlignment
236{
237    Left,
238    Center,
239    Right,
240    Distributed,
241    Justified,
242    JustifiedLow,
243    ThaiDistributed
244}
245/// <summary>
246/// Fillstyle.
247/// </summary>
248public enum eFillStyle
249{
250    NoFill,
251    SolidFill,
252    GradientFill,
253    PatternFill,
254    BlipFill,
255    GroupFill
256}
257namespace OfficeOpenXml.Drawing
258{
259    /// <summary>
260    /// An Excel shape.
261    /// </summary>
262    public sealed class ExcelShape : ExcelDrawing
263    {
264        internal ExcelShape(ExcelDrawings drawings, XmlNode node) :
265            base(drawings, node, "xdr:sp/xdr:nvSpPr/xdr:cNvPr/@name")
266        {
267            init();
268        }
269        internal ExcelShape(ExcelDrawings drawings, XmlNode node, eShapeStyle style) :
270            base(drawings, node, "xdr:sp/xdr:nvSpPr/xdr:cNvPr/@name")
271        {
272            init();
273            XmlElement shapeNode = node.OwnerDocument.CreateElement("xdr", "sp", ExcelPackage.schemaSheetDrawings);
274            shapeNode.SetAttribute("macro", "");
275            shapeNode.SetAttribute("textlink", "");
276            node.AppendChild(shapeNode);
277
278            shapeNode.InnerXml = ShapeStartXml();
279            node.AppendChild(shapeNode.OwnerDocument.CreateElement("xdr", "clientData", ExcelPackage.schemaSheetDrawings));
280        }
281        private void init()
282        {
283            SchemaNodeOrder = new string[] { "prstGeom", "ln", "pPr", "defRPr", "solidFill", "uFill", "latin", "cs", "r", "rPr", "t" };
284        }
285        #region "public methods"
286        const string ShapeStylePath = "xdr:sp/xdr:spPr/a:prstGeom/@prst";
287        /// <summary>
288        /// Shape style
289        /// </summary>
290        public eShapeStyle Style
291        {
292            get
293            {
294                string v = GetXmlNodeString(ShapeStylePath);
295                try
296                {
297                    return (eShapeStyle)Enum.Parse(typeof(eShapeStyle), v, true);
298                }
299                catch
300                {
301                    throw (new Exception(string.Format("Invalid shapetype {0}", v)));
302                }
303            }
304            set
305            {
306                string v = value.ToString();
307                v = v.Substring(0, 1).ToLower() + v.Substring(1, v.Length - 1);
308                SetXmlNodeString(ShapeStylePath, v);
309            }
310        }
311        ExcelDrawingFill _fill = null;
312        /// <summary>
313        /// Fill
314        /// </summary>
315        public ExcelDrawingFill Fill
316        {
317            get
318            {
319                if (_fill == null)
320                {
321                    _fill = new ExcelDrawingFill(NameSpaceManager, TopNode, "xdr:sp/xdr:spPr");
322                }
323                return _fill;
324            }
325        }
326        ExcelDrawingBorder _border = null;
327        /// <summary>
328        /// Border
329        /// </summary>
330        public ExcelDrawingBorder Border       
331        {
332            get
333            {
334                if (_border == null)
335                {
336                    _border = new ExcelDrawingBorder(NameSpaceManager, TopNode, "xdr:sp/xdr:spPr/a:ln");
337                }
338                return _border;
339            }
340        }
341        string[] paragraphNodeOrder = new string[] { "pPr", "defRPr", "solidFill", "uFill", "latin", "cs", "r", "rPr", "t" };
342        const string PARAGRAPH_PATH = "xdr:sp/xdr:txBody/a:p";
343        ExcelTextFont _font=null;
344        public ExcelTextFont Font
345        {
346            get
347            {
348                if (_font == null)
349                {
350                    XmlNode node = TopNode.SelectSingleNode(PARAGRAPH_PATH, NameSpaceManager);
351                    if(node==null)
352                    {
353                        Text="";    //Creates the node p element
354                        node = TopNode.SelectSingleNode(PARAGRAPH_PATH, NameSpaceManager);
355                    }
356                    _font = new ExcelTextFont(NameSpaceManager, TopNode, "xdr:sp/xdr:txBody/a:p/a:pPr/a:defRPr", paragraphNodeOrder);
357                }
358                return _font;
359            }
360        }
361        const string TextPath = "xdr:sp/xdr:txBody/a:p/a:r/a:t";
362        /// <summary>
363        /// Text inside the shape
364        /// </summary>
365        public string Text
366        {
367            get
368            {
369                return GetXmlNodeString(TextPath);
370            }
371            set
372            {
373                SetXmlNodeString(TextPath, value);
374            }
375
376        }
377        string lockTextPath = "xdr:sp/@fLocksText";
378        /// <summary>
379        /// Lock drawing
380        /// </summary>
381        public bool LockText
382        {
383            get
384            {
385                return GetXmlNodeBool(lockTextPath, true);
386            }
387            set
388            {
389                SetXmlNodeBool(lockTextPath, value);
390            }
391        }
392        ExcelParagraphCollection _richText = null;
393        /// <summary>
394        /// Richtext collection. Used to format specific parts of the text
395        /// </summary>
396        public ExcelParagraphCollection RichText
397        {
398            get
399            {
400                if (_richText == null)
401                {
402                    //XmlNode node=TopNode.SelectSingleNode(PARAGRAPH_PATH, NameSpaceManager);
403                    //if (node == null)
404                    //{
405                    //    CreateNode(PARAGRAPH_PATH);
406                    //}
407                        _richText = new ExcelParagraphCollection(NameSpaceManager, TopNode, PARAGRAPH_PATH, paragraphNodeOrder);
408                }
409                return _richText;
410            }
411        }
412        const string TextAnchoringPath = "xdr:sp/xdr:txBody/a:bodyPr/@anchor";
413        /// <summary>
414        /// Text Anchoring
415        /// </summary>
416        public eTextAnchoringType TextAnchoring
417        {
418            get
419            {
420                return GetTextAchoringEnum(GetXmlNodeString(TextAnchoringPath));
421            }
422            set
423            {
424                SetXmlNodeString(TextAnchoringPath, GetTextAchoringText(value));
425            }
426        }
427        const string TextAnchoringCtlPath = "xdr:sp/xdr:txBody/a:bodyPr/@anchorCtr";
428        /// <summary>
429        /// Specifies the centering of the text box.
430        /// </summary>
431        public bool TextAnchoringControl
432        {
433            get
434            {
435                return GetXmlNodeBool(TextAnchoringCtlPath);
436            }
437            set
438            {
439                if (value)
440                {
441                    SetXmlNodeString(TextAnchoringCtlPath, "1");
442                }
443                else
444                {
445                    SetXmlNodeString(TextAnchoringCtlPath, "0");
446                }
447            }
448        }
449        const string TEXT_ALIGN_PATH = "xdr:sp/xdr:txBody/a:p/a:pPr/@algn";
450        /// <summary>
451        /// How the text is aligned
452        /// </summary>
453        public eTextAlignment TextAlignment
454        {
455            get
456            {
457               switch(GetXmlNodeString(TEXT_ALIGN_PATH))
458               {
459                   case "ctr":
460                       return eTextAlignment.Center;
461                   case "r":
462                       return eTextAlignment.Right;
463                   case "dist":
464                       return eTextAlignment.Distributed;
465                   case "just":
466                       return eTextAlignment.Justified;
467                   case "justLow":
468                       return eTextAlignment.JustifiedLow;
469                   case "thaiDist":
470                       return eTextAlignment.ThaiDistributed;
471                   default:
472                       return eTextAlignment.Left;
473               }
474            }
475            set
476            {
477                switch (value)
478                {
479                    case eTextAlignment.Right:
480                        SetXmlNodeString(TEXT_ALIGN_PATH, "r");
481                        break;
482                    case eTextAlignment.Center:
483                        SetXmlNodeString(TEXT_ALIGN_PATH, "ctr");
484                        break;
485                    case eTextAlignment.Distributed:
486                        SetXmlNodeString(TEXT_ALIGN_PATH, "dist");
487                        break;
488                    case eTextAlignment.Justified:
489                        SetXmlNodeString(TEXT_ALIGN_PATH, "just");
490                        break;
491                    case eTextAlignment.JustifiedLow:
492                        SetXmlNodeString(TEXT_ALIGN_PATH, "justLow");
493                        break;
494                    case eTextAlignment.ThaiDistributed:
495                        SetXmlNodeString(TEXT_ALIGN_PATH, "thaiDist");
496                        break;
497                    default:
498                        DeleteNode(TEXT_ALIGN_PATH);
499                        break;
500                }               
501            }
502        }
503        const string INDENT_ALIGN_PATH = "xdr:sp/xdr:txBody/a:p/a:pPr/@lvl";
504        /// <summary>
505        /// Indentation
506        /// </summary>
507        public int Indent
508        {
509            get
510            {
511                return GetXmlNodeInt(INDENT_ALIGN_PATH);
512            }
513            set
514            {
515                if (value < 0 || value > 8)
516                {
517                    throw(new ArgumentOutOfRangeException("Indent level must be between 0 and 8"));
518                }
519                SetXmlNodeString(INDENT_ALIGN_PATH, value.ToString());
520            }
521        }
522        const string TextVerticalPath = "xdr:sp/xdr:txBody/a:bodyPr/@vert";
523        /// <summary>
524        /// Vertical text
525        /// </summary>
526        public eTextVerticalType TextVertical
527        {
528            get
529            {
530                return GetTextVerticalEnum(GetXmlNodeString(TextVerticalPath));
531            }
532            set
533            {
534                SetXmlNodeString(TextVerticalPath, GetTextVerticalText(value));
535            }
536        }
537
538        #endregion
539        #region "Private Methods"
540        private string ShapeStartXml()
541        {
542            StringBuilder xml = new StringBuilder();
543            xml.AppendFormat("<xdr:nvSpPr><xdr:cNvPr id=\"{0}\" name=\"{1}\" /><xdr:cNvSpPr /></xdr:nvSpPr><xdr:spPr><a:prstGeom prst=\"rect\"><a:avLst /></a:prstGeom></xdr:spPr><xdr:style><a:lnRef idx=\"2\"><a:schemeClr val=\"accent1\"><a:shade val=\"50000\" /></a:schemeClr></a:lnRef><a:fillRef idx=\"1\"><a:schemeClr val=\"accent1\" /></a:fillRef><a:effectRef idx=\"0\"><a:schemeClr val=\"accent1\" /></a:effectRef><a:fontRef idx=\"minor\"><a:schemeClr val=\"lt1\" /></a:fontRef></xdr:style><xdr:txBody><a:bodyPr vertOverflow=\"clip\" rtlCol=\"0\" anchor=\"ctr\" /><a:lstStyle /><a:p></a:p></xdr:txBody>", _id, Name);
544            return xml.ToString();
545        }
546        #endregion
547        internal new string Id
548        {
549            get { return Name + Text; }
550        }
551    }
552}
Note: See TracBrowser for help on using the repository browser.