1

Not easy to summarize the problem in a single sentence ...

I have an web app running on tomcat 7, with Java 6. The app accesses Excel sheets using JACOB, which uses JNI and COM, starting an separate Excel process. To ensure, the Excel sheet is mutable, my Java process creates a copy of the original XLS using File.createTempFile() and passes the temp file to the Excel process.

OS is Windows Server 2008. Excel version is from Office 2010.

My Problem: Everything works fine as long as Tomcat is started interactively from command line or frm the IDE. If I start Tomcat as service (with default user SYSTEM), Excel fails to open the temp file saying:

com.jacob.com.ComFailException: Invoke of: Open
Source: Microsoft Excel
Description: Microsoft Excel kann auf die Datei 'C:\Program Files\apache-tomcat\temp\Entwickl-Auftr-Bez-n-Maß 54-131 215-2 Optimierung 210-0    210-3.xlsx6119727457676255726.clone' nicht zugreifen. Dies kann mehrere Gründe haben:

• Der Name des Dokuments oder der Pfad ist nicht vorhanden.
• Das Dokument wird von einem anderen Programm verwendet.
• Der Name der Arbeitsmappe, die gespeichert werden soll, ist identisch zu dem Namen eines  anderen Dokuments, welches schreibgeschützt ist.

    com.jacob.com.Dispatch.invokev(Native Method)
    com.jacob.com.Dispatch.invokev(Unknown Source)
    com.jacob.com.Dispatch.callN(Unknown Source)
    com.jacob.com.Dispatch.call(Unknown Source)
    de.insites.ms.com.xls.Workbook.<init>(Unknown Source)
    de.insites.ms.com.xls.Excel.openWorkbook(Unknown Source)
    de.harti.harticalc.excel.MahanoExcel.<init>(Unknown Source)
    de.harti.harticalc.excel.MahanoExcel.create(Unknown Source)    
    de.harti.harticalc.excel.ExcelProcessor.getExcel(Unknown Source)
    de.harti.harticalc.excel.ExcelProcessor.calculatePosition(Unknown Source)
    de.harti.mahano.service.PositionServlet.doGet(Unknown Source)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    de.harti.mahano.service.AbstractMahanoWsServlet.service(Unknown Source)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    de.harti.mahano.service.CharsetFilter.doFilter(Unknown Source)

The german message means that Excel can't access the file because the file does not exist, is locked by another process or is somehow write locked.

I verified the file exists and it's a readable Excel document (I can open it using Excel interactively).

My guess is, that Windows denies the access of the EXCEL sub process to my file, because it's created by the java process which it doesn't trust.

How can I give Excel access to the file when Tomcat is running as windows service?

EDIT: English version of the Exception message

ERROR - Invoke of: Open
Source: Microsoft Office Excel
Description: Microsoft Office Excel cannot access the file 'c:\marchena\marchena10\work\marchena\batch_58288\input\content_1.xlsx'. There are several possible reasons:

    ? The file name or path does not exist.
    ? The file is being used by another program.
    ? The workbook you are trying to save has the same name as a currently open workbook.

SOLUTION Found the solution here link. I had to create the folder

    C:\Windows\SysWOW64\config\systemprofile\Desktop

manualy. Seems on Windows Server 2008, Excel needs this folder when running as SYSTEM but does not create if missing.

Thanks for your hints.

Nordmeyer
  • 541
  • 5
  • 15
  • It's usually recommended that you don't run Excel from a non-interactive service. There's an old Microsoft KB about it. Can you use a library, e.g. [Apache POI](http://poi.apache.org/) instead? – Rup May 24 '13 at 08:54
  • [KB 257757](http://support.microsoft.com/kb/257757): "Although such programmatic development can be implemented on a client system with relative ease, a number of complications can occur if Automation takes place from server-side code such as ... a Windows NT service." – Rup May 24 '13 at 09:04
  • This being an english-speaking site, I recommend you posting the exceptions in english and not in german. – m0skit0 May 24 '13 at 09:07
  • @Rup yes, sorry, didn't read that, I must be blind. – m0skit0 May 24 '13 at 16:13
  • Thanks for your hints. I expected problems and solved most of them. Hopefully this one too. I already implementde some POI apps, but in this case, POI is insufficent. My customer has some deeper Excel knowlede which makes him able to implement some minor busness logic in Excel himself. My app just uses his sheets for calculations. The app already runs since 2010 using Open Office's UNO bridge. Unfortunately, there are some minor but nasty compatibilty problems between Excel and Calc which brought us to the decission to migrate the app. – Nordmeyer May 27 '13 at 10:25
  • Thanks for the update! It's best to also post that as an answer to your question below so we know it's solved. – Rup May 28 '13 at 14:41

1 Answers1

2

Found the solution here link. I had to create the folder

C:\Windows\SysWOW64\config\systemprofile\Desktop

manualy. Seems on Windows Server 2008, Excel needs this folder when running as SYSTEM but does not create it if missing.

Thanks for your hints.

Nordmeyer
  • 541
  • 5
  • 15