2009-02-04 60 views
1

我正嘗試從Java/SWT應用程序與Excel進行通信。我已經能夠打開一個工作表,打開一個文件並保存它,但這就是它。是否有使用OLE自動化(來自Java)的良好參考?

任何人都可以指向我的一些文檔/例子嗎?我特別需要知道哪些命令可用。我確實嘗試記錄宏來檢查。這是有用的,但沒有給我我想要的一切。

這是我迄今已嘗試一個樣本:

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); 
} 

回答

1

不是一個文件,而是因爲你通過自動化詢問了可用的命令:你試過自帶的OLE/COM對象查看與Windows 2000資源工具包?下載here

+0

尚未 - 感謝您的鏈接 – paul 2009-02-04 12:11:12

2

使用VBA幫助MSOffice。您也可以在Office的VB編輯器中使用對象瀏覽器。