2

Java/SWTアプリケーションからExcelと通信しようとしています。ワークシートを開いてファイルを開いて保存することができましたが、それだけです。

誰かが私にこれに関するいくつかのドキュメント/例を教えてもらえますか?特に、どのコマンドが使用可能かを知る必要があります。検査するマクロを記録しようとしました。これは便利でしたが、私が望むすべてを私に与えることはできませんでした。

これは私がこれまで試してきたことのサンプルです:

private static OleAutomation openFile(
        OleAutomation automation, String fileName) {
    Variant workbooks = automation.getProperty(0x0000023c);// get User
                                                            // Defined
                                                            // Workbooks
    Variant[] arguments = new Variant[1];

    arguments[0] = new Variant(fileName);
    System.out.println("workbooks::\t" + workbooks);

    IDispatch p1 = workbooks.getDispatch();
    int[] rgdispid = workbooks.getAutomation().getIDsOfNames(new String[] { "Open" });
    int dispIdMember = rgdispid[0];
    Variant workbook = workbooks.getAutomation().invoke(dispIdMember, arguments);
    System.out.println("Opened the Work Book");
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    int id = workbook.getAutomation().getIDsOfNames(new String[] { "ActiveSheet" })[0];
    System.out.println(id);
    Variant sheet = workbook.getAutomation().getProperty(id);
    OleAutomation sheetAutomation = sheet.getAutomation();

    return (sheetAutomation);
}
4

2 に答える 2

2

VBA ヘルプ MSOffice を使用します。また、Office の VB エディターでオブジェクト ブラウザーを使用することもできます。

于 2009-12-29T12:38:19.600 に答える