private CellFormat GetCellFormat(BsGridExcelStyle style, out int formatId) { if (style.FillId.HasValue && style.FontId.HasValue) { foreach (var item in cellFormats) { if (item.AreEqual(style)) { formatId = cellFormats.IndexOf(item); return(null); } } var cellFormat = ExcelHelpers.CreateCellFormat((UInt32)style.FontId, (UInt32)style.FillId); cellFormats.Add(style); formatId = cellFormats.IndexOf(style); return(cellFormat); } else { int fontId; var font = GetFont(style, out fontId); if (font != null) { styleSheet.Fonts.Append(font); } int fillId; var fill = GetFill(style, out fillId); if (fill != null) { styleSheet.Fills.Append(fill); } var formatStyle = new BsGridExcelStyle() { FontId = fontId, FillId = fillId }; return(GetCellFormat(formatStyle, out formatId)); } }