Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3107_LearningALPS/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/4.0.3/EPPlus-4.0.3/Drawing/Vml/ExcelVmlDrawingPosition.cs

Last change on this file was 12074, checked in by sraggl, 10 years ago

#2341: Added EPPlus-4.0.3 to ExtLibs

File size: 4.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           2010-06-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;
36namespace OfficeOpenXml.Drawing.Vml
37{
38    /// <summary>
39    /// The position of a VML drawing. Used for comments
40    /// </summary>
41    public class ExcelVmlDrawingPosition : XmlHelper
42    {
43        int _startPos;
44        internal ExcelVmlDrawingPosition(XmlNamespaceManager ns, XmlNode topNode, int startPos) :
45            base(ns, topNode)
46        {
47            _startPos = startPos;
48        }
49        /// <summary>
50        /// Row. Zero based
51        /// </summary>
52        public int Row
53        {
54            get
55            {
56                return GetNumber(2);
57            }
58            set
59            {
60                SetNumber(2, value);
61            }
62        }
63        /// <summary>
64        /// Row offset in pixels. Zero based
65        /// </summary>
66        public int RowOffset
67        {
68            get
69            {
70                return GetNumber(3);
71            }
72            set
73            {
74                SetNumber(3, value);
75            }
76        }
77        /// <summary>
78        /// Column. Zero based
79        /// </summary>
80        public int Column
81        {
82            get
83            {
84                return GetNumber(0);
85            }
86            set
87            {
88                SetNumber(0, value);
89            }
90        }
91        /// <summary>
92        /// Column offset. Zero based
93        /// </summary>
94        public int ColumnOffset
95        {
96            get
97            {
98                return GetNumber(1);
99            }
100            set
101            {
102                SetNumber(1, value);
103            }
104        }
105        private void SetNumber(int pos, int value)
106        {
107            string anchor = GetXmlNodeString("x:Anchor");
108            string[] numbers = anchor.Split(',');
109            if (numbers.Length == 8)
110            {
111                numbers[_startPos + pos] = value.ToString();
112            }
113            else
114            {
115                throw (new Exception("Anchor element is invalid in vmlDrawing"));
116            }
117            SetXmlNodeString("x:Anchor", string.Join(",",numbers));
118        }
119
120        private int GetNumber(int pos)
121        {
122            string anchor = GetXmlNodeString("x:Anchor");
123            string[] numbers = anchor.Split(',');
124            if (numbers.Length == 8)
125            {
126                int ret;
127                if (int.TryParse(numbers[_startPos + pos], out ret))
128                {
129                    return ret;
130                }
131            }
132            throw(new Exception("Anchor element is invalid in vmlDrawing"));
133        }
134    }
135}
Note: See TracBrowser for help on using the repository browser.