The information in this article applies to:
The Jword8.exe sample illustrates how to automate Microsoft® Word 97 version 8.0 (MS Word) from a Java application. This sample shows how to invoke Word 97, make it visible, and open up an existing Word document. It also PrintPreviews the document and Prints it. It uses the Open, PrintPreview, and PrintOut methods of MS Word 97.
The following file is available for download from the Microsoft Software Library:
Jword8.exe
http://support.microsoft.com/download/support/mslfiles/Jword8.exe .
After downloading the Jword8.exe file, extract the files into a new directory and ensure the files are named as seen in the Project Files in Jword8.exe section below.
This sample illustrates how to call a COM object like Word 97 from Java. It shows how you can invoke MS Word, make it visible, and open an existing MS Word document. It also PrintPreviews and Prints the document. It makes use of methods like Open, PrintPreview, and PrintOut, and properties like putVisible (or setVisible) of the MS Word Type Library.
import msword8.*;
Copy this line of text and insert it into the beginning of any Java source file that uses the COM component. This has been done for you in this sample (see line 9 in JWord8.java). In the summary.txt line, you will note that there are no methods listed for any of the classes. Recall that when you call COM from Java, you use the class file to create the COM component, but you must use the interface file to access the COM component. Double-click the Summary.txt line to view that file in Microsoft® Developer Studio®.
// appWord.putVisible(true); appWord.setVisible(true);
COM components can get access to any system resources. As such, they are both very powerful and potentially very dangerous. In the Microsoft VM in Microsoft® Internet Explorer 3.x and higher, only trusted class files can use COM components. Class files from digitally signed .cab files are trusted.
If the HTML file is run from Microsoft Developer Studio, the class files are also trusted. This can be very helpful during applet development. However, to deliver your applet to other users, you must put it in a signed .cab file.
When it is run as an application, the class file must already be on your machine.
When it is run as an applet, the class file may be downloaded to your machine.
There is a potential security threat running downloaded software. To run a Java applet that uses COM components, the applet code must be trusted. For more information on trusted class files, see the Knowledge Base Article, HOWTO: Make Your Java Code Trusted in Internet Explorer.
You can download the SDK for Java 2.0x at the following Web site:
For the latest Knowledge Base articles and other support information on VisualJ++ and the SDK for Java, please see the following pages on the Microsoft Technical Support site:
http://support.microsoft.com/support/visualj/
http://support.microsoft.com/support/java/