加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何在C#中将Excel.Range.Interior.Color转换为System.Drawing.C

发布时间:2020-12-15 18:04:54 所属栏目:百科 来源:网络整理
导读:我有一张excel表,其中一些单元格有一些背景颜色.我需要在 HTML代码中使用这种颜色,因此我想将Excel.Range.Interior.Color转换为RGB格式或System.Drawing.Color. 在这之后,我将使用System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color)来获取要在htm
我有一张excel表,其中一些单元格有一些背景颜色.我需要在 HTML代码中使用这种颜色,因此我想将Excel.Range.Interior.Color转换为RGB格式或System.Drawing.Color.

在这之后,我将使用System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color)来获取要在html标签中使用的颜色.

我尝试过以下方法:

Excel.Range r = (Excel.Range)m_objRange[2,2];
System.ComponentModel.TypeConverter converter = System.ComponentModel.TypeDescriptor.GetConverter(r.Interior.Color);
               MessageBox.Show(""+converter.ConvertTo(r.Interior.Color,typeof(System.Drawing.Color)));

但我得到一个错误,我无法将System.Double转换为System.Drawing.Color

解决方法

Excel.Range.Interior.Color返回的值是颜色的长整数值.

例子:

‘#000000等于0

‘#FFFFFF等于16777215

您需要将十进制值转换为十六进制.从那里,很容易转换为RGB. (分组为2个八位字节,并转换回十进制):)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读