This is not, unfortunately, a blog dedicated to that great twelve volume series of novels by Anthony Powell. However, it is a form of record of my journey through the world of information technology; a journey motivated by both profit (it is intimately related to my profession) and inquisitiveness (I love to know how things work).
It is my intention, therefore to record. These records are primarily for my benefit, but may be useful to others as a side effect.

Saturday, January 23, 2010

OpenOffice 3.1.1 in a Java 6 Applet

There is a tantalising set of documents on the OpenOffice.org wiki about how you can use the officebean.jar which comes with all OpenOffice installations to display documents in an applet. The problem is, its out of date, and the link to the source is dead. But don't let that stop you...

Netbeans (I used 6.8 - get it here. You could use another IDE if you like)

The CodeFirstly I created a new Java Class Library project in Netbeans called OOoApplet. To this I added a single class which I called "OOoBeanViewer.java". I then (lazily) went looking for the example code. I found it on Koders.com here. I cut and pasted this into my OOoBeanViewer.java stub in Netbeans.

The DependenciesIn order for this to compile and run I had to add the following dependencies:

The EnvironmentBecause Open Office doesn't really run in the applet (rather we start it, and then redirect its display to the applet) we need so set things up so that the OOoBean knows where to look. This wa the hardest part as the assumption in the docs I could find was that this demo should just work. It didn't for me.

To get it to work I needed to add a Windows environment variable called UNO_PATH and set its value to be the path to the program directory of your OpenOffice install. I set mine to: "C:\Program Files\OpenOffice.org 3\program"

To get this to stick I then had to reboot. A check "echo %UNO_PATH%" at the command line showed that this had worked.

Running ItAll that was left was to compile and run. This was done simply using Netbeans. The result is a mostly empty Applet window with some buttons down the side. Fear not! You need to create a new document to see what you desire. This is what you get if you select "New Document ... > Text Document":

6 comments:

Hi, The links in your post are no longer valid. Could you please post some examples?

I am mostly interested in the code you mentioned here "I then (lazily) went looking for the example code. I found it on Koders.com here. I cut and pasted this into my OOoBeanViewer.java stub in Netbeans.". I can't find working example and would be really grateful if you could share the code, thanks.