c# - ICellStyle FillForegroundColor 的自定义颜色比提供的命名颜色

标签 c# c#-4.0 npoi

我们刚开始使用 NPOI 组件。

我们在设置 ICellStyle 属性的 FillForegroundColor 时遇到问题。

ICellStyle HeaderCellStyle = xssfworkbook.CreateCellStyle(); 

HeaderCellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.RED.index;

FillForegroundColor 需要短类型。

我们如何设置不同的颜色而不是使用 HSSFColor 中的颜色。

我们需要设置为 "RGB192:0:0" 以及我们如何为 ICellStyle 属性 FillForegroundColor 设置

有人可以通过一些例子帮助我们吗?

最佳答案

我自己找到了解决方案。请引用下面的代码

byte[] rgb = new byte[3] { 192, 0, 0 };
 XSSFCellStyle HeaderCellStyle1 = (XSSFCellStyle)xssfworkbook.CreateCellStyle();
 HeaderCellStyle1.SetFillForegroundColor(new XSSFColor(rgb));

关于c# - ICellStyle FillForegroundColor 的自定义颜色比提供的命名颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22687901/

相关文章:

C# 程序使用 NPOI 编辑 excel(.xls) 的单元格值不起作用

c# - 使用 npoi 单元格范围地址读取 excel

c# - 是否可以在 visual studio 调试 session 之间保留 cookie

c# - ASP.Net 核心 : Get User Roles with LinQ Select method

c# 反射返回 "Nullable` 1"

C# 4 表达式树中的 "dynamic"

c# - NPOI:如何在条件格式中使用自定义 XSSFColor?

c# - 获取特定字符之间的字符串

c# - 从另一个列表中获取不包含某些内容的文件列表

.net - 如何确定正在执行的程序集是 Web 应用程序还是 winform/控制台?