简体   繁体   中英

IKVM.NET & Excel VBA

I'm using IKVM.NET in order to convert a Java library (signally, Strata ) into a .NET library. Here are the steps I perform:

  1. I download the latest Strata release .
  2. I unzip all the JAR files contained into the lib folder of the archive to C:\\Strata\\ , including the following auxiliary libraries:
    • commons-math3-3.6.1.jar
    • guava-26.0-jre.jar
    • joda-beans-2.4.0.jar
    • joda-convert-2.2.0.jar
    • slf4j-api-1.7.25.jar
  3. I generate a keyfile for the library I want to create using the command sn -k "C:\\Strata\\Strata.snk" .
  4. Using the binary bytecode compiler of IKVM.NET , I convert the JAR files of Strata into a .NET library with the following command: ikvmc -out:"C:\\Strata\\Strata.dll" -keyfile:"C:\\Strata\\Strata.snk" -assembly:Strata -version:2.2.0 -fileversion:2.2.0 -target:library -platform:anycpu -recurse:"C:\\Strata\\*.jar" .

Once the process described above is done, even if a few warnings concerning missing classes are shown, I obtain a working .NET wrapper of Strata . If I create a new Visual Studio project referencing the Strata.dll assembly, I'm capable of using its classes and methods without problems.

What I would really love to achieve is to make the wrapper work in Excel VBA macros, so that I can instantiate and use Strata classes in the subs, according to the contents of the sheets.

This is what I tried so far, but to no avail:

  1. I register all the IKVM.NET libraries and the Strata wrapper into the GAC as follows: gacutil /i "C:\\IKVM\\IKVM.*.dll" , gacutil /i "C:\\Strata\\Strata.dll" .
  2. I register the Strata wrapper as COM component and I create its types library as follows: regasm /codebase /tlb "C:\\Strata\\Strata.dll" .

Now, when I open Excel and I go under Development > Visual Basic > Tools > References... I can see the TLB file of Strata (located at "C:\\Strata\\Strata.tlb") and I can add it to the current project. But as soon as I type something the window or I open the Objects Browser , Excel crashes without providing any meaningful information about what's going on.

I'm totally clueless about this issue.

Is my registration process correct? Do I have to register the IKVM.NET libraries too and create their type libraries? Should I include them into the Excel VBA project together with the Strata wrapper type libraries? Could the problem be caused by the fact that I'm using a x64 version of Excel and the wrapper has been compiled under AnyCPU ? Do I need to edit the wrapper by adding a ComVisible attribute on every public class? May this problem be due to the fact that the wrapper contains weird method names like “\\_Build01_\\p”?

Rather than use IKVM.NET you can use Java directly to build an Excel add-in.

To build an Excel add-in in Java instead of having to use .NET, see https://exceljava.com .

There is even a Strata-Excel project that you might be interested in that wraps the Strata library in an Excel add-in: https://github.com/exceljava/strata-excel

I think you should find this much more convenient than converting the Java libraries to .NET.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM