JACOB を使用して、Java から PowerPoint やその他の Office アプリケーションへの COM 呼び出しを行っています。特定の Windows 7 ボックスで、次のメッセージが頻繁に表示されますが、常にではありません。
Source: Microsoft Office PowerPoint 2007
Description: PowerPoint could not open the file.
エクセルから私は得る:
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 では発生しないことがわかりました。そして、私が知る限り、それはファイルシステムに関連していません(ファイルをコピーするメカニズムを交換し、ファイルを別のファイルシステムに配置しようとしました)。
catalina.bat start
これは、コマンドラインから実行したときではなく、Java アプリケーションがサービスとして実行されているときにのみ発生することに気付きました。