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 | *******************************************************************************/
|
---|
31 | using System;
|
---|
32 | using System.Collections.Generic;
|
---|
33 | using System.Linq;
|
---|
34 | using System.Text;
|
---|
35 |
|
---|
36 | namespace 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 | _name = value;
|
---|
90 | streamName = value;
|
---|
91 | if (_nameChangeCallback != null)
|
---|
92 | {
|
---|
93 | _nameChangeCallback(value);
|
---|
94 | }
|
---|
95 | }
|
---|
96 | }
|
---|
97 | /// <summary>
|
---|
98 | /// A description of the module
|
---|
99 | /// </summary>
|
---|
100 | public string Description { get; set; }
|
---|
101 | private string _code="";
|
---|
102 | /// <summary>
|
---|
103 | /// The code without any module level attributes.
|
---|
104 | /// <remarks>Can contain function level attributes.</remarks>
|
---|
105 | /// </summary>
|
---|
106 | public string Code {
|
---|
107 | get
|
---|
108 | {
|
---|
109 | return _code;
|
---|
110 | }
|
---|
111 | set
|
---|
112 | {
|
---|
113 | if(value.StartsWith("Attribute",StringComparison.InvariantCultureIgnoreCase) || value.StartsWith("VERSION",StringComparison.InvariantCultureIgnoreCase))
|
---|
114 | {
|
---|
115 | throw(new InvalidOperationException("Code can't start with an Attribute or VERSION keyword. Attributes can be accessed through the Attributes collection."));
|
---|
116 | }
|
---|
117 | _code = value;
|
---|
118 | }
|
---|
119 | }
|
---|
120 | /// <summary>
|
---|
121 | /// A reference to the helpfile
|
---|
122 | /// </summary>
|
---|
123 | public int HelpContext { get; set; }
|
---|
124 | /// <summary>
|
---|
125 | /// Module level attributes.
|
---|
126 | /// </summary>
|
---|
127 | public ExcelVbaModuleAttributesCollection Attributes { get; internal set; }
|
---|
128 | /// <summary>
|
---|
129 | /// Type of module
|
---|
130 | /// </summary>
|
---|
131 | public eModuleType Type { get; internal set; }
|
---|
132 | /// <summary>
|
---|
133 | /// If the module is readonly
|
---|
134 | /// </summary>
|
---|
135 | public bool ReadOnly { get; set; }
|
---|
136 | /// <summary>
|
---|
137 | /// If the module is private
|
---|
138 | /// </summary>
|
---|
139 | public bool Private { get; set; }
|
---|
140 | internal string streamName { get; set; }
|
---|
141 | internal ushort Cookie { get; set; }
|
---|
142 | internal uint ModuleOffset { get; set; }
|
---|
143 | internal string ClassID { get; set; }
|
---|
144 | public override string ToString()
|
---|
145 | {
|
---|
146 | return Name;
|
---|
147 | }
|
---|
148 | }
|
---|
149 | }
|
---|