Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there OLE Automation in Java?

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

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

Thanks for the answers in advance :)

like image 717
Shahab Avatar asked Jul 13 '11 13:07

Shahab


2 Answers

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.

See here for 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.

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

like image 195
allquixotic Avatar answered Oct 16 '22 06:10

allquixotic


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 POI which 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:

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

like image 22
Perception Avatar answered Oct 16 '22 07:10

Perception