Mar*_*off 39
该"任意"数字是RGB值(B*256 ^ 2 + G*256 + R)的数学组合和十六进制颜色值到十进制数(基数16到基数10)的转换,具体取决于哪种方式你想看看它.只是不同的基础.下面是我在为Excel编写的XLAM addin文件中使用的方法.这种方法已经多次派上用场了.我已将文档包含在我的addin文件中.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Function Color
' Purpose Determine the Background Color Of a Cell
' @Param rng Range to Determine Background Color of
' @Param formatType Default Value = 0
' 0 Integer
' 1 Hex
' 2 RGB
' 3 Excel Color Index
' Usage Color(A1) --> 9507341
' Color(A1, 0) --> 9507341
' Color(A1, 1) --> 91120D
' Color(A1, 2) --> 13, 18, 145
' Color(A1, 3) --> 6
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function Color(rng As Range, Optional formatType As Integer = 0) As Variant
Dim colorVal As Variant
colorVal = Cells(rng.Row, rng.Column).Interior.Color
Select Case formatType
Case 1
Color = Hex(colorVal)
Case 2
Color = (colorVal Mod 256) & ", " & ((colorVal \ 256) Mod 256) & ", " & (colorVal \ 65536)
Case 3
Color = Cells(rng.Row, rng.Column).Interior.ColorIndex
Case Else
Color = colorVal
End Select
End Function
Run Code Online (Sandbox Code Playgroud)
小智 16
很高兴看到怀亚特先生使用快速的RGB颜色方法
R = C Mod 256
G = C \ 256 Mod 256
B = C \ 65536 Mod 256
Run Code Online (Sandbox Code Playgroud)
这比使用六角形str的那些快几倍,有些人推荐
小智 8
另一个答案对我不起作用。我找到:
R = C And 255
G = C \ 256 And 255
B = C \ 256 ^ 2 And 255
Run Code Online (Sandbox Code Playgroud)
并且它工作正常。
| 归档时间: |
|
| 查看次数: |
73355 次 |
| 最近记录: |