|
1 |
| -Getting started with Excel-DNA |
2 |
| -============================== |
3 |
| -
|
4 |
| -Do this first: |
5 |
| --------------- |
6 |
| -
|
7 |
| -* The .NET 2.0 runtime must be installed (or .NET 4 with additional settings). |
8 |
| -The .NET Framework Version 2.0 Redistributable Package is available from Microsoft here: |
9 |
| -http://www.microsoft.com/downloads/details.aspx?FamilyID=0856eacb-4362-4b0d-8edd-aab15c5e04f5&DisplayLang=en |
10 |
| -
|
11 |
| -* Macros security in Excel must not be 'Very High' or 'High' (if set to Medium -- it will prompt whether to enable each macro library). To use the .NET macros you will have to 'Enable' at the prompt. |
12 |
| -
|
13 |
| -
|
14 |
| -1. Create a user-defined function in Visual Basic |
15 |
| -------------------------------------------------- |
16 |
| -* Make a copy of ExcelDna.xll in a convenient directory, calling the copy Test1.xll. |
17 |
| -* Create a new text file, called Test1.dna (the same prefix as the .xll file), with contents: |
18 |
| -
|
19 |
| - <DnaLibrary RuntimeVersion="v2.0" Language="VB"> |
20 |
| - <![CDATA[ |
21 |
| - |
22 |
| - Public Module MyFunctions |
23 |
| -
|
24 |
| - Function AddThem(x, y) |
25 |
| - AddThem = x + y |
26 |
| - End Function |
27 |
| -
|
28 |
| - End Module |
29 |
| - |
30 |
| - ]]> |
31 |
| - </DnaLibrary> |
32 |
| -
|
33 |
| -* (To target .NET 4 or .NET 4.5, use RuntimeVersion="V4.0" instead.) |
34 |
| -* Load Test1.xll in Excel (either File->Open or Tools->Add-Ins and Browse). |
35 |
| -* You should be prompted whether to Enable Macros, click Enable. |
36 |
| -* Enter =AddThem(4,2) into a cell - you should get 6. |
37 |
| -* There should also be an entry for AddThem in the function wizard, under the category Test1. |
38 |
| -
|
39 |
| -Troubleshooting |
40 |
| ---------------- |
41 |
| -* If you are not prompted to Enable Macros and nothing else happens, your security level is probably on High. Set it to Medium. |
42 |
| -* If you get a message indicating that the .xll file is not recognized (and even opening it as text), you might not have the .NET Framework 2.0 installed. Install it. Otherwise Excel is using .Net version 1.1 by default. To change this, refer back to the prerequisites section. |
43 |
| -* If Excel crashes with an unhandled exception, an access violation or some other horrible error, either during loading or when running the function, please let me know. This shouldn't happen, and I would like to know if it does. |
44 |
| -* If a form appears with the title 'ExcelDna Compilation Errors' then there were some errors trying to compile the code in the .dna file. Check that you have put the right code into the .dna file. |
45 |
| -* If Excel prompts for Enabling Macros, and then the function does not work and does not appear in the function wizard, you might not have the right filename for the .dna file. The prefix should be the same as the .xll file and it should be in the same directory. |
46 |
| -* Otherwise, if something goes wrong, let me know or post to the Google group noted below. |
47 |
| -
|
48 |
| -2. Creating a user-defined function in C# |
49 |
| ------------------------------------------ |
50 |
| -* Change the contents of Test1.dna to: |
51 |
| -
|
52 |
| -<DnaLibrary RuntimeVersion="v2.0" Language="CS"> |
53 |
| - <![CDATA[ |
54 |
| - |
55 |
| - using ExcelDna.Integration; |
56 |
| - |
57 |
| - public class MyFunctions |
58 |
| - { |
59 |
| - [ExcelFunction(Description="Joins a string to a number", Category="Useful functions")] |
60 |
| - public static string JoinThem(string str, double val) |
61 |
| - { |
62 |
| - return str + val; |
63 |
| - } |
64 |
| - } |
65 |
| - |
66 |
| - ]]> |
67 |
| -</DnaLibrary> |
68 |
| -
|
69 |
| -* Reload the .xll, either from File->Open or in Tools->Add-Ins. |
70 |
| -* Check with the formula =JoinThem("abc", 123) |
71 |
| -* If the first example worked, this one should too. |
72 |
| -
|
73 |
| -3. Making the functions from a compiled library available |
74 |
| ---------------------------------------------------------- |
75 |
| -Excel-DNA can also load any compiled .NET library. Public static functions with a compatible signature are exported to Excel. |
76 |
| -
|
77 |
| -* Create a file called TestLib.cs containing the following code: |
78 |
| -
|
79 |
| - using ExcelDna.Integration; |
80 |
| - |
81 |
| - public class SomeClass |
82 |
| - { |
83 |
| -
|
84 |
| - [ExcelFunction(Description="Multiplies two numbers", Category="Useful functions")] |
85 |
| - public static double MultiplyThem(double v1, double v2) |
86 |
| - { |
87 |
| - return v1 * v2; |
88 |
| - } |
89 |
| - } |
90 |
| -
|
91 |
| -
|
92 |
| -* Compile TestLib.cs to TestLib.dll: from the command-line: |
93 |
| -c:\windows\microsoft.net\framework\v2.0.50727\csc.exe /target:library /reference:ExcelDna.Integration.dll TestLib.cs |
94 |
| -
|
95 |
| -* Modify Test1.dna to contain: |
96 |
| -
|
97 |
| - <DnaLibrary> |
98 |
| - <ExternalLibrary Path="TestLib.dll" /> |
99 |
| - </DnaLibrary> |
100 |
| -
|
101 |
| -* Reload the .xll and check =MultiplyThem(2,3) |
102 |
| -* To support .NET 4 assemblies, add a RuntimeVersion="v4.0" attribute to the DnaLibrary tag: |
103 |
| -
|
104 |
| - <DnaLibrary RuntimeVersion="v4.0"> |
105 |
| - <ExternalLibrary Path="TestLib.dll" /> |
106 |
| - </DnaLibrary> |
107 |
| -
|
108 |
| -4. Create an add-in using Visual Studio and the Excel-DNA NuGet package |
109 |
| ------------------------------------------------------------------------ |
110 |
| -Excel-DNA is also available as a NuGet package. Create a new "Class Library" project (in C#, Visual Basic or F#) and install the "Excel-DNA" package. |
111 |
| -The project will be configured as an Excel add-in, with additional information and instructions in the Readme.txt file that is displayed. |
112 |
| - |
113 |
| -5. Additional samples |
114 |
| ---------------------- |
115 |
| -Included in the distribution are various samples in the Distribution\Samples directory. Each sample is a .dna file which can be loaded by putting a renamed copy of ExcelDna.xll in the same directory, where <TheName>.dna must be matched by <TheName>.xll. |
116 |
| -
|
117 |
| -6. Getting Support |
118 |
| ------------------- |
119 |
| -The Excel-DNA Google group at https://groups.google.com/forum/#!forum/exceldna is the primary support forum. All questions are welcome. |
120 |
| -Formal support agreements for corporate users are also available - see http://excel-dna.net/support/ for details. |
| 1 | +Getting started with Excel-DNA |
| 2 | +============================== |
| 3 | + |
| 4 | +Do this first: |
| 5 | +-------------- |
| 6 | + |
| 7 | +* The .NET 2.0 runtime must be installed (or .NET 4 with additional settings). |
| 8 | +The .NET Framework Version 2.0 Redistributable Package is available from Microsoft here: |
| 9 | +http://www.microsoft.com/downloads/details.aspx?FamilyID=0856eacb-4362-4b0d-8edd-aab15c5e04f5&DisplayLang=en |
| 10 | + |
| 11 | +* Macros security in Excel must not be 'Very High' or 'High' (if set to Medium -- it will prompt whether to enable each macro library). To use the .NET macros you will have to 'Enable' at the prompt. |
| 12 | + |
| 13 | + |
| 14 | +1. Create a user-defined function in Visual Basic |
| 15 | +------------------------------------------------- |
| 16 | +* Make a copy of ExcelDna.xll in a convenient directory, calling the copy Test1.xll. |
| 17 | +* Create a new text file, called Test1.dna (the same prefix as the .xll file), with contents: |
| 18 | + |
| 19 | + <DnaLibrary RuntimeVersion="v2.0" Language="VB"> |
| 20 | + <![CDATA[ |
| 21 | + |
| 22 | + Public Module MyFunctions |
| 23 | + |
| 24 | + Function AddThem(x, y) |
| 25 | + AddThem = x + y |
| 26 | + End Function |
| 27 | + |
| 28 | + End Module |
| 29 | + |
| 30 | + ]]> |
| 31 | + </DnaLibrary> |
| 32 | + |
| 33 | +* (To target .NET 4 or .NET 4.5, use RuntimeVersion="V4.0" instead.) |
| 34 | +* Load Test1.xll in Excel (either File->Open or Tools->Add-Ins and Browse). |
| 35 | +* You should be prompted whether to Enable Macros, click Enable. |
| 36 | +* Enter =AddThem(4,2) into a cell - you should get 6. |
| 37 | +* There should also be an entry for AddThem in the function wizard, under the category Test1. |
| 38 | + |
| 39 | +Troubleshooting |
| 40 | +--------------- |
| 41 | +* If you are not prompted to Enable Macros and nothing else happens, your security level is probably on High. Set it to Medium. |
| 42 | +* If you get a message indicating that the .xll file is not recognized (and even opening it as text), you might not have the .NET Framework 2.0 installed. Install it. Otherwise Excel is using .Net version 1.1 by default. To change this, refer back to the prerequisites section. |
| 43 | +* If Excel crashes with an unhandled exception, an access violation or some other horrible error, either during loading or when running the function, please let me know. This shouldn't happen, and I would like to know if it does. |
| 44 | +* If a form appears with the title 'ExcelDna Compilation Errors' then there were some errors trying to compile the code in the .dna file. Check that you have put the right code into the .dna file. |
| 45 | +* If Excel prompts for Enabling Macros, and then the function does not work and does not appear in the function wizard, you might not have the right filename for the .dna file. The prefix should be the same as the .xll file and it should be in the same directory. |
| 46 | +* Otherwise, if something goes wrong, let me know or post to the Google group noted below. |
| 47 | + |
| 48 | +2. Creating a user-defined function in C# |
| 49 | +----------------------------------------- |
| 50 | +* Change the contents of Test1.dna to: |
| 51 | + |
| 52 | +<DnaLibrary RuntimeVersion="v2.0" Language="CS"> |
| 53 | + <![CDATA[ |
| 54 | + |
| 55 | + using ExcelDna.Integration; |
| 56 | + |
| 57 | + public class MyFunctions |
| 58 | + { |
| 59 | + [ExcelFunction(Description="Joins a string to a number", Category="Useful functions")] |
| 60 | + public static string JoinThem(string str, double val) |
| 61 | + { |
| 62 | + return str + val; |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + ]]> |
| 67 | +</DnaLibrary> |
| 68 | + |
| 69 | +* Reload the .xll, either from File->Open or in Tools->Add-Ins. |
| 70 | +* Check with the formula =JoinThem("abc", 123) |
| 71 | +* If the first example worked, this one should too. |
| 72 | + |
| 73 | +3. Making the functions from a compiled library available |
| 74 | +--------------------------------------------------------- |
| 75 | +Excel-DNA can also load any compiled .NET library. Public static functions with a compatible signature are exported to Excel. |
| 76 | + |
| 77 | +* Create a file called TestLib.cs containing the following code: |
| 78 | + |
| 79 | + using ExcelDna.Integration; |
| 80 | + |
| 81 | + public class SomeClass |
| 82 | + { |
| 83 | + |
| 84 | + [ExcelFunction(Description="Multiplies two numbers", Category="Useful functions")] |
| 85 | + public static double MultiplyThem(double v1, double v2) |
| 86 | + { |
| 87 | + return v1 * v2; |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + |
| 92 | +* Compile TestLib.cs to TestLib.dll: from the command-line: |
| 93 | +c:\windows\microsoft.net\framework\v2.0.50727\csc.exe /target:library /reference:ExcelDna.Integration.dll TestLib.cs |
| 94 | + |
| 95 | +* Modify Test1.dna to contain: |
| 96 | + |
| 97 | + <DnaLibrary> |
| 98 | + <ExternalLibrary Path="TestLib.dll" /> |
| 99 | + </DnaLibrary> |
| 100 | + |
| 101 | +* Reload the .xll and check =MultiplyThem(2,3) |
| 102 | +* To support .NET 4 assemblies, add a RuntimeVersion="v4.0" attribute to the DnaLibrary tag: |
| 103 | + |
| 104 | + <DnaLibrary RuntimeVersion="v4.0"> |
| 105 | + <ExternalLibrary Path="TestLib.dll" /> |
| 106 | + </DnaLibrary> |
| 107 | + |
| 108 | +4. Create an add-in using Visual Studio and the Excel-DNA NuGet package |
| 109 | +----------------------------------------------------------------------- |
| 110 | +Excel-DNA is also available as a NuGet package. Create a new "Class Library" project (in C#, Visual Basic or F#) and install the "ExcelDna.AddIn" package. |
| 111 | +The project will be configured as an Excel add-in, with additional information and instructions in the Readme.txt file that is displayed. |
| 112 | + |
| 113 | +5. Additional samples |
| 114 | +--------------------- |
| 115 | +Included in the distribution are various samples in the Distribution\Samples directory. Each sample is a .dna file which can be loaded by putting a renamed copy of ExcelDna.xll in the same directory, where <TheName>.dna must be matched by <TheName>.xll. |
| 116 | + |
| 117 | +6. Getting Support |
| 118 | +------------------ |
| 119 | +The Excel-DNA Google group at https://groups.google.com/forum/#!forum/exceldna is the primary support forum. All questions are welcome. |
| 120 | +Formal support agreements for corporate users are also available - see http://excel-dna.net/support/ for details. |
121 | 121 |
|
0 commit comments