2

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 ?

menjaraz
  • 7,551
  • 4
  • 41
  • 81
Dev
  • 127
  • 2
  • 8
  • 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 set particular color to a cell in the sheet which is specified in sheet_Name. !! how can i set the color? – Dev Jan 30 '12 at 05:46

2 Answers2

2

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); 
menjaraz
  • 7,551
  • 4
  • 41
  • 81
  • I want it to be with Qt properties . so how can i do ? can you explain it clearly ? – Dev Jan 30 '12 at 08:49
  • Try something similar to Cell_Range->setProperty("Value", QVariant(1234)); – menjaraz Jan 30 '12 at 11:59
  • QAxObject* Interior = currentCell->querySubObject("Interior"); Interior->setProperty("ColorIndex",Index_val); And It works fine!!!! Thanks menjaraz !! – Dev Jan 31 '12 at 04:43
  • You are welcome. Don't forget to study the [Excel Object Model Reference](http://msdn.microsoft.com/en-us/library/bb149081%28v=office.12%29.aspx) to go further. I will edit accordingly the answer so that it can serve readily any visitor. If feel that my attempt to answer was helpfull you can accept it. – menjaraz Jan 31 '12 at 08:00
1

How to get currentCell object:

  QAxObject* Interior = currentCell->querySubObject("Interior"); 
  Interior->setProperty("ColorIndex",Index_val); 
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213