PDA

View Full Version : Ole objects in Qt(MS OFFice)



mchara
25th September 2007, 09:34
Hi,
I know how to use QAxObject with automation objects to access MS Office files, but there's no ActiveX controls that would be able to show Office documents embedded in my application. I found that OLE containers are supposed to embeed documents in a way that allows to edit them with original(server) application, but unfortunately activeQt framework doesn't support OLE objects.
Does anybody knows is it possible to embed OLE object in Qt application?
I heard that it is possible to write an activeX control in MFC(that supports OLE objects) and embed it in QAxWidget, but I don't know MFC so maybe there's other similar way to do it.

wysota
25th September 2007, 10:37
I know how to use QAxObject with automation objects to access MS Office files, but there's no ActiveX controls that would be able to show Office documents embedded in my application.
Really? What's wrong with QAxWidget?


I found that OLE containers are supposed to embeed documents in a way that allows to edit them with original(server) application, but unfortunately activeQt framework doesn't support OLE objects.
Sure it does. Take a look at ActiveX examples that come with Qt.


I heard that it is possible to write an activeX control in MFC(that supports OLE objects) and embed it in QAxWidget, but I don't know MFC so maybe there's other similar way to do it.

Hmm... OLE is ActiveX... so I don't know what exactly would you wrap into what...

Just create a QAxWidget and use its setControl() method (inherited from QAxBase) to spawn an appropriate COM object to handle the resource you want to edit.

mchara
25th September 2007, 11:00
When I'm using QAxObject with "Excel.Application" control and calling dynamicCall("Activate()") it opens MS Excel as separate application with whole gui, separate window ect. and there's no control that is drawn as QAxWidget embedded in a window of my application. OLE objects is quite different mechanism that doesn't use COM objects directly but via ole32.dll windows library. The behaviour I want to achive is object that shows only a contents of a document in my application and makes it editable after a click(as when You i.e. click insert>object>"microSoft Excel WorkSheet" in MS Word).

There's one workaround known to me: after activation of Excel.Application object, created window can be reparented to calling application, but it's still drawn with whole excel's gui stuff.
Do you see the difference now?

wysota
25th September 2007, 11:17
Actually, I don't think it looks exactly like that. The static image is just an image (you can't interact with it, i.e. select the contents with the mouse) - you can probably create one using QAxObject or a hidden QAxWidget. The actual "automation" takes place after you click the image to make it editable. Only then the actual component is embedded into the application.

If you want to display a word document, you can probably spawn a word control, make it read only and strip it of all decorations.

And by the way, wikipedia says you are wrong:

ActiveX is an alternate name for OLE automation (OLE - Object Linking and Embedding), not a separate technology.

mchara
25th September 2007, 12:01
I am using Office 2003 (maybe activeX controls are different in different versions of office) and QAxWidget doesn't draw anything(i got black screen).
I'm doing everything as in Qt example and Outlook works embedded but Excel doesn't - they have different interfaces.

OLE object indeed is an activeX but those aren't synonyms: OLE uses different interfaces & workflow - check it before quoting wrong informations. Ole objects behaves in a little different way than regular activeX controls and I need behaviour more like OLE(with embedding in application and ability to show contents only or edit a document, as i'm saying for the third time) and QAxWidget can't do it with office 2003 controls(QAxWidget doesn't draw excel embedded, but opens an application in separate window and full gui what's not what i'm want to!).

I need some advise, not pointless conversation.

wysota
25th September 2007, 12:15
I am using Office 2003 (maybe activeX controls are different in different versions of office) and QAxWidget doesn't draw anything(i got black screen).
I'm doing everything as in Qt example and Outlook works embedded but Excel doesn't - they have different interfaces.
Maybe the id is different? Either try passing the document you want to view as the control (like "C:\\somedoc.xls") or check what COM servers you have registered in your system. I don't think the application version should matter...


OLE object indeed is an activeX but those aren't synonyms
True. But ActiveX contains OLE functionality.


I need some advise, not pointless conversation.
If you need OLE functionality, you can fetch the correct interface using QAxBase API and perform a precise call using OLE interface. OLE is built over COM and you have full (most?) COM support in Qt, so this should be possible. So I advise you first focus on properly embedding the component in your application.

mchara
25th September 2007, 12:33
try passing the document you want to view as the control (like "C:\\somedoc.xls") .
The QAxWidget with setControl to a file generates warnings and says that an object doesn't support automation and fails to activate it.
Any ideas why it happens?

wysota
25th September 2007, 13:24
The QAxWidget with setControl to a file generates warnings and says that an object doesn't support automation and fails to activate it.
Any ideas why it happens?

Indeed weird, try passing "Excel.Application" then. And check out the "webbrowser" example - it uses the approach directly to embed a web browser and call its functions. You can use it as a test bed (even from within Designer), you just might need to remove the dynamicCall() line.

Sorry I can't test it by myself but I don't have Excel and I'm currently working on Linux and don't want to stop to reboot the machine :)

jpn
25th September 2007, 18:49
I first tried

dumpcpp Excel.Application -o excel
which only gave me

dumpcpp: type library '' not found
Then I found this thread: http://lists.trolltech.com/qt-interest/2007-02/msg00704.html, so I tried:

dumpcpp {00020813-0000-0000-C000-000000000046} -o excel
which worked, but the resulting excel.h is 166k lines so I don't feel like diving into it as I'm not that familiar with the subject. :)

mchara
26th September 2007, 07:07
Yeah, already tried... but it generates automation object interface only.
Just as QAxObject :( ...