import msword.*; import ezjcom.*; public class WriteSaveSample { public static void main( String[] args ) { try { // Launch MS Word, // write some text, // save in C:\EZJWordSample1.doc, // and exit MS Word Application msword = new Application(); _Application app = msword.get_Application(); app.setVisible( true ); // IMPORTANT: Otherwise you will not see the app app.getDocuments().Add(); // Add a new document object // Type some text in the document Selection sel = app.getSelection(); sel.TypeText( "Here is some sample text.\r\r" ); sel.TypeText( "Open Timestamp: " ); _Font font = sel.getFont().get_Font(); WdColor oldColor = font.getColor(); font.setColor( WdColor.wdColorRed ); sel.InsertDateTime( new JComVariant( "MM/dd/yyyy hh:mm" )); font.setColor( oldColor ); sel.TypeText( "\r" ); // End of para // Save the document app.getActiveDocument().get_Document().SaveAs( new JComVariant( "C:\\EZJWordSample1.doc" )); // Exit MS Word app.Quit(); } catch (Exception ex) { ex.printStackTrace(); } } }