Just thought you'd like to hear of a technique that has worked for
I have a bunch of "legacy" Java code that I have previously called in
Excel using a Java/COM bridge (J-Integra). Because of the fact that
the interface is COM I have to write a bnuch of wrapper functions in
VBA to be able to call my API from within Excel.
Well, a better approach as I have discovered is to use IKVM to run my
Java code in .NET and then use ExcelDna to create the addin portion.
Here are the steps I use:
(1) Create some Java interfaces that are exact analogues of the ones I
am interested in in ExcelDna (this is not required as you can use the
IKVMSTUB exe to create stub JAR files from the ExcelDna assembly to
compile your Java code against) -- I just did this to avoid addin
creators in my company having to know anything about IKVM. I also have
an ExcelAddIn interface in Java for any initialisation of the Java
stuff at runtime.
(2) Also i created a bunch of runtime converters for the types passsed/
received by Excel for function arguments and return values -- mostly
you need this if either your functions arg/return values are declared
(3) I create my addin code in Java using the same semantics that are
required when coding directly in VB.NET or C# in that only public
static methods can be used as addin functions.
(4) As I am stuck with pre 1.5 Java APIs for now I wrote a Java doclet
class to look at my Java source and create C# source code that wrapped
up my Java methods and added the runtime conversion calls. There are
also custom JavaDoc tags so I can pass through values to the
ExcelFunction and ExcelArgument attributes in the generated C# (for
instance AllowReference on ExcelArgumentAttribute, Category on
ExcelFunctionAttribute and so on).
(5) then you need to convert your JARs into .NET assemblies using the
IKVM ikvmc compiler.
(6) Compile up the generated C# referencing the converted JAR files.
(7) Thats it....
I will speak to people at my company to see if I am allowed to release
the generic stuff (converters, Java interfaces and so on) for open