Is there a good reference for using OLE Automation (from Java)?

2

I am trying to communicate with Excel from a Java/SWT application. I have been able to open a worksheet, open a file and save it but that's about it.

Can anyone point me to some documentation/examples for this? I especially need to know which commands are available. I did try to record macros to inspect. This was useful but did not give me everything I wanted.

This is a sample of what I have been trying so far:

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);
}
java
automation
ole
asked on Stack Overflow Feb 4, 2009 by paul

2 Answers

2

Use VBA help MSOffice. Also you can use Object Browser in Office's VB editor.

answered on Stack Overflow Dec 29, 2009 by P.Melamed
1

Not a documentation, but since you asked about the available commands via automation: have you tried the OLE/COM Object viewer that comes with the Windows 2000 resource kit? Download here.

answered on Stack Overflow Feb 4, 2009 by Stephan Keller

User contributions licensed under CC BY-SA 3.0