Hi,
I tried to use the example on GitHub for MS-Word COM-automation:
https://github.com/twall/jna/blob/master/contrib/msoffice/src/com/sun/jna/platform/win32/COM/office/MSOfficeDemo.javaThe first thing I noticed that these examples use classes which are not in the current version 4.0.0 (jar).
The example uses the 'com.sun.jna.platform.win32.COM.COMLateBindingObject'. Therefore I had to download the
sources and create my own jna-platform.jar.
After that, the example seems to work. Word started and could be set to visible. Then it was
possible to open a document, add text, close the document, hide the window and quit the application.
But one thing couldn't be done: Save the document to another file name or to another file format.
In both cases, there occur an exception: com.sun.jna.platform.win32.COM.COMException: Falscher Variablentyp.
(engl.: Wrong Variable Type).
I didn't alter the example-file. Seems that either the example is wrong implemented or JNA-implementation of COM has
a bug. I marked the line form the Example, where the exception occurs.
. . . . .
try {
msWord = new MSWord();
System.out.println("MSWord version: " + msWord.getVersion());
msWord.setVisible(true);
// msWord.newDocument();
msWord.openDocument(currentWorkingDir + "jnatest.doc", true);
msWord.insertText("Hello from JNA!");
// wait 10sec. before closing
Thread.currentThread().sleep(10000);
// save in different formats
// pdf format is only supported in MSWord 2007 and above
// msWord.SaveAs("C:\\TEMP\\jnatestSaveAs.pdf", wdFormatPDF);
msWord.SaveAs("C:\\TEMP\\jnatestSaveAs.rtf", wdFormatRTF); // EXCEPTION!
msWord.SaveAs("C:\\TEMP\\jnatestSaveAs.html", wdFormatHTML); // EXCEPTION!
// close and save the document
}
. . . . .
Does anybody had the same problem and found a solution for that. I read in the frequently asked questions
that the COM-implementation in JNA is not well tests and they recomment to use com4j or JACOB. Don't
know if you can trust the implementation in JNA.
Thanks for help.
Best regards
Andi