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

Siv*_*ini 7 c# npoi c#-4.0

我们刚开始使用NPOI组件.

我们遇到了设置ICellStyle属性的FillForegroundColor的问题.

ICellStyle HeaderCellStyle = xssfworkbook.CreateCellStyle(); 

HeaderCellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.RED.index;
Run Code Online (Sandbox Code Playgroud)

FillForegroundColor期望类型为short.

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

我们需要设置"RGB192:0:0"以及如何为ICellStyle属性FillForegroundColor执行此操作

Colud有人通过一些例子来帮助我们吗?

Siv*_*ini 11

我找到了解决方案.请参考以下代码

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

  • 将我的风格投射到`XSSFCellStyle`就是我所缺少的. (3认同)
  • 不好意思,但这不能回答问题。您的问题与`ICellStyle`有关,但您仅针对`XSSFCellStyle`类回答。这不适用于另一个也继承了ICellStyle的HSSFCellStyle类。 (2认同)