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