从 Range.Interior.Color(或任何其他颜色属性)返回 RGB 值 [英] Return RGB values from Range.Interior.Color (or any other Color Property)

查看:27
本文介绍了从 Range.Interior.Color(或任何其他颜色属性)返回 RGB 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图逐步将单元格的背景颜色更改为黑色,但我发现 Range.Interior.Color 方法返回一个 Long,这似乎是任意的.查看 MSDN 上的文档,几乎没有关于这个数字代表什么的内容.有没有办法从这个长返回RGB值.我实际上需要与 RGB(red, green, blue) 函数相反的函数.

I was trying to incrementally change the background color of a cell to black, and I found that the Range.Interior.Color method returns a Long which is seemingly arbitrary. Looking at the documentation on MSDN, there is nearly nothing about what this number represents. Is there a way to return the RGB value from this long. I effectively need the opposite of the RGB(red, green, blue) function.

推荐答案

简短回答:

没有为此内置功能.您必须编写自己的函数.

There is no built in functionality for this. You must write your own function.

长答案:

从 Interior.Color 属性返回的 long 是我们习惯于在 html 中看到的颜色的典型十六进制数的十进制转换,例如66FF66".此外,可以传递常量 xlNone (-4142) 以将单元格设置为在背景中没有颜色,但是此类单元格从 Get<中标记为白色 RGB(255, 255, 255)/代码> 属性.知道了这一点,我们可以编写一个函数来返回一个或所有适当的 RGB 值.

The long that is returned from the Interior.Color property is a decimal conversion of the typical hexidecimal numbers that we are used to seeing for colors in html e.g. "66FF66". Additionally the constant xlNone (-4142) can be passed to set cell to have no color in the background, however such cells are marked white RGB(255, 255, 255) from the Get property. Knowing this, we can write a function that returns one or all of the appropriate RGB values.

幸运的是,Allan Wyatt 先生在这里做到了这一点!

Luckily, a kind Mr. Allan Wyatt has done just that here!

确定颜色的 RGB 值

这篇关于从 Range.Interior.Color(或任何其他颜色属性)返回 RGB 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆