Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/4.0.3/EPPlus-4.0.3/VBA/ExcelVbaModule.cs @ 15682

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

#2341: Added EPPlus-4.0.3 to ExtLibs

File size: 5.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    Added   26-MAR-2012
30 *******************************************************************************/
31using System;
32using System.Collections.Generic;
33using System.Linq;
34using System.Text;
35
36namespace OfficeOpenXml.VBA
37{
38    /// <summary>
39    /// Type of VBA module
40    /// </summary>
41    public enum eModuleType
42    {
43        /// <summary>
44        /// A Workbook or Worksheet objects
45        /// </summary>
46        Document=0,
47        /// <summary>
48        /// A Module
49        /// </summary>
50        Module=1,
51        /// <summary>
52        /// A Class
53        /// </summary>
54        Class=2,
55        /// <summary>
56        /// Designer, typically a user form
57        /// </summary>
58        Designer=3
59    }
60    internal delegate void ModuleNameChange(string value);
61
62    /// <summary>
63    /// A VBA code module.
64    /// </summary>
65    public class ExcelVBAModule
66    {
67        string _name = "";
68        ModuleNameChange _nameChangeCallback = null;
69        internal ExcelVBAModule()
70        {
71            Attributes = new ExcelVbaModuleAttributesCollection();
72        }
73        internal ExcelVBAModule(ModuleNameChange nameChangeCallback) :
74            this()
75        {
76            _nameChangeCallback = nameChangeCallback;
77        }
78        /// <summary>
79        /// The name of the module
80        /// </summary>
81        public string Name
82        {   
83            get
84            {
85                return _name;
86            }
87            set
88            {
89                if (value.Any(c => c > 255))
90                {
91                    throw (new InvalidOperationException("Vba module names can't contain unicode characters"));
92                }
93                if (value != _name)
94                {
95                    _name = value;
96                    streamName = value;
97                    if (_nameChangeCallback != null)
98                    {
99                        _nameChangeCallback(value);
100                    }
101                }
102            }
103        }
104        /// <summary>
105        /// A description of the module
106        /// </summary>
107        public string Description { get; set; }
108        private string _code="";
109        /// <summary>
110        /// The code without any module level attributes.
111        /// <remarks>Can contain function level attributes.</remarks>
112        /// </summary>
113        public string Code {
114            get
115            {
116                return _code;
117            }
118            set
119            {
120                if(value.StartsWith("Attribute",StringComparison.InvariantCultureIgnoreCase) || value.StartsWith("VERSION",StringComparison.InvariantCultureIgnoreCase))
121                {
122                    throw(new InvalidOperationException("Code can't start with an Attribute or VERSION keyword. Attributes can be accessed through the Attributes collection."));
123                }
124                _code = value;
125            }
126        }
127        /// <summary>
128        /// A reference to the helpfile
129        /// </summary>
130        public int HelpContext { get; set; }
131        /// <summary>
132        /// Module level attributes.
133        /// </summary>
134        public ExcelVbaModuleAttributesCollection Attributes { get; internal set; }
135        /// <summary>
136        /// Type of module
137        /// </summary>
138        public eModuleType Type { get; internal set; }
139        /// <summary>
140        /// If the module is readonly
141        /// </summary>
142        public bool ReadOnly { get; set; }
143        /// <summary>
144        /// If the module is private
145        /// </summary>
146        public bool Private { get; set; }
147        internal string streamName { get; set; }
148        internal ushort Cookie { get; set; }
149        internal uint ModuleOffset { get; set; }
150        internal string ClassID { get; set; }
151        public override string ToString()
152        {
153            return Name;
154        }
155    }
156}
Note: See TracBrowser for help on using the repository browser.