What's the best/easiest way to manipulate Acti

2019-04-15 08:06发布

问题:

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?

回答1:

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


回答2:

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



回答3:

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.



回答4:

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



标签: java com activex