Java Program to control Microsoft Word as slave

R

Ross

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?
 
R

Ross

Thinking slightly outside the box, this may be relevant:

http://openxmldeveloper.org/archive/category/1008.aspx

Thanks. I've got an article on writing .docx files from Java.

But the main problem I am thinking of would be to look into a
microsoft word document, and be aware of which pages certain elements
are found on. Without hard page breaks, I'm not sure that this
information can be found in the document itself. Hence the COM/OLE
solution.
 
A

Arne Vajhøj

Ross said:

Word is COM based.

There is only one way:

Java--(JNI)--some C/C++ code--(COM)--Word

The only question is whether that C/C++ code is something
you write or something you find.

I will strongly suggest that you find something. JNI and COM
are two complex API's to learn.

COM bridges exist for Java.
Only works in Java using third party tools, and only on windows.

Given that Word only runs on Windows, then that is not
really a restriction.

Arne
 
J

John B. Matthews

Arne Vajhøj said:
Ross wrote: [...]
Only works in Java using third party tools, and only on windows.

Given that Word only runs on Windows, then that is not
really a restriction.

Office Mac 2008 is reasonably interoperable with the Windows version:

<http://www.microsoft.com/mac/products/Office2008/default.mspx>

The Office applications include support for AppleScript & Open Scripting
Architecture:

<http://en.wikipedia.org/wiki/AppleScript#Open_Scripting_Architecture>
<http://www.microsoft.com/mac/developers/default.mspx>
 
A

Arne Vajhøj

John said:
Ross wrote: [...]
Only works in Java using third party tools, and only on windows.
Given that Word only runs on Windows, then that is not
really a restriction.

Office Mac 2008 is reasonably interoperable with the Windows version:

<http://www.microsoft.com/mac/products/Office2008/default.mspx>

The Office applications include support for AppleScript & Open Scripting
Architecture:

Ah. Then there could be a point in wanting a cross-platform
solution.

But unless there are a common wrapper for both COM and the Apple thingy,
then the original poster will probably have to code it himself.

Arne
 
L

Lew

Arne said:
John said:
Ross wrote: [...]
Only works in Java using third party tools, and only on windows.
Given that Word only runs on Windows, then that is not
really a restriction.

Office Mac 2008 is reasonably interoperable with the Windows version:

<http://www.microsoft.com/mac/products/Office2008/default.mspx>

The Office applications include support for AppleScript & Open
Scripting Architecture:

Ah. Then there could be a point in wanting a cross-platform
solution.

But unless there are a common wrapper for both COM and the Apple thingy,
then the original poster will probably have to code it himself.

Or one could use OpenOffice, which has a Java API and understand the .doc
format. It also runs on Linux.
 
C

ck

Or one could use OpenOffice, which has a Java API and understand the .doc
format.  It also runs on Linux.

Brilliant, change client requirements and expectation for ease of
development.
 
A

Andy Dingley

Hi. I believe that it's possible to write programs that control a
running version of Microsoft Word as a slave.

Yes. We've been doing it via COM (the sensible approach) using the
Jacob Java library to access COM File formats were rtf (Word's happy
with that) and we were then using Novosoft's rtf2fo to turn this into
XSL:FO then Apache FOP to PDF.

OTOH, we've also killed this off completely now, in favour of editing
HTML rather than RTF and using TinyMCE as a web-app-embeddable rich-
text editor. Word disappears, so we can run on non-Windows desktops
and there's no need to buy Office.
 
R

Ross

Too many posts to respond to directly.

Learning complex interfaces is not something I'm too worried about. If
there's a real need, I feel confident that I'd be up and running
quickly enough. After the normal thrashing about. But, I wouldn't
write a .COM bridge if there are suitable ones already available. No
point.

Using OpenOffice would be an acceptable solution if I could be sure
that OpenOffice would put page breaks in the same location as
microsoft word for the same .doc document. In fact, I think it might
be a better solution. Maybe I need to go off and ask questions on an
openoffice forum.

Microsoft Word (depending on version) can run on Linux under some
variants of wine. E.g. Crossover Office and Word 2007.

For my particular application, I was thinking that IF I go this route,
I would have my main application communicating with an external
application (still in Java) that communicates with Word. The main
application would still work standalone, communication with word would
be an option. The "external application" could be platform dependent.
 
L

Lew

ck said:
With if's [sic] and but's [sic] involved. I am sorry to say,
Microsoft != Open office.[sic]

Microsft != Word, also.

But specious comments aside, OpenOffice is superior to Word.
 
R

Roedy Green

Thinking slightly outside the box, this may be relevant:

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.
--
Roedy Green Canadian Mind Products
http://mindprod.com

I advocate that super programmers who can juggle vastly more complex balls than average guys can, should be banned, by management, from dragging the average crowd into system complexity zones where the whole team will start to drown.
~ Jan V.
 
R

Roedy Green

Brilliant, change client requirements and expectation for ease of
development.
--

One of the rules of brainstorming is you don't throw wet blankets on
any suggestions. It stifles the flow of imagination. You do that
later after a wide assortment of ideas has been generated.

Consider also that these discussions are not intended for just the
O.P. They are for people who may have similar problems later, or for
people reading the thread years later, whose requirements are not
identical to O.P.s.

My back goes up when a poster starts treating fellow posters as
employees whose duty is to serve him in the manner he most prefers.
I see it more that O.P. simply seeded a discussion by tossing out an
interesting question.

The most elegant solutions to problems often come when you change your
requirements slightly because something that you thought was fixed,
was not quite so unmovable.

Analogously, I discovered the key to writing very fast assembler code
was to set up every loop is an often peculiar way, but that was highly
convenient for the loop body. You have to change your notions of what
the initial conditions are. You write the code from the inside out.

It is one thing to say that at given idea will not apply in this case,
but quite another to chastise someone for presenting it. Lew was
completely in bounds with his suggestion.
--
Roedy Green Canadian Mind Products
http://mindprod.com

I advocate that super programmers who can juggle vastly more complex balls than average guys can, should be banned, by management, from dragging the average crowd into system complexity zones where the whole team will start to drown.
~ Jan V.
 
L

Lew

ck wrote, quoted or indirectly quoted someone who said :
Roedy Green said:
It is one thing to say that at given idea will not apply in this case,
but quite another to chastise someone for presenting it. Lew was
completely in bounds with his suggestion.

On the up side, he did accurately describe my suggestion as brilliant.
 
A

Arne Vajhøj

Lew said:
Arne said:
John said:
[...]
Only works in Java using third party tools, and only on windows.
Given that Word only runs on Windows, then that is not
really a restriction.

Office Mac 2008 is reasonably interoperable with the Windows version:

<http://www.microsoft.com/mac/products/Office2008/default.mspx>

The Office applications include support for AppleScript & Open
Scripting Architecture:

Ah. Then there could be a point in wanting a cross-platform
solution.

But unless there are a common wrapper for both COM and the Apple thingy,
then the original poster will probably have to code it himself.

Or one could use OpenOffice, which has a Java API and understand the
.doc format. It also runs on Linux.

It is very unlikely that the original posters customers will
want to change from MSO to OOo just to solve his problem.

If OOo is easy to embed in a Java app, then it it could work. But
I have never heard about that. And given that OOo contains a lot
of OS specific code, then I would expect it to be difficult
to achieve.

Arne
 
A

Arne Vajhøj

M

Mayeul

Lew said:
Arne said:
John said:
[...]
Only works in Java using third party tools, and only on windows.
Given that Word only runs on Windows, then that is not
really a restriction.

Office Mac 2008 is reasonably interoperable with the Windows version:

<http://www.microsoft.com/mac/products/Office2008/default.mspx>

The Office applications include support for AppleScript & Open
Scripting Architecture:

Ah. Then there could be a point in wanting a cross-platform
solution.

But unless there are a common wrapper for both COM and the Apple thingy,
then the original poster will probably have to code it himself.

Or one could use OpenOffice, which has a Java API and understand the
.doc format. It also runs on Linux.

I wouldn't rely on OpenOffice.org to preserve exactly Word's pagination,
though.

Actually, I wouldn't even rely on Word to preserve exactly Word's
pagination, so maybe no exact solution exist and relying on
OpenOffice.org is as correct as one can be. I'd just think the error
rate would be lower with a chosen version of Word, configuration, and
set of installed fonts.
 

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

Forum statistics

Threads
473,780
Messages
2,569,609
Members
45,253
Latest member
BlytheFant

Latest Threads

Top