OLE ignores calls to Microsoft Excel. OLE or Windows problem? [message #698316] |
Tue, 19 July 2011 09:00 |
Markus Kunde Messages: 3 Registered: July 2011 |
Junior Member |
|
|
Hi all,
I have a problem regarding OLE.
System (business laptop):
- Win 7 64bit (local Admin rights)
- Java 1.6.0.26 32bit
- Eclipse Indigo (SWT win32 x86: Version 3.7.0.v3735b)
- Office 2010 32bit
This is an example code. I just try to open Microsoft Excel, set visible to true and insert a new workbook. This fails and I cannot identify the reason for that. Maybe it is Java, SWT or a special configuration in Windows (in fact I have no idea because I potentially could exclude everything). The method-invoke "Add" returns a null, NO new workbook is displayed in Excel and in my code the following statements will fail because I need the workbook-object which is null.
The problem background:
- The same environment (JRE and Eclipse, SWT) on a clean Win 7 64bit and Office 32bit works (sounds like a Windows configuration failure). During debugging, I see that Excel opens and with invoking "add" a new workbook occurs.
- Other programming languages (Python with Win32 extensions, Powershell and Visual Basic) can perform the same code. In these languages invoking "add" produces a new visible workbook (sounds like a SWT-OLE or Java problem).
Anybody an idea?
Maybe it is just a security property on my business laptop (it works in other languages?) or maybe its a SWT problem?
Thanks for any ideas I can try.
Markus
Here is my example code (after null-pointer native Excel process will not killed):
private void workbookAdd() {
Display display = new Display();
Shell shell = new Shell(display);
OleFrame frame = new OleFrame(shell, SWT.NONE);
OleControlSite controlSite = new OleControlSite(frame, SWT.NONE, "Excel.Application");
OleAutomation application = new OleAutomation(controlSite);
controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
// Set visible
Variant[] arguments = new Variant[1];
arguments[0] = new Variant("true");
int[] ids = application.getIDsOfNames(new String[] { "Visible" });
application.setProperty(ids[0], arguments);
// Get Workbooks-Object
int[] excelIds = application.getIDsOfNames(new String[] { "Workbooks" });
Variant workbooksVariant = application.getProperty(excelIds[0]);
OleAutomation workbooks = workbooksVariant.getAutomation();
// Add new workbook
int idAdd = workbooks.getIDsOfNames(new String[] { "Add" })[0];
Variant add = workbooks.invoke(idAdd);
OleAutomation workbook = add.getAutomation();
//some things I'd like to do with "workbook"-object.
//...
//...
// Close Excel
int invokeID = application.getIDsOfNames(new String[] { "Quit" })[0];
application.invokeNoReply(invokeID);
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03455 seconds