使用epplus C#设置Excel工作表单元格的自定义BackgroundColor [英] Set custom BackgroundColor of a Excel sheet cell using epplus c#

查看:457
本文介绍了使用epplus C#设置Excel工作表单元格的自定义BackgroundColor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

我正在使用EEPlus.

I am using EEPlus.

我坚持使用十六进制颜色代码,例如#B7DEE8,用于Excel工作表中的单元格.

I am stuck at applying a hex color code, e.g. #B7DEE8, for a cell in my Excel sheet.

我得到了以下(有效的)代码:

I got the following (working) code:

ws.Cells["A1:B1"].Style.Fill.PatternType = ExcelFillStyle.Solid;
ws.Cells["A1:B1"].Style.Fill.BackgroundColor.SetColor(Color.Gray);

但是我需要类似以下内容的东西:

But I need something like the following:

ws.Cells["A1:B1"].Style.Fill.BackgroundColor.SetColor("#B7DEE8");

所以我的问题是:EEPlus是否可以使用十六进制颜色代码?如果是这样,我该怎么办?

So my question is: is it possible to use hex color codes with EEPlus? If so, how can I do that?

推荐答案

尝试一下

Color colFromHex = System.Drawing.ColorTranslator.FromHtml("#B7DEE8");
ws.Cells["A1:B1"].Style.Fill.PatternType = ExcelFillStyle.Solid;
ws.Cells["A1:B1"].Style.Fill.BackgroundColor.SetColor(colFromHex);

这篇关于使用epplus C#设置Excel工作表单元格的自定义BackgroundColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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