Using OpenOffice API to convert Excel files

I am currently working on a Proof Of Concept around Java CAPS and its capacity to handle, parse and transform Swift messages.

Customer do receive fund subscription orders from their partners and customers in many different formats : XML, CSV and ... Excel files.

Excel files are always a bit tricky to handle when you're not developping nor deploying on Windows servers (if you are using Windows, then check out our DCOM Binding Components as it might be an elegant way to handle DCOM compliant objects from OpenESB - or - our DCOM OTD for the folks using Java CAPS repository-based projects)

The solution I choose to handle these files is quite simple : I am using the OpenOffice API to programmatically open the XLS file with OO and save it as a CSV text file ... just like you would do it by hand, using the OO GUI.

I attached a code sample to demonstrate this.  This is a complete NetBeans project.

For this sample to compile and execute, you will need a couple of OO jar files in your classpath (see the code sample for the exact list of required jars, they are all shipping with OpenOffice) and you will need to start OpenOffice in background mode, listening to network invocations from your client program (the exact command is given in the code sample).

This was tested on Mac OS X, with Apple's Java 6 and StarOffice 9 Beta. Enjoy !

The same technique can be applied to programmatically generates PDF files, without buying the expensive Distiller.  This will be the subject of my next blog entry.

As usual, your comments and feebacks are welcome.


Comments:

Using OpenOffice API to convert Excel files is brilliant!

Posted by gallbladder attack symptoms on décembre 20, 2009 at 09:47 PM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Sébastien Stormacq is a Senior Software Architect at Sun Microsystems. He uses his 15+ years of professional experience to design large scale, secured and highly transactional architectures based on Sun's middleware solutions.

Search

Archives
« avril 2014
lun.mar.mer.jeu.ven.sam.dim.
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today