开发者

Using IKVM-compiled Java .dll in VBA/Excel?

开发者 https://www.devze.com 2023-03-24 01:02 出处:网络
I am looking to be able to execute code from a Java project inside an Excel VBA sheet. Elsewhere on SO, I have discovered IKVM, which is a .NET implementation of Java which allows converting a .jar in

I am looking to be able to execute code from a Java project inside an Excel VBA sheet. Elsewhere on SO, I have discovered IKVM, which is a .NET implementation of Java which allows converting a .jar into a .dll. I was hoping this would let me access the classes/methods from the .jar inside the VBA editor, but I am having trouble doing so.

I have tried using the declare statement in VBA (in many different permutations, attempting to make it work) but the most common error refers to entry points in the .DLL.

I have also tried registering the .DLL as a reference in Excel, but it gives a boilerplate error and does not register it.

As a reference, I've been testing it using the following class before bothering to test it with the whole project:

public class IKVMTest {
    public static void print(Str开发者_开发知识库ing s) {
        System.out.println(s);
    }
}

This class is compiled by Eclipse and exported into IKVMTest.jar. At this point, I use ikvmc -target:library IKVMTest.jar to receive IKVMTest.dll. For simplicity's sake, this .dll and the Excel sheet I am testing in are dumped in the IKVM bin folder (since there are some dependencies on the IKVM .dll files).

If I could get it working for this sample test, I could get it working for the project overall.


Have you tried making your .NET assembly COM visible so you can use VBA to instantiate it?

using [ComVisible(true)] on the class and methods generated by the IKVM code might make it visible as a COM object to your VBA app.

Have a look here for reference: http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.comvisibleattribute.aspx#Y1600

Also, have a look here: How to call a .net assembly in VBA using COM Interop http://blogs.msdn.com/b/smondal/archive/2009/08/31/how-to-call-a-net-assembly-in-vba-using-com-interop.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消