Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/3.1.3/EPPlus-3.1.3/Style/ExcelParagraphCollection.cs @ 10355

Last change on this file since 10355 was 9580, checked in by sforsten, 12 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: 5.8 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.Drawing;
37using System.Drawing;
38
39namespace OfficeOpenXml.Style
40{
41    /// <summary>
42    /// A collection of Paragraph objects
43    /// </summary>
44    public class ExcelParagraphCollection : XmlHelper, IEnumerable<ExcelParagraph>
45    {
46        List<ExcelParagraph> _list = new List<ExcelParagraph>();
47        string _path;
48        internal ExcelParagraphCollection(XmlNamespaceManager ns, XmlNode topNode, string path, string[] schemaNodeOrder) :
49            base(ns, topNode)
50        {
51            var nl = topNode.SelectNodes(path + "/a:r", NameSpaceManager);
52            SchemaNodeOrder = schemaNodeOrder;
53            if (nl != null)
54            {
55                foreach (XmlNode n in nl)
56                {
57                    _list.Add(new ExcelParagraph(ns, n, "",schemaNodeOrder));
58                }
59            }
60            _path = path;
61        }
62        public ExcelParagraph this[int Index]
63        {
64            get
65            {
66                return _list[Index];
67            }
68        }
69        public int Count
70        {
71            get
72            {
73                return _list.Count;
74            }
75        }
76        /// <summary>
77        /// Add a rich text string
78        /// </summary>
79        /// <param name="Text">The text to add</param>
80        /// <returns></returns>
81        public ExcelParagraph Add(string Text)
82        {
83            XmlDocument doc;
84            if (TopNode is XmlDocument)
85            {
86                doc = TopNode as XmlDocument;
87            }
88            else
89            {
90                doc = TopNode.OwnerDocument;
91            }
92            XmlNode parentNode=TopNode.SelectSingleNode(_path, NameSpaceManager);
93            if (parentNode == null)
94            {
95                CreateNode(_path);
96            }
97           
98            var node = doc.CreateElement("a", "r", ExcelPackage.schemaDrawings);
99            parentNode.AppendChild(node);
100            var childNode = doc.CreateElement("a", "rPr", ExcelPackage.schemaDrawings);
101            node.AppendChild(childNode);
102            var rt = new ExcelParagraph(NameSpaceManager, node, "", SchemaNodeOrder);
103            rt.ComplexFont = "Calibri";
104            rt.LatinFont = "Calibri";
105            rt.Size = 11;
106
107            rt.Text = Text;
108            _list.Add(rt);
109            return rt;
110        }
111        public void Clear()
112        {
113            _list.Clear();
114            TopNode.RemoveAll();
115        }
116        public void RemoveAt(int Index)
117        {
118            var node = _list[Index].TopNode;
119            while (node != null && node.Name != "a:r")
120            {
121                node = node.ParentNode;
122            }
123            node.ParentNode.RemoveChild(node);
124            _list.RemoveAt(Index);
125        }
126        public void Remove(ExcelRichText Item)
127        {
128            TopNode.RemoveChild(Item.TopNode);
129        }
130        public string Text
131        {
132            get
133            {
134                StringBuilder sb = new StringBuilder();
135                foreach (var item in _list)
136                {
137                    sb.Append(item.Text);
138                }
139                return sb.ToString();
140            }
141            set
142            {
143                if (Count == 0)
144                {
145                    Add(value);
146                }
147                else
148                {
149                    this[0].Text = value;
150                    int count = Count;
151                    for (int ix = Count-1; ix > 0; ix--)
152                    {
153                        RemoveAt(ix);
154                    }
155                }
156            }
157        }
158        #region IEnumerable<ExcelRichText> Members
159
160        IEnumerator<ExcelParagraph> IEnumerable<ExcelParagraph>.GetEnumerator()
161        {
162            return _list.GetEnumerator();
163        }
164
165        #endregion
166
167        #region IEnumerable Members
168
169        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
170        {
171            return _list.GetEnumerator();
172        }
173
174        #endregion
175    }
176}
Note: See TracBrowser for help on using the repository browser.