public static NPOI.SS.UserModel.ICellStyle GetCellStyle(this NPOI.SS.UserModel.IWorkbook workbook, short backColorIndex, short fontColorIndex, System.Drawing.Font font, NPOI.SS.UserModel.HorizontalAlignment horizontalAlignment = NPOI.SS.UserModel.HorizontalAlignment.General, NPOI.SS.UserModel.VerticalAlignment verticalAlignment = NPOI.SS.UserModel.VerticalAlignment.None, NPOI.SS.UserModel.BorderStyle borderLeft = NPOI.SS.UserModel.BorderStyle.None, NPOI.SS.UserModel.BorderStyle borderTop = NPOI.SS.UserModel.BorderStyle.None, NPOI.SS.UserModel.BorderStyle borderRight = NPOI.SS.UserModel.BorderStyle.None, NPOI.SS.UserModel.BorderStyle borderBottom = NPOI.SS.UserModel.BorderStyle.None) { NPOI.SS.UserModel.ICellStyle cellStyle = workbook.CreateCellStyle(); if (backColorIndex >= 8 && backColorIndex <= 63) { cellStyle.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground; cellStyle.FillForegroundColor = backColorIndex; } cellStyle.Alignment = horizontalAlignment; cellStyle.VerticalAlignment = verticalAlignment; cellStyle.BorderLeft = borderLeft; cellStyle.BorderTop = borderTop; cellStyle.BorderRight = borderRight; cellStyle.BorderBottom = borderBottom; if (font != null) { NPOI.SS.UserModel.IFont cellFont = workbook.CreateFont(); if (fontColorIndex >= 8 && fontColorIndex <= 63) { cellFont.Color = fontColorIndex; } cellFont.FontName = font.Name; cellFont.FontHeight = font.Size; cellFont.Boldweight = (short)(font.Bold ? NPOI.SS.UserModel.FontBoldWeight.Bold : NPOI.SS.UserModel.FontBoldWeight.Normal); cellStyle.SetFont(cellFont); } return(cellStyle); }