Hi. I believe that it's possible to write programs that control a
running version of Microsoft Word as a slave. Requesting it to load
documents, save documents, read and write content.
1. Is this true?
2. Is it possible to do this from java?
3. How do you do it?
Some others here have recommended OpenOffice.org (OOo). I have some
experience using OOo with Java and thought I would share it with you.
OOo opens word documents with a high degree of success. It is very
easy to start OOo is "headless" mode. In this way OOo is just a
detail of your implementation, your clients don't have to give up Word
and it isn't like disk space is a big issues these days.
Programs which make use of OOo will work across a range of platforms
without any modifications. Further OOo can be controlled by a fair
number of Programming languages there are bindings for (off the top of
my head): Java, C++, Python, VB and JavaScript and perhaps others.
This feat is accomplished though UNO (universal network objects) a
technology similar to COM (to Microsoft people), D-BUS (to Linux
people), COBRA and others that have tried to solve the same issue.
OOo acts as a server waiting for requests for UNO objects (a language
independent abstraction). Because of the abstraction, code written in
one language looks a lot like code written in another language (so
examples from other languages can still be of use to you as the same
thinking).
So if you are thinking about it like I was then you'll think: Wow I
can control almost every facet of OOo in a platform independant way
even using OOo over a network (Microsoft licenses are why this isn't
easily possible with Office) and not need to worry about licenses! Now
for the down side...
Many programmers are used to working with Java API's... however
because you are dealing with a remote system it passes back references
of type Object you then must cast them to the correct local type
before you can use them. Each OOo UNO object is capable of producing
many different other UNO Objects... So you need to cast at almost
every step which makes a lot of overhead further if you often use an
IDE is is frustrating not to be able to use any type of auto complete
or even use JavaDoc you need to look at documentation that is platform
independent. You know what object you need and you have an object
which you're certain can get you there but working though the
interfaces can feel like navigating a maze sometimes.
Setting up the project can be challenging too. A good place to start
is to download the OpenOffice SDK, OpenOffice, Netbeans 6.5 (later
versions such as 6.7 do not have the plug in available yet to create
an OOo project easily). Then install the OOo plugin into Netbeans 6.5
(it is only a few clicks under the available plugins) and create a OOo
project (it will provide the code needed to connect to a running
instance of OOo). Finally the SDK has numerous Java examples so you
simply copy one of them and you have an interesting running program.
Take what you have learned about dependencies from this exercise and
apply them to your IDE of choice (or text editor).
To get around this casting/documentation issue there is a software
company out there that has formed a framework with the OOo UNO Objects
implemented in Java which I am certain would make programming for
OpenOffice a pleasure. There is a price tag for this service. Then
there is a source forge project out to do the same thing but I don't
know how far along they are.
Finally I am going to speak heresy on a Java forum and say that
without proper tools Java and UNO is a big pain. It is much easier to
use a language without type safety. I know this is counter intuitive
for many but unless you've actually tried doing UNO with Java and then
with JavaScript, Python or VB you can not appreciate the change. So
if you want to write the majority of your program in Java, Python (or
Jython) is probably the path of least resistance (I would even believe
this to be true if you have no experience with Python what so ever, as
was the case for myself).
A simple Google search will turn up the OpenOffice.org Developers
Guide. What ever path you decide on good luck. You will also find
further support from: The OpenOffice.org forum.