java – 从服务通过JACOB调用时,Office 2007无法打开文件

我正在使用JACOB从 Java对PowerPoint和其他Office应用程序进行COM调用.在特定的Windows 7机器上,我经常收到以下消息,但并非总是如此:
Source: Microsoft Office PowerPoint 2007
Description: PowerPoint Could not open the file.

从excel我得到:

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错误只是:

VariantChangeType Failed

以下是我正在运行的,错误来自最后一行.

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();

我已经尝试在Open调用之前设置断点并且文件在那里,我实际上可以在GUI中使用PowerPoint打开它,但是当我执行步骤时抛出异常.

关于这个问题的烦人的事情是,它似乎不断发生,但是在对它进行了一段时间(重新运行相同的代码)之后,它最终成功完成,之后再也没有出现过.

进一步的研究我发现这只发生在.ppt,.doc和.xls文件中,而不是.pptx,.docx和.xlsx.据我所知,它与文件系统无关(我已经换掉了复制文件并尝试将文件放在不同文件系统上的机制).

我刚刚注意到这只发生在Java应用程序作为服务运行时,而不是在我从命令行运行catalina.bat时.

解决方法

我有同样的问题(jacob在服务中不工作),这个有用的发布(更改dcomcnfg)做了诀窍:

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

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...