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.
我想用ActiveX打开和操作Excel文件。我在其他项目上使用Python的Win32 Extensions和Groovy的Scriptom库取得了成功,但如果可能的话,这次需要这样做才是纯Java。
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?
我已经尝试过雅各布Java COM桥,但这看起来并不简单或简单,我无法检索单元格值(即使这是基础Scriptom的库)。还有替代品吗?
4 个解决方案
#1
4
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...
雅各布真的是这里工作的工具。我建议你花时间学习一下COM和ActiveX的工作方式,我想你会发现它更容易使用。 COM是一项相当大的成就,但很难。像VB这样的包装使它看起来很容易(对于它们有用的有限用途),但它并不容易。我有一本关于学习COM的好书,但是现在没有名字好用的...
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.
您想了解IDispatch接口(这是大多数Excel的COM接口的开发)。这是一个令人讨厌的,令人讨厌的界面(你可以用它来做很多病毒式的事情之一,它无法分辨实际发生的事情) - 但学习它是关键。
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!).
如果您只在一个区域遇到问题(即从单元格中获取值),您可以获取Scriptom的源代码并查看它们的作用(毕竟是开源的!)。
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.
另一个建议是尝试在VBA中实现代码的一些测试用例,并确保正确思考所有返回值。当我们在我们的一个Java应用程序中进行Excel自动化时,我们从Word的VBA实现了通用算法,处理了问题案例等等......之后,转移到Jacob非常简单。
- K
#2
0
how about http://www.nevaobject.com/_docs/_java2com/java2com.htm -- this is commercial but works better.
http://www.nevaobject.com/_docs/_java2com/java2com.htm怎么样 - 这是商业化但效果更好。
#3
0
Have you looked at JExcelAPI? Instead of using ActiveX this is a Java library which directly reads and writes Excel files.
你看过JExcelAPI吗?这是一个直接读取和写入Excel文件的Java库,而不是使用ActiveX。
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.
不是您的问题的确切答案,但它也可以解决问题,特别是如果您正在寻找纯Java解决方案。
#4
0
There's also JIntegra, which does a similar thing. Also commercial. And there's JNIWrapper, which does a similar thing. again, also commercial.
还有JIntegra,它做了类似的事情。也是商业的。还有JNIWrapper,它做了类似的事情。再次,也是商业。
#1
4
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...
雅各布真的是这里工作的工具。我建议你花时间学习一下COM和ActiveX的工作方式,我想你会发现它更容易使用。 COM是一项相当大的成就,但很难。像VB这样的包装使它看起来很容易(对于它们有用的有限用途),但它并不容易。我有一本关于学习COM的好书,但是现在没有名字好用的...
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.
您想了解IDispatch接口(这是大多数Excel的COM接口的开发)。这是一个令人讨厌的,令人讨厌的界面(你可以用它来做很多病毒式的事情之一,它无法分辨实际发生的事情) - 但学习它是关键。
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!).
如果您只在一个区域遇到问题(即从单元格中获取值),您可以获取Scriptom的源代码并查看它们的作用(毕竟是开源的!)。
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.
另一个建议是尝试在VBA中实现代码的一些测试用例,并确保正确思考所有返回值。当我们在我们的一个Java应用程序中进行Excel自动化时,我们从Word的VBA实现了通用算法,处理了问题案例等等......之后,转移到Jacob非常简单。
- K
#2
0
how about http://www.nevaobject.com/_docs/_java2com/java2com.htm -- this is commercial but works better.
http://www.nevaobject.com/_docs/_java2com/java2com.htm怎么样 - 这是商业化但效果更好。
#3
0
Have you looked at JExcelAPI? Instead of using ActiveX this is a Java library which directly reads and writes Excel files.
你看过JExcelAPI吗?这是一个直接读取和写入Excel文件的Java库,而不是使用ActiveX。
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.
不是您的问题的确切答案,但它也可以解决问题,特别是如果您正在寻找纯Java解决方案。
#4
0
There's also JIntegra, which does a similar thing. Also commercial. And there's JNIWrapper, which does a similar thing. again, also commercial.
还有JIntegra,它做了类似的事情。也是商业的。还有JNIWrapper,它做了类似的事情。再次,也是商业。