import msword.*; import ezjcom.*; public class OpenWriteSaveSample { public static void main( String[] args ) { _Application app = null; try { // Launch MS Word, // Open file C:\EZJWordSample1.doc, // Append some text to the file, // Save the file, // (leave MS word running) Application msword = new Application(); app = msword.get_Application(); app.setVisible( true ); // IMPORTANT: Otherwise you will not see the app Document doc = app.getDocuments().Open( new JComVariant( "C:\\EZJWordSample1.doc" )); // Open existing document // Go to the end of the document. int characterCount = doc.get_Document().getCharacters().getCount(); Selection sel = app.getSelection(); sel.MoveStart( new JComVariant( WdUnits.wdCharacter ), new JComVariant( characterCount+1 )); // Type some text at the end of the document sel.TypeText( "Modified at " ); _Font font = sel.getFont().get_Font(); WdColor oldColor = font.getColor(); font.setColor( WdColor.wdColorBlue ); sel.TypeText( new java.util.Date().toString()); font.setColor( oldColor ); sel.TypeText( "\r" ); // End of para // Save the document app.getActiveDocument().get_Document().Save(); // Leave MS Word running // app.Quit(); } catch (Exception ex) { if ( app != null ) try { app.Quit(); // Probably got here if the .doc file was not found } catch (Exception e) {} ex.printStackTrace(); } } }