我使用雅各布从Java对PowerPoint和其他办公应用程序进行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.“错误”这个词就是:
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调用之前放置一个断点,文件就在那里,实际上我可以在图形用户界面中使用PowerPoint打开它,但当我执行该操作时抛出了异常。
这个问题的恼人之处在于,它似乎一开始就一直在发生,但在一段时间后(重新运行相同的代码),它最终成功完成,此后再也不会发生。
进一步的研究发现,这种情况只发生在.ppt、.doc和.xls文件上,而不是.pptx、.docx和.xlsx文件上。据我所知,它与文件系统无关(我替换了复制文件的机制,并尝试将文件放在不同的文件系统上)。
我刚刚注意到,只有当Java应用程序作为服务运行时才会发生这种情况,而不是当我从命令行运行catalina.bat start时。
发布于 2011-04-01 21:54:48
我也有同样的问题(雅各布在服务中不工作),这个有用的帖子(更改dcomcnfg)解决了这个问题:
http://bytes.com/topic/c-sharp/answers/819740-c-service-excel-application-workbooks-open-fails-when-called-service#post3466746
发布于 2010-09-14 13:02:20
这对你有效吗?
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();
}
}更新:如果这是在客户端工作,只是自动化导致了问题,你可以查看http://support.microsoft.com/kb/257757来查看可能的问题。这两个错误代码明显不同,但它可能会帮助您排除所有故障。
https://stackoverflow.com/questions/3658936
复制相似问题