Problem with COM Excel communication

Help
Den
2010-08-27
2014-01-21
  • Den
    Den
    2010-08-27

    I am using jacob.jar (version: 1.7 from danadler.com/jacob) to establish the communication of a JAVA application with Excel. This works fine with MS Windows Server 2000 and MS Excel 2000.

    Now  I have to deploy this JAVA application on MS Windows Server 2008. But unfortunately the COM communication doesn't work anymore. The system throws the following exception when it tries to open the excel workbook.

    Error message:
    "Source: Microsoft Excel
    Description: Unable to get the Open property of the Workbooks class"

    Here some informations about the environments:
    - Webapplication JSP (JAVA 1.4)
    - jacob.jar/jacob.dll 1.7
    - Server: MS Windows Server 2008
    - MS Excel 2000

    Here is the code snippet, where the error occurs. It occurs at line

    workbook = Dispatch.call((Dispatch)workbooks,"Open",excelSheet).toDispatch();

            try 
            {
                xl.setProperty("Visible", new Variant(true));
                Object workbooks = xl.getProperty("Workbooks").toDispatch();
                workbook = Dispatch.call((Dispatch)workbooks,"Open",excelSheet).toDispatch();
                sheet = Dispatch.get((Dispatch)workbook,"ActiveSheet").toDispatch();
            }
    

    Thank you very much for any helps.

    Den

     
  • pauloaguia
    pauloaguia
    2010-09-29

    I'm facing this exact same problem: I have a system that opens an Excel workbook and was working fine until I migrated it to Win2008.

    Some facts I've figured out on my own:
    * My application usually executes as user System (it is started from a service). If the whole system is executed as a regular user, it works fine, no error
    * If I go to Administrative Tools -> Component Services -> DCOM Config and set Microsoft Excel Application's Identity to execute as a specific user, Jacob does not cause this error. However Excel occupies 100% CPU and I have problems starting it as a regular application, from the Start menu.
    * Before this call a call to the Visible property succeeds perfectly… although setting a property and getting a return from a method are quite different operations so this may not mean anything…

    Seems to me like there are some security issues involved here, related to the fact that this is not an Interactive user account; but can't quite figure them out on my own…

    I was using Jacob 1.9 but have tried also with the latest version and the error still occurs…

     
  • pauloaguia
    pauloaguia
    2010-09-29

    (forgot to add I'm using Excel 2003)

    I've debugged the application up to the point where it calls the native method invokev(Dispatch dispatchTarget, String name, int dispID, int lcid, int wFlags, Variant vArg, int uArgErr);

    As far as I can tell everything seems fine - the variable I have for the workbooks collection seems to be instantiated and valid (not that I understand much about it hough).
    I took a look at the C++ code but can't really see anything meaningful… seems like I'll need to debug it to find out more. Is there anyone who can point me out how to work it out to debug the C++ part of Jacob?

     
  • pauloaguia
    pauloaguia
    2010-09-30

    Ok, I found the answer…
    I didn't get to debug the JNI code (shame on me) but decided to spend some more time looking for the problem online. And the answer turned out to be quite obnoxious:

    create the folder  C:\Windows\SysWOW64\config\systemprofile\Desktop (Win2008 x64)
    or the folder C:\Windows\System32\config\systemprofile\Desktop (Win 2008 x86)

    Apparently, when opening a file Office tries to read something from the Desktop of the current user. So, since I'm running as a service, under the SYSTEM account, the systemprofile needs a Desktop folder (Head -> Desk)

    Eventually other automatic or server side tasks may need this Desktop folder under a different profile folder…

     
  • Den
    Den
    2010-10-05

    Hi Paulo,

    many thanks for your support.

    Your advice to set a specific user in DCOM Config has obviously solved my problem. I have changed the identity of the user from "The launching user" to "The interactive User".  Voila, the communication with Excel works again.

    CU
    Vu Dang

     
  • Thanks for the post.
    I had a similar issue when installing an application (under local system account) using Jacob 1.14 to start MS Word in Windows Server 2008 R2 (64 Bit).
    The CPU usage went up 100% and Word never returned.

    Creating the Desktop folder here resolved the issue:
    C:\Windows\SysWOW64\config\systemprofile\Desktop

    Many thanks again for posting this answer.

    Best regards,
    Josef

     
    • we have the same issue with Windows Server 2012 and this fix does not work . Does anyone know if Jacob is compatible with windows server 2012 ?