1 votes

Compter les cellules avec une couleur de fond

Dans une plage de cellules, y a-t-il un moyen de compter celles qui ont une certaine couleur de fond ?

1voto

user3439894 Points 52496

Voici un exemple dans AppleScript qui compter le nombre de cellules dans un gamme qui a le couleur de fond de rouge.

Numbers Image

Notez que la cible Numéros document était ouvert et à l'arrière-plan de scriptÉditeur .

Lorsque le script a été exécuté, il a affiché la boîte de dialogue suivante.

Display Dialog Image

--  # User definded variables.

set theRange to "A1:L10"

--  # The background color of the range’s cells. Expressed as a list of RGB (Red, Green, Blue) 
--  #  values, from 0 to 65535. For example, the color red is: {65535, 0, 0}

set R to 65535
set G to 0
set B to 0

--  # Other variables.

set thisColor to ""
set theRGBValue to {}
set theCount to 0

tell application "Numbers"
    tell document 1
        tell sheet 1
            tell table 1
                tell range theRange
                    repeat with i from 1 to (cell count)
                        set thisColor to background color of cell i as string
                        if thisColor is not "" then
                            set theRGBValue to (background color of cell i)
                            if item 1 of theRGBValue is equal to R and item 2 of theRGBValue is equal to G and item 3 of theRGBValue is equal to B then
                                set theCount to theCount + 1
                            end if
                        end if
                    end repeat
                end tell
            end tell
        end tell
    end tell
end tell

display dialog "The cell count with the color {" & R & ", " & G & ", " & B & "} is: " & theCount buttons {"OK"} default button 1

Note : Ce test a été effectué sur une ancienne version de l'interface utilisateur. Numéros (09 ver 2.3) et peut nécessiter un ajustement pour les versions plus récentes.

Si vous ne savez pas ce que le RGB valeur d'un cell est de se brancher sur le script ci-dessus, puis pour obtenir le RGB valeur de la background color d'un cell par exemple F5 utiliser :

tell application "Numbers"
    get background color of cell 1 of range "F5:F5" of table 1 of sheet 1 of document 1
end tell

Pour votre information, j'ai codé l'exemple principal ci-dessus dans sa forme longue et il pourrait être condensé en ce qui suit pour l'exemple de l'UE. tell application "Numbers" bloc :

tell application "Numbers"
    tell range theRange of table 1 of sheet 1 of document 1
        repeat with i from 1 to (cell count)
            if (background color of cell i as string) is not "" then
                set theRGBValue to (background color of cell i)
                if item 1 of theRGBValue is equal to R and item 2 of theRGBValue is equal to G and item 3 of theRGBValue is equal to B then
                    set theCount to theCount + 1
                end if
            end if
        end repeat
    end tell
end tell

LesApples.com

LesApples est une communauté de Apple où vous pouvez résoudre vos problèmes et vos doutes. Vous pouvez consulter les questions des autres utilisateurs d'appareils Apple, poser vos propres questions ou résoudre celles des autres.

Powered by:

X