How to Apply a color to excel cell using Qt?

3.7k Views Asked by At

I am new to Qt . I have written a program to read and write datas from excel file.

    void Excel::Color(const QString& Sheet_Name,const QString& cell,const QString& color_Name) { 
  QAxObject* Worksheet = activeWorkbook->querySubObject("WorkSheets(const QString&)",Sheet_Name); 
  QAxObject* Cell_Range = Worksheet->querySubObject("Range(const QString&)",cell ); 
} 

Now i need to apply color to particular cell. Is there any posibility to achieve this ?

2

There are 2 best solutions below

4
On BEST ANSWER

As a enthusiast, I did office automation in the past. I don't feel very comfortable with Qt but I have Qt Creator 2.4.0 installed on my box with the latest Qt framework: It's very promising.

Here is a VBA snippet more relevant to Cell coloring,

Cells(1, “D”).Interior.Color = RGB(0, 255, 255)
Cells(1, “D”).Borders.Weight = xlThick
Cells(1, “D”).Borders.Color = RGB(0, 0, 255)

You can also head to this interesting thread related to harnessing Excel file with QAxWidget.

Edit:

The OP finally end up founding an appropriate Qt solution as follows:

QAxObject* Interior = currentCell->querySubObject("Interior"); 
Interior->setProperty("ColorIndex",Index_val); 
0
On

How to get currentCell object:

  QAxObject* Interior = currentCell->querySubObject("Interior"); 
  Interior->setProperty("ColorIndex",Index_val);