7

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 アプリケーションがサービスとして実行されているときにのみ発生することに気付きました。

4

2 に答える 2

3

私は同じ問題を抱えていました (サービス中の jacob が機能していません)。

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

于 2011-04-01T13:54:48.157 に答える
2

これはうまくいきますか?

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を表示して、考えられる問題を確認できます。エラーコードは明らかに異なりますが、トラブルシューティングに役立つ場合があります。

于 2010-09-14T05:02:19.983 に答える