tags:

views:

455

answers:

4

I want to open and manipulate Excel files with ActiveX. I've had success with Python's Win32 Extensions and Groovy's Scriptom libraries on other projects but need to do this is pure Java this time if possible.

I've tried the Jacob Java COM Bridge but that doesn't seem as straightforward or simple to use, and I couldn't get it to retrieve cell values (even though this is the library underlying Scriptom). Are there alternatives?

A: 

how about http://www.nevaobject.com/_docs/_java2com/java2com.htm -- this is commercial but works better.

anjanb
A: 

Have you looked at JExcelAPI? Instead of using ActiveX this is a Java library which directly reads and writes Excel files.

Not an exact answer to your questions but it might solve the problem just as well, especially if you're looking for a pure Java solution.

Leigh Caldwell
A: 

There's also JIntegra, which does a similar thing. Also commercial. And there's JNIWrapper, which does a similar thing. again, also commercial.

John Gardner
+2  A: 

Jacob is really the tool for the job here. I recommend that you take the time to learn a bit about how COM and ActiveX work, and I think you'll find that it's easier to use. COM is quite an accomplishment, but it's hard. Wrappers like VB make it seem easy (For the limited use that they work for), but it is not at all easy. I have a great book on learning COM, but don't have the name handy right now...

You want to learn about the IDispatch interface (this is what most of Excel's COM interface is developed around). It's a nasty, nasty interface (one of those viral things that you can do so much with it that it becomes impossible to tell what is actually happening) - but learning it is key.

If you are having issues in just one area (i.e. getting a value from a cell), you could grab the source for Scriptom and see what they do (open source, after all!).

Another suggestion is to try to implement some test cases of your code in VBA and make sure that you are correctly thinking through all the return values. When we were doing Excel automation in one of our Java apps, we implemented the general algorithm from Word's VBA, worked through the problem cases, etc... After that, transferring over to Jacob was pretty straightforward.

  • K
Kevin Day
I have used VB/VBA and yes it makes COM seem easy. Your advice is helpful, if you could add the book title when you find it, that'd be appreciated. What Java/COM library do you prefer?
Joe Skora