java – 从服务通过JACOB调用时,Office 2007无法打开文件
发布时间:2020-12-15 00:50:42 所属栏目:Java 来源:网络整理
导读:我正在使用JACOB从 Java对PowerPoint和其他Office应用程序进行COM调用.在特定的Windows 7机器上,我经常收到以下消息,但并非总是如此: Source: Microsoft Office PowerPoint 2007Description: PowerPoint could not open the file. 从excel我得到: ERROR -
我正在使用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:marchenamarchena10workmarchenabatch_58288inputcontent_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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |