Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » OLE ignores calls to Microsoft Excel. OLE or Windows problem?
OLE ignores calls to Microsoft Excel. OLE or Windows problem? [message #698316] Tue, 19 July 2011 09:00 Go to next message
Markus Kunde is currently offline Markus KundeFriend
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);
	}
Re: OLE ignores calls to Microsoft Excel. OLE or Windows problem? [message #698765 is a reply to message #698316] Wed, 20 July 2011 07:49 Go to previous messageGo to next message
Markus Kunde is currently offline Markus KundeFriend
Messages: 3
Registered: July 2011
Junior Member
I believe I discovered the error.

There is a COM-Addin installed in Excel. After disabling my application works well.
Maybe there is a problem in the SWT-OLE implementation?

With other programming languages it works even with activated COM-Addin.
Perhaps somebody could validate my behavior?

COM-Addin: Adobe PDFMaker
Re: OLE ignores calls to Microsoft Excel. OLE or Windows problem? [message #698767 is a reply to message #698765] Wed, 20 July 2011 07:50 Go to previous message
Markus Kunde is currently offline Markus KundeFriend
Messages: 3
Registered: July 2011
Junior Member
For those who have the same problem:
This piece of code deactivates the COM-Addins:

int idAddIns = application.getIDsOfNames(new String[] {"COMAddIns"})[0];
        Variant addInsVar = application.getProperty(idAddIns);
        OleAutomation addIns = addInsVar.getAutomation();
        
        int countID = addIns.getIDsOfNames(new String[] {"Count"})[0];
        Variant countVariant = addIns.getProperty(countID);
                
        int addInsItemID = addIns.getIDsOfNames(new String[] {"Item"})[0];
        for (int i = 1; i <= countVariant.getInt(); i++) {
            Variant addInsItemVariant = addIns.invoke(addInsItemID, new Variant[] {new Variant(i)});
            OleAutomation addInsItem = addInsItemVariant.getAutomation();
            
            int addInsItemConnectID = addInsItem.getIDsOfNames(new String[] { "Connect" })[0];
            if (addInsItem.getProperty(addInsItemConnectID).getBoolean()) {
                int addInsItemNameID = addInsItem.getIDsOfNames(new String[] { "ProgId" })[0];
                Variant addInsItemNameVariant = addInsItem.getProperty(addInsItemNameID);
                String name = addInsItemNameVariant.getString();                
                addInsItem.setProperty(addInsItemConnectID, new Variant(false));
            }
        }
Previous Topic:StyledText cursor position
Next Topic:Showing SWT modal dialog from AWT
Goto Forum:
  


Current Time: Thu Apr 25 10:17:05 GMT 2024

Powered by FUDForum. Page generated in 0.03091 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top