Error while trying to open a Word document.

1,085 views
Skip to first unread message

Fatbob

unread,
Nov 15, 2011, 9:54:27 AM11/15/11
to ComfyJ Forum
Hi everyone!

My web service is trying to open a Word document and I get this
error...

COM object method returns error code: 0x80020009; DISP_E_EXCEPTION
(Exception occurred.)

The funny thing is that I have this web service running on another
server (same version of Word installed on both servers, Word 2010),
but on this one server I get that error.

Here is my code that tries to open the doc...

OleFunctions.oleInitialize();

_Application app = Application.create(ClsCtx.LOCAL_SERVER);
app.setVisible(new VariantBool(false));

_Document doc = null;

try
{
doc = app.getDocuments().add(new Variant(WORKING_FOLDER + fileName
+ ".doc"),
Variant.createUnspecifiedParameter(),
Variant.createUnspecifiedParameter(),
Variant.createUnspecifiedParameter());
} catch (Exception e) {
log.error("Unable to open DOC... " + WORKING_FOLDER + fileName +
".doc - (" + e.getMessage() + ")");
}

Any ideas as to what my be causing this?

Thanks!

Fatbob

unread,
Nov 15, 2011, 9:11:04 PM11/15/11
to ComfyJ Forum
I believe my problem might be related to the OS. IN my previous post I
forgot to mention that my web service is running on Windows Server
2008 R2 (JBoss 4.3). I tried my installed my web service on another
server which also happens to be a Windows Server 2008 R2 and guess
what... same error. Up until now, I've been running on Windows Server
2003 without any issues. So what can it be about 2008 that is causing
this error when trying to open a Word document?

Thanks!

Sergei Piletsky

unread,
Nov 16, 2011, 8:27:09 AM11/16/11
to Fatbob, ComfyJ Forum
Hi,

Thank you for contacting our support and providing us with the detailed information.

Well, the problem might be related to the OS, but we need to find out the cause of that DISP_E_EXCEPTION COM exception first. To get an exception error message you just need to catch the AutomationException, which is specially designed to handle such kind of COM exceptions, and get the its extended exception info, for example:

    try {
        // perform operation
    } catch (AutomationException e) {
        ExcepInfo info = e.getExceptionInformation();
        String description = info.getBstrDescription();
        System.err.println(description);
    }


This approach should give you an exception description directly form the Word application and hopefully it should explain why it happens.

It also can be important not to hide the Word application window (using the app.setVisible(new VariantBool(false)); method call), because I know that some methods cannot be invoked properly while a word window is invisible.

Please try these suggestions and let me know the results.

Sincerely,
Serge

Fatbob

unread,
Nov 16, 2011, 9:30:18 AM11/16/11
to ComfyJ Forum
Thanks for the reply Sergei.

So I tried what you suggested and here is what I got...

Word has encountered a problem.

Unfortunately not much to go on I'm afraid.

On Nov 16, 8:27 am, Sergei Piletsky <sergei.pilet...@teamdev.com>
wrote:

Fatbob

unread,
Nov 16, 2011, 9:32:07 AM11/16/11
to ComfyJ Forum
I also removed app.setVisible(new VariantBool(false)).

Fatbob

unread,
Nov 22, 2011, 1:08:34 PM11/22/11
to ComfyJ Forum
I found a solution and I figure I'd post the links in hopes that this
might help someone else in the future.

http://schprit.blogspot.com/2010/11/using-microsoft-office-2007-with-dcom.html

http://www.officefrustration.com/showthread.php?t=935543


On Nov 16, 8:27 am, Sergei Piletsky <sergei.pilet...@teamdev.com>
wrote:

Reply all
Reply to author
Forward
0 new messages