PDA

View Full Version : Qt QAxObject - Find Documentation for Excell API/SDK on Cell Property,etc



Kyef
19th February 2021, 13:56
I need to integrate my Qt Application with MS Excel, I have created a class that can do the job so well but I have limited knowledge of the variables to include when dealing with the worksheet (querySubObject) and Cell Properties such as borders (Bottom Border, Top Border, Bottom Double border,etc), as well as writing images, chats, etc into the spreadsheet, headers and footers(this very important). I have searched the internet in vain. Can someone point to me how I can access these attributes so I can make my exports look elegant to the final user? Thanks.

d_stranz
19th February 2021, 16:37
The Microsoft VBA (Visual Basic for Applications) framework is the primary programming interface to Office applications. The Excel Object Model (https://docs.microsoft.com/en-us/office/vba/api/overview/excel/object-model) defines all of the objects that can be manipulated through VBA (which uses the underlying COM /ActiveX interface to Excel).

This VBA-based object model is identical to the ActiveX model you can access through C++. So you can follow that documentation to get at the objects and their properties from within C++. After you #import the Excel type libraries into your C++ program, you will find that it has generated "tli" and "tlh" #include files that contain the actual C++ names for each of the corresponding VBA objects. (So "Application" becomes "_Application" for example). These are readable ASCII files and you will be able to see the complete C++-based object model in them. You'll need to learn how to read Microsoft MIDL (https://docs.microsoft.com/en-us/windows/win32/midl/midl-start-page) syntax but it isn't much different from C++.

There is a document here (https://personalpages.manchester.ac.uk/staff/Andrew.Hazel/EXCEL_C++.pdf) that gives some examples of interfacing to Excel ActiveX using C++. Skip the first 57 pages. Another example is here (https://www.technical-recipes.com/2012/how-to-interface-with-excel-in-c/). Googling for "Excel C++ ActiveX examples" will give you more hits than these.

Note that it is -not- necessary to use the Qt ActiveX framework in order to use non-GUI-based ActiveX objects from within a Qt app. You can directly #import the type libraries and use them to create ActiveX object instances inside the Excel:: namespace.

The Qt ActiveX framework is unnecessary overhead that actually makes it much more difficult to use non-GUI ActiveX objects in a Qt app.


Cell Properties such as borders (Bottom Border, Top Border, Bottom Double border,etc)

For this you'll probably want to retrieve the CellFormat (https://docs.microsoft.com/en-us/office/vba/api/excel.cellformat) object for the cell (or whatever it is called in the C++ model).

Kyef
20th February 2021, 08:56
Thank you very much. This is what I needed. I have gone through the links and able to identify the properties and methods that I needed urgently. In Qt, we have got the modules and API to access Ms excel and all I needed were the property and methods that can be executed to get the formats desired. Let me get this working!!:o