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)