NPOI 自定义单元格背景颜色-Excel
使用
在线颜色选择器 | RGB颜色查询对照表
(http://tools.jb51.net/static/colorpicker/)
查找颜色RGB
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.CreateSheet("计划") as HSSFSheet;
//调色板实例
HSSFPalette palette = workbook.GetCustomPalette();
palette.SetColorAtIndex((short)10, (byte)228, (byte)223, (byte)236);
HSSFColor hssFColor = palette.FindColor((byte)228, (byte)223, (byte)236);
第一个参数:设置调色板新增颜色的编号,自已设置即可;取值范围8-64
第二、第三、第四个参数,组成RGB值
ICellStyle title_style = workbook.CreateCellStyle();
//设置单元格上下左右边框线
title_style.BorderTop = BorderStyle.Thin;
title_style.BorderBottom = BorderStyle.Thin;
title_style.BorderLeft = BorderStyle.Thin;
title_style.BorderRight = BorderStyle.Thin;
title_style.WrapText = true;
title_style.Alignment = HorizontalAlignment.Left;
title_style.VerticalAlignment = VerticalAlignment.Center;
title_style.FillPattern = FillPattern.SolidForeground;
title_style.FillForegroundColor = hssFColor.GetIndex();
HSSFRow dataRow2 = sheet.CreateRow(1) as HSSFRow;
for (int i = 0; i < det_title_arr.Length; i++)
{
ICell Cell = dataRow2.CreateCell(i);
Cell.CellStyle = title_style;
}
参考:https://www.cnblogs.com/yxhblog/p/6225018.html