Java 中有 OLE 自动化吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6679810/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 16:53:49  来源:igfitidea点击:

Is there OLE Automation in Java?

javaexceloleole-automation

提问by Shahab

Is it possible to use OLE Automation in Java? If not, why is it not possible in Java?

是否可以在 Java 中使用 OLE 自动化?如果没有,为什么在 Java 中不可能?

I'm looking to automate the exporting of excel spreadsheets in different format (ie, .csv etc...)

我希望自动导出不同格式的 Excel 电子表格(即 .csv 等...)

Thanks for the answers in advance :)

感谢您提前回答:)

采纳答案by Perception

You can use JACOB. But there will be some pain involved as it's not documented very well and the performance is not the best. It can also be hard to get it running correctly for you environment depending on which version of Windows you are targetting. I would definitely not use it if you are building a scalable web application. Another option would be Apache POIwhich has really come a long way from its early roots and is used in alot of production ready tools like JBoss Drools. If you decide to go with JACOB then I recommend you read this SO thread:

您可以使用JACOB。但是会有一些痛苦,因为它没有很好的记录并且性能不是最好的。根据您的目标 Windows 版本,它也很难在您的环境中正确运行。如果您正在构建可扩展的 Web 应用程序,我绝对不会使用它。另一种选择是Apache POI,它从它的早期根源已经走了很长一段路,并被用于许多生产就绪工具,如 JBoss Drools。如果你决定和 JACOB 一起去,那么我建议你阅读这个 SO 线程:

Is there a good reference for using OLE Automation (from Java)?

是否有使用 OLE 自动化(来自 Java)的好参考?

回答by allquixotic

Recently (March 2013), an independent contributor added support for generic COM Automation to JNA, which is the last man standing in terms of native platform API integration from Java. JNA is still very actively maintained, unlike Jawin/JACOB/etc.

最近(2013 年 3 月),一位独立贡献者向 JNA 添加了对通用 COM 自动化的支持,这是 Java 本地平台 API 集成方面的最后一个人。与 Jawin/JACOB/etc 不同,JNA 仍然非常积极地维护。

See herefor an example of how it is used. The pre-cooked bindings to the Office APIs are very simple so far, but looking at the code, it seems very easy to use the COM Automation APIs (IDispatch, Variant, etc) to do late binding to almost any COM interface.

有关如何使用它的示例,请参见此处。到目前为止,对 Office API 的预制绑定非常简单,但是从代码来看,使用 COM 自动化 API(IDispatch、Variant 等)对几乎所有 COM 接口进行后期绑定似乎非常容易。

I would like to see, however, a more complete binding of the Office COM APIs, since they are by far the most often used COM API in the world. Maybe there could also be an "MSExcel2007.java", "MSExcel2010.java", etc. to cover the different API versions. So it's very much a work in progress, but JNA is now as generally useful for COM Automation as JACOB/Jawin, with the bonus that it's extremely actively maintained (as of April 2013).

但是,我希望看到 Office COM API 的更完整绑定,因为它们是迄今为止世界上最常用的 COM API。也许还有“MSExcel2007.java”、“MSExcel2010.java”等来涵盖不同的 API 版本。所以这是一项正在进行的工作,但 JNA 现在对 COM 自动化和 JACOB/Jawin 一样普遍有用,而且它的维护非常积极(截至 2013 年 4 月)。

回答by Dan

There is a library called JACOBthat allows precisely what you're looking for. What do you mean by "from the Java API?" You mean from from the official J2SE packages? I'm not sure how to answer that other than to say that J2SE doesn't include libraries for every conceivable need under the sun, especially those that only work on a single operating system. That's why third party packages exist.

有一个名为JACOB的库,可以准确地满足您的需求。“来自Java API”是什么意思?你的意思是来自官方的 J2SE 包?我不知道如何回答这个问题,只能说 J2SE 不包含满足所有可能的需求的库,尤其是那些只能在单一操作系统上运行的库。这就是第三方软件包存在的原因。

回答by kervin

Commercial, but they seem to have a free Open-Source and Academic license...

商业,但他们似乎有一个免费的开源和学术许可证......

JExcel

精益求精

JExcel Developer Documents

JExcel 开发人员文档

I have no affiliation.

我没有隶属关系。