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

标签 java com ms-office powerpoint jacob

我正在使用 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 start 时发生。

最佳答案

我有同样的问题(服务中的 jacob 不工作),这个有用的帖子(更改 dcomcnfg)起到了作用:

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

关于java - 从服务通过 JACOB 调用时,Office 2007 无法打开文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3658936/

相关文章:

java - 从 Java Action 监听器返回一个字符串

java - 骑士巡回赛不会超过第四步

windows - 使用 Outlooks COM 类组件仅在管理员权限下失败

c# - 当前使用 C# 扩展 Excel 的最佳方法是什么?

java - 如何查看我被重定向到哪个 URL?

java - 匿名类上的 NotSerializableException

c++ - 哪个是 IErrorInfo 版本的正确处理

c++ - ATL COM 类注册 .rgs 文件默认值

excel - 在 Office.js 中使用 Excel.run() 链接 Promise

c# - 什么支持Excel更好? (VB.net 或 C#.net ??)