在Java中操纵ActiveX对象的最好/最简单的方法是什么? [英] What's the best/easiest way to manipulate ActiveX objects in Java?

查看:121
本文介绍了在Java中操纵ActiveX对象的最好/最简单的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用ActiveX打开和操作Excel文件。我已经成功使用Python的 Win32扩展和Groovy的 Scriptom 库在其他项目,但需要这样做是纯Java这一次,如果可能的话。

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.

我尝试过 Jacob Java COM Bridge 但这似乎不直接或简单的使用,我不能得到它检索单元格值(即使这是Scriptom的基础库)。是否有替代方案?

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?

推荐答案

Jacob确实是这里工作的工具。我建议你花时间来了解一下COM和ActiveX是如何工作的,我想你会发现它更容易使用。 COM是一个相当成就,但它是。包装器像VB使它看起来很容易(为他们工作的有限的使用),但它不是很容易。我有一本关于学习COM的好书,但是现在没有方便的名字...

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...

你想了解IDispatch接口(这是最的Excel的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.

如果你只在一个区域有问题(即从一个单元格中获取值),你可以抓住Scriptom的源代码,看看他们做了什么(开源,毕竟!)。

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!).

另一个建议是尝试在VBA中实现你的代码的一些测试用例,并确保你正确地思考所有的返回值。当我们在我们的一个Java应用程序中执行Excel自动化时,我们从Word的VBA中实现了通用算法,处理了问题情况等。然后,转移到Jacob非常简单。

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

这篇关于在Java中操纵ActiveX对象的最好/最简单的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆