Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HLScript/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/3.1.3/EPPlus-3.1.3/VBA/ExcelVBAModuleCollection.cs @ 10331

Last change on this file since 10331 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: 7.9 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    Added   12-APR-2012
30 *******************************************************************************/
31using System;
32using System.Collections.Generic;
33using System.Linq;
34using System.Text;
35
36namespace OfficeOpenXml.VBA
37{
38    /// <summary>
39    /// Base class for VBA collections
40    /// </summary>
41    /// <typeparam name="T"></typeparam>
42    public class ExcelVBACollectionBase<T> : IEnumerable<T>
43    {
44        internal protected List<T> _list=new List<T>();       
45        public IEnumerator<T> GetEnumerator()
46        {
47            return _list.GetEnumerator();
48        }
49
50        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
51        {
52            return _list.GetEnumerator();
53        }
54        /// <summary>
55        /// Indexer
56        /// </summary>
57        /// <param name="Name">Name</param>
58        /// <returns></returns>
59        public T this [string Name]
60        {
61            get
62            {
63                return _list.Find((f) => f.GetType().GetProperty("Name").GetValue(f, null).ToString().ToLower() == Name.ToLower());
64            }
65        }
66        /// <summary>
67        /// Indexer
68        /// </summary>
69        /// <param name="Index">Position</param>
70        /// <returns></returns>
71        public T this[int Index]
72        {
73            get
74            {
75                return _list[Index];
76            }
77        }
78        /// <summary>
79        /// Number of items in the collection
80        /// </summary>
81        public int Count
82        {
83            get { return _list.Count; }
84        }
85        /// <summary>
86        /// If a specific name exists in the collection
87        /// </summary>
88        /// <param name="Name">The name</param>
89        /// <returns>True if the name exists</returns>
90        public bool Exists(string Name)
91        {
92            return _list.Exists((f) => f.GetType().GetProperty("Name").GetValue(f, null).ToString().ToLower() == Name.ToLower());
93        }
94        /// <summary>
95        /// Removes the item
96        /// </summary>
97        /// <param name="Item"></param>
98        public void Remove(T Item)
99        {
100            _list.Remove(Item);
101        }
102        /// <summary>
103        /// Removes the item at the specified index
104        /// </summary>
105        /// <param name="index">THe index</param>
106        public void RemoveAt(int index)
107        {
108            _list.RemoveAt(index);
109        }
110       
111        internal void Clear()
112        {
113            _list.Clear();
114        }
115    }
116    /// <summary>
117    /// Collection class for VBA modules
118    /// </summary>
119    public class ExcelVbaModuleCollection : ExcelVBACollectionBase<ExcelVBAModule>
120    {
121        ExcelVbaProject _project;
122        internal ExcelVbaModuleCollection (ExcelVbaProject project)
123      {
124            _project=project;
125      }
126        internal void Add(ExcelVBAModule Item)
127        {
128            _list.Add(Item);
129        }
130        /// <summary>
131        /// Adds a new VBA Module
132        /// </summary>
133        /// <param name="Name">The name of the module</param>
134        /// <returns>The module object</returns>
135        public ExcelVBAModule AddModule(string Name)
136        {
137            var m = new ExcelVBAModule();
138            m.Name = Name;
139            m.Type = eModuleType.Module;
140            m.Attributes._list.Add(new ExcelVbaModuleAttribute() { Name = "VB_Name", Value = Name, DataType = eAttributeDataType.String });
141            m.Type = eModuleType.Module;
142            _list.Add(m);
143            return m;
144        }
145        /// <summary>
146        /// Adds a new VBA class
147        /// </summary>
148        /// <param name="Name">The name of the class</param>
149        /// <param name="Exposed">Private or Public not createble</param>
150        /// <returns>The class object</returns>
151        public ExcelVBAModule AddClass(string Name, bool Exposed)
152        {
153            var m = new ExcelVBAModule();
154            m.Name = Name;           
155            m.Type = eModuleType.Class;
156            m.Attributes._list.Add(new ExcelVbaModuleAttribute() { Name = "VB_Name", Value = Name, DataType = eAttributeDataType.String });
157            m.Attributes._list.Add(new ExcelVbaModuleAttribute() { Name = "VB_Base", Value = "0{FCFB3D2A-A0FA-1068-A738-08002B3371B5}", DataType = eAttributeDataType.String });
158            m.Attributes._list.Add(new ExcelVbaModuleAttribute() { Name = "VB_GlobalNameSpace", Value = "False", DataType = eAttributeDataType.NonString });
159            m.Attributes._list.Add(new ExcelVbaModuleAttribute() { Name = "VB_Creatable", Value = "False", DataType = eAttributeDataType.NonString });
160            m.Attributes._list.Add(new ExcelVbaModuleAttribute() { Name = "VB_PredeclaredId", Value = "False", DataType = eAttributeDataType.NonString });
161            m.Attributes._list.Add(new ExcelVbaModuleAttribute() { Name = "VB_Exposed", Value = Exposed ? "True" : "False", DataType = eAttributeDataType.NonString });
162            m.Attributes._list.Add(new ExcelVbaModuleAttribute() { Name = "VB_TemplateDerived", Value = "False", DataType = eAttributeDataType.NonString });
163            m.Attributes._list.Add(new ExcelVbaModuleAttribute() { Name = "VB_Customizable", Value = "False", DataType = eAttributeDataType.NonString });
164
165            //m.Code = _project.GetBlankClassModule(Name, Exposed);
166            m.Private = !Exposed;
167            //m.ClassID=
168            _list.Add(m);
169            return m;
170        }
171    }
172    /// <summary>
173    /// A collection of the vba projects references
174    /// </summary>
175    public class ExcelVbaReferenceCollection : ExcelVBACollectionBase<ExcelVbaReference>
176    {       
177        internal ExcelVbaReferenceCollection()
178        {
179
180        }
181        /// <summary>
182        /// Adds a new reference
183        /// </summary>
184        /// <param name="Item">The reference object</param>
185        public void Add(ExcelVbaReference Item)
186        {
187            _list.Add(Item);
188        }
189    }
190    /// <summary>
191    /// A collection of the module level attributes
192    /// </summary>
193    public class ExcelVbaModuleAttributesCollection : ExcelVBACollectionBase<ExcelVbaModuleAttribute>
194    {
195        internal string GetAttributeText()
196        {
197            StringBuilder sb=new StringBuilder();
198
199            foreach (var attr in this)
200            {
201                sb.AppendFormat("Attribute {0} = {1}\r\n", attr.Name, attr.DataType==eAttributeDataType.String ? "\"" + attr.Value + "\"" : attr.Value);
202            }
203            return sb.ToString();
204        }
205    }
206}
Note: See TracBrowser for help on using the repository browser.