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