0

Доброе время суток! Задача такова, надо вычислить в таблице Excel сколько красных ячеек, сколько зеленных ячеек, так и далее... с помощью C++ Builder.

1
  • Если кроме C++ Builder можно использовать excel, то создаёте com-объект Excel.Application (если не забыл), находите нужный шит (sheet) и исследуете ячейки.
    – alexlz
    20 авг 2012 в 8:33

1 ответ 1

2

Затрудняюсь сказать, как узнать цвет ячейки прямо из C++ Builder. Вы можете создать макросы VBA и уже их как-нибудь использовать из приложения C++ Builder. Пример макроса:

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

Взято отсюда: Color Functions In Excel.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.