C# Excel Npoi 顏色設置


/// <summary>
/// 獲取單元格樣式
/// </summary>
/// <param name="excel">wrook</param>
/// <param name="nFontSize">字體大小,正常設置即可,方法內部轉化</param>
/// <param name="align">橫向停靠位置</param>
/// <param name="bIsBlod">是否加粗</param>
/// <param name="colorIndex">顏色索引</param>
/// <returns>ICellStyle</returns>
private static ICellStyle GetCellStyle(IWorkbook excel, int nFontSize, HorizontalAlignment align = HorizontalAlignment.Left, bool bIsBlod = false,short colorIndex =64)
{
IFont fontContent = excel.CreateFont();
fontContent.IsBold = bIsBlod;
fontContent.FontHeight = nFontSize * 20;
fontContent.FontName = "微軟雅黑";
HSSFCellStyle cellContextStyle =(HSSFCellStyle) excel.CreateCellStyle();//這里不要用IcellStye,接口顏色無法更改
cellContextStyle.Alignment = align;
cellContextStyle.VerticalAlignment = VerticalAlignment.Center;
cellContextStyle.SetFont(fontContent);
cellContextStyle.BorderBottom = BorderStyle.Medium;
cellContextStyle.BorderLeft = BorderStyle.Medium;
cellContextStyle.BorderTop = BorderStyle.Medium;
cellContextStyle.BorderRight = BorderStyle.Medium;
if (colorIndex != 64)
{
cellContextStyle.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground;
cellContextStyle.FillForegroundColor = colorIndex;
}
return cellContextStyle;
}

 


免責聲明!

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



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