Good time of day! The task is to calculate in the Excel spreadsheet how many red cells, how many green cells, and so on ... using C ++ Builder.

  • If, in addition to C ++ Builder, you can use excel, then create a com-object Excel. Application (if you have not forgotten), find the necessary sheet and examine cells. - alexlz

1 answer 1

It is difficult to say how to know the color of the cell directly from C ++ Builder. You can create VBA macros and use them somehow from the C ++ Builder application. Macro example:

Function ColorIndexOfOneCell(Cell As Range, OfText As Boolean, _ DefaultColorIndex As Long) As Long Dim CI As Long Application.Volatile True If OfText = True Then CI = Cell(1, 1).Font.ColorIndex Else CI = Cell(1, 1).Interior.ColorIndex End If If CI < 0 Then If IsValidColorIndex(ColorIndex:=DefaultColorIndex) = True Then CI = DefaultColorIndex Else CI = -1 End If End If ColorIndexOfOneCell = CI End Function Private Function IsValidColorIndex(ColorIndex As Long) As Boolean Select Case ColorIndex Case 1 To 56 IsValidColorIndex = True Case xlColorIndexAutomatic, xlColorIndexNone IsValidColorIndex = True Case Else IsValidColorIndex = False End Select End Function 

Taken from here: Color Functions In Excel .