Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem to use Jacob (Java COM bridge) for Word automation

843829Feb 28 2008 — edited Mar 28 2008
I'm trying to use Jacob (Java COM bridge) in order to create a Word Document which corresponds to the reply of a mail (we fill some fields from a db ) and the main program is written in Java. Thus, we want to use COM objects in Java....
To achieve that, my settings are
- jacob 1.14
- jre1.5.0_06
- windows 2000 server sp4
- word 2000

no problem to compile and run the following basic sample, except the error due to method which gets the documents property from Word context (see below).
A lot of posts have already been created on several forums but after tested all those responses (change jre, change office....), no one hase efficiently solved my problem.
Help me, please!

The java class
import com.jacob.activeX.ActiveXComponent; 
import com.jacob.com.ComThread; 
import com.jacob.com.Dispatch; 
import com.jacob.com.Variant; 
import com.jacob.com.DispatchEvents; 
 
public class openDoc  
{ 
private ActiveXComponent wordApp = null; 
private String file = "c:\\temp\\TEST.doc"; 
public openDoc() 
{ 
// Open the word application conn object 
ActiveXComponent wordApp = new ActiveXComponent("Word.Application"); 
 
wordApp.setProperty("Visible", new Variant(true)); 
 
final Object wordDocuments = wordApp.getProperty("Documents").toDispatch(); 
 
// Open a document file that already exits 
Object document = Dispatch.call(wordDocuments, "Open",file).toDispatch(); 
 
} 
 
public static void main (String[] args) 
{ 
new openDoc(); 
} 
} 
the error which is thrown:

Exception in thread "main" com.jacob.com.ComFailException: A COM exception has been encountered:
At Invoke of: Documents
Description: An unknown COM error has occured.
at com.jacob.com.Dispatch.invokev(Native Method)
at com.jacob.activeX.ActiveXComponent.getProperty(ActiveXComponent.java)
at openDoc.<init>(openDoc.java:18)
at openDoc.main(openDoc.java:27)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 25 2008
Added on Feb 28 2008
2 comments
1,345 views