Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting Excel Document in Qt

Tags:

excel

qt4

activex

I am using Qt 4.5 and Windows XP. I need to create an Microsoft Excel Document that has data (some labels and values) from the Qt application. I need to format those data with some fonts,bold,italics,color, background color etc., Besides ordinary data, there will be Picture files (JPG) also. I need to add those into the Excel. I know retrieving values from Excel using QAxWidget, QAxObject. But I don't have a clue about the formatting options that can be applied to cells through Qt and adding images as well?? Any help regarding this are welcome.

like image 772
liaK Avatar asked Apr 15 '10 11:04

liaK


People also ask

How do I read an Excel file in Qt?

To use ODBC for Excel on Windows, the MS Access Database Engine must be downloaded as mentioned in the wiki Note from which this sample code was tested (Win7/ qt4. 9 , Win10/ qt 5.7) , then the connection can work. alternatively in the same Qt wiki Content, you can find different ways of opening MS Excel with Qt.

How do I create a QT file in Excel?

It can be done using Active Qt. This allows to use Active X (OLE) to interact with Excel. But this requires to have Excel installed on the computer that will run your program. Another solution, if you only need to fill the cells of a spreadsheet is to create a CSV file.

How do I write an Excel file in C++?

If you simply want to fill a few cells the easiest way is to write a CSV file. If you want more control on the format or layout of your sheets you can use the Excel 2003 XML format. Just create a template of the file as you like, and use it to create your own: it is plain XML, relatively simple to understand.


1 Answers

There are a few options:

  1. Use a cross platform library
    • xlslib is one such library
  2. Use the Excel Object model directly If your program will run on a machine that has office installed you can use COM or ActiveX to tie into the Excel object model to create the workbooks. Excel has a rich and complete object that will let you do most operations.
  3. Write to an intermediate database Write the QT data to some type of database and pull the data using Excel. This route requires in depth Excel knowledge and a database.
  4. Write out an XML format that Excel can understand
    • Excel 2003 can understand SpreadsheetML. Simple formatting should be straight forward to construct an XML document for. http://msdn.microsoft.com/en-us/library/bb226687(office.11).aspx
    • Excel 2007 can understand OpenXML. I have not worked with it, but I understand it is more complicated (i.e. more feature rich) http://msdn.microsoft.com/en-us/library/aa338205.aspx
like image 94
ccozad Avatar answered Sep 19 '22 15:09

ccozad