Office 2007 cannot open files when called through JACOB from a service

I use JACOB to make COM calls for PowerPoint and other Office applications with Java. In a separate Windows 7 window, I get the following message quite often, but not always:

Source: Microsoft Office PowerPoint 2007 Description: PowerPoint could not open the file. 

From excel, I get:

 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. 

Word Error:

 VariantChangeType failed 

The following is what I run, the error comes from the last line.

  ComThread.InitSTA(); slideApp = new ActiveXComponent("PowerPoint.Application"); Dispatch presentations = slideApp.getProperty("Presentations").toDispatch(); Dispatch presentation = Dispatch.call(presentations, "Open", inputFile.getAbsolutePath(), MsoTriState.msoTrue.getInteger(), // ReadOnly MsoTriState.msoFalse.getInteger(), // Untitled The Untitled parameter is used to create a copy of the presentation. MsoTriState.msoFalse.getInteger() // WithWindow ).toDispatch(); 

I tried to set a breakpoint just before making an open call, and there is a file, and I can open it using PowerPoint in the GUI, but when I take a step, this is an exception.

The unfortunate thing about this problem is that it seems to always start from the very beginning, but after it scrambled for a while (repeating the same code), it ultimately succeeds, and after that never repeated.

Further research I found that this only happens with .ppt, .doc and .xls files, not .pptx, .docx and .xlsx. And as far as I can tell, this is not related to the file system (I changed the mechanism that copies the files and tries to put the files in another file system).

I just noticed that this only happens when the Java application is running as a service, and not when I run catalina.bat start from the command line.

+6
java ms-office powerpoint com jacob
source share
2 answers

Does this work for you?

 import com.jacob.activeX.ActiveXComponent; import com.jacob.com.ComThread; import com.jacob.com.Dispatch; import com.jacob.com.Variant; public class PPT { private static final String inputFile = "c:\\learning.ppt"; public static void main(String[] args) { ActiveXComponent slideApp = new ActiveXComponent("PowerPoint.Application"); slideApp.setProperty("Visible", new Variant(true)); ActiveXComponent presentations = slideApp.getPropertyAsComponent("Presentations"); ActiveXComponent presentation = presentations.invokeGetComponent("Open",new Variant(inputFile), new Variant(true)); ComThread.Release(); } } 

Update: If this works with the client, and it is just an automation causing problems, you can look at http://support.microsoft.com/kb/257757 to see possible problems. The error codes are clearly different, but this can help you fix all the problems.

+2
source share

I had the same problem (jacob is not working in the service), and this useful post (changing dcomcnfg) did the trick:

http://bytes.com/topic/c-sharp/answers/819740-c-service-excel-application-workbooks-open-fails-when-called-service#post3466746

+2
source share

All Articles