Java Program to control Microsoft Word as slave

D

Dev

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?

Best Java API to manipulate MS Word docs is iText search for API in
google.

all the best
Dev
 
C

ck

Thinking even further out the box, convert your docs to
OpenOffice/Star Office.

Then the odt files have a simple well-documented format.
You have to unzip them first.http://mindprod.com/jgloss/openoffice.html

You might then use OpenOffice to convert them back.

This might work for most of the cases, although two points to note -
- Document compatibility - In some cases OpenOffice does not show/
render documents created in Microsoft word as intended, leading to
incompatibility. Would OpenOffice API resolve it?
- In case OpenOffice API does not resolve it, problem would grow as
the complexity of documents (documents created in Microsoft word)
increases.
 
M

Mayeul

ck said:
This might work for most of the cases, although two points to note -
- Document compatibility - In some cases OpenOffice does not show/
render documents created in Microsoft word as intended, leading to
incompatibility. Would OpenOffice API resolve it?
- In case OpenOffice API does not resolve it, problem would grow as
the complexity of documents (documents created in Microsoft word)
increases.

Doesn't the same go if using Word itself instead of OpenOffice.org API?
 
K

Ken

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

Arne Vajhøj

Ken said:
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...

Will it work without having OOo installed on the computer but just
having some parts distributed with the Java app?

Arne
 
P

Pitch

Thank you. I didn't intend to be though.

Glad you didn't take it personally. :)

However, I'd really like to hear from you about howcome a MSWord
application would differently paginate an MSW-document from the same or
a lesser version?? (pardon my English)
 
L

Lew

Pitch said:
However, I'd really like to hear from you about howcome a MSWord
application would differently paginate an MSW-document from the same or
a lesser version?? (pardon my English)

I don't know why it happens, but I've seen it happen.

Maybe it changed its mind about font metrics.

It's one of those Word mysteries, like why it asks you if you want to save
your "changes" to a document that you have not changed, which Word does to me
more often than not.

Word is my favorite Microsoft product after SQL Server, but it has quirks.
 
J

Jukka Lahtinen

Lew said:
It's one of those Word mysteries, like why it asks you if you want to save
your "changes" to a document that you have not changed, which Word does to
me more often than not.

It seems to ask it every time after you have printed the document.
There may be other actions that always make word to believe it should save
something, but printing is at least one of them.
 
L

Lew

Jukka said:
It seems to ask it every time after you have printed the document.
There may be other actions that always make word to believe it should save
something, but printing is at least one of them.

That's a "when", not a "why".
 
P

Pitch

I don't know why it happens, but I've seen it happen.

Maybe it changed its mind about font metrics.

Well, if something is changed (system fonts, printer, page size...) then
is ok to repaginate the document. I see it as a feature, not a problem.

OP should have this in mind when opening Word documents.
 
L

Lew

Pitch said:
Well, if something is changed (system fonts, printer, page size...) then
is ok to repaginate the document. I see it as a feature, not a problem.

OP should have this in mind when opening Word documents.

My speculation wasn't that the fonts changed.
 
K

Ken

Will it work without having OOo installed on the computer but just
having some parts distributed with the Java app?

Arne

AFAIK, you will still need a stand alone install of OOo. It is
difficult and not recommended to trim down the OOo install by removing
applications. There are a lot of interdependencies and there will be
feature loss... so yes you can trim down the feature set if you know
what you are doing. I would love it if I could just package what I
wanted but once again UNO and OpenOffice can act as a server so you
don't need it on the actual machine (although I don't know about
performance issues) you could just use it remotely it is hardly any
more complicated that using it locally.

Being FOSS anything is possible but being far from a small project,
well you know it won't be easy.

I think UNO is a really neat technology and would love to see it grow
beyond OOo. UNO does have reflection. So with the reflection support
built into a Java IDE like Netbeans, the IDE could automatically
generate interfaces for the required objects. No crazy casting like
is currently needed and no need for a pre-existing group of interfaces
to exist. Also I would find it really nice, if I could easily create
my own UNO services in my own programs (ask the IDE to create a
service based on the interface of the class and report errors where
java can do something the UNO specification can not). I am a huge fan
of FOSS and feel the real power is in combining existing tools. A
trivially easy to use IPC tool which allows us to make our programs
easily consumable by other languages I think would be a great start at
realizing that potential. Further I think a Java IDE is the perfect
place for this technology.

Imagine if VLC and your favorite audio player exposed their interfaces
with UNO. You could do all kinds of wonderful stuff. No one needs to
jump on a retarded marketing band wagon and stick a ".net" on the name
of every programming language, you just need a binding. Okay clearly I
love the idea, sorry if I went over zealous. Oh hell, I take that
back people should start waving UNO flags with me. (btw there is a
mono binding, so it will not be like the two technologies will be on
different islands just ours will be better because some Monolithic
organization isn't going to roll over and crush the standards).

If anyone wants to know more about UNO:
http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/OpenOffice.org_Developers_Guide
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top