我正在使用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)做了诀窍:
原文地址:https://www.jb51.cc/java/129845.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。