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

如果是8,9會導致邊框被覆蓋,其中,8是改變邊框的顏色,9是改變整個sheet的背景顏色

第二、第三、第四個參數,組成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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM