private static GemBoxCellStyle ConvertStyle(CellStyle style) { var resultStyle = new GemBoxCellStyle(); resultStyle.Borders.SetBorders( MultipleBorders.Top, style.Style.BorderTopColor, ConvertLineStyle(style.Style.BorderTopStyle)); resultStyle.Borders.SetBorders( MultipleBorders.Right, style.Style.BorderRightColor, ConvertLineStyle(style.Style.BorderRightStyle)); resultStyle.Borders.SetBorders( MultipleBorders.Bottom, style.Style.BorderBottomColor, ConvertLineStyle(style.Style.BorderBottomStyle)); resultStyle.Borders.SetBorders( MultipleBorders.Left, style.Style.BorderLeftColor, ConvertLineStyle(style.Style.BorderLeftStyle)); resultStyle.FillPattern.PatternStyle = FillPatternStyle.Solid; resultStyle.FillPattern.PatternForegroundColor = style.Style.BackgroundColor; resultStyle.Font.Color = style.Style.Color.Value; resultStyle.Font.Italic = style.Style.IsItalic; resultStyle.Font.Name = style.Style.Font; resultStyle.Font.Size = style.Style.FontSize * 20; resultStyle.Font.Strikeout = style.Style.IsLineThrough; resultStyle.Font.UnderlineStyle = style.Style.IsUnderline ? UnderlineStyle.Single : UnderlineStyle.None; resultStyle.Font.Weight = style.Style.IsBold ? ExcelFont.BoldWeight : ExcelFont.NormalWeight; resultStyle.HorizontalAlignment = (HorizontalAlignmentStyle)style.Style.HAlign.Value; resultStyle.VerticalAlignment = (VerticalAlignmentStyle)style.Style.VAlign.Value; resultStyle.NumberFormat = style.NumberFormat; resultStyle.WrapText = true; return resultStyle; }
private static GemBoxCellStyle ConvertStyle(CellStyle style) { var resultStyle = new GemBoxCellStyle(); if (style.Style.BorderTopColor.HasValue && style.Style.BorderTopStyle.HasValue) { resultStyle.Borders.SetBorders( MultipleBorders.Top, style.Style.BorderTopColor, ConvertLineStyle(style.Style.BorderTopStyle)); } if (style.Style.BorderRightColor.HasValue && style.Style.BorderRightStyle.HasValue) { resultStyle.Borders.SetBorders( MultipleBorders.Right, style.Style.BorderRightColor, ConvertLineStyle(style.Style.BorderRightStyle)); } if (style.Style.BorderBottomColor.HasValue && style.Style.BorderBottomStyle.HasValue) { resultStyle.Borders.SetBorders( MultipleBorders.Bottom, style.Style.BorderBottomColor, ConvertLineStyle(style.Style.BorderBottomStyle)); } if (style.Style.BorderLeftColor.HasValue && style.Style.BorderLeftStyle.HasValue) { resultStyle.Borders.SetBorders( MultipleBorders.Left, style.Style.BorderLeftColor, ConvertLineStyle(style.Style.BorderLeftStyle)); } SetValueHelper(style.Style.BackgroundColor, value => { resultStyle.FillPattern.PatternStyle = FillPatternStyle.Solid; resultStyle.FillPattern.PatternForegroundColor = value; }); SetValueHelper(style.Style.Color, value => { resultStyle.Font.Color = value; }); SetValueHelper(style.Style.IsItalic, value => { resultStyle.Font.Italic = value; }); SetValueHelper(style.Style.Font, value => { resultStyle.Font.Name = value; }); SetValueHelper(style.Style.FontSize, value => { resultStyle.Font.Size = value * 20; }); SetValueHelper(style.Style.IsLineThrough, value => { resultStyle.Font.Strikeout = value; }); SetValueHelper(style.Style.IsUnderline, value => { resultStyle.Font.UnderlineStyle = value ? UnderlineStyle.Single : UnderlineStyle.None; }); SetValueHelper(style.Style.IsBold, value => { resultStyle.Font.Weight = value ? ExcelFont.BoldWeight : ExcelFont.NormalWeight; }); if (style.Style.HAlign.HasValue) { switch (style.Style.HAlign.Value) { case HAlign.Center: resultStyle.HorizontalAlignment = HorizontalAlignmentStyle.Center; break; case HAlign.Justify: resultStyle.HorizontalAlignment = HorizontalAlignmentStyle.Justify; break; case HAlign.Left: resultStyle.HorizontalAlignment = HorizontalAlignmentStyle.Left; break; case HAlign.Right: resultStyle.HorizontalAlignment = HorizontalAlignmentStyle.Right; break; } } if (style.Style.VAlign.HasValue) { switch (style.Style.VAlign.Value) { case VAlign.Bottom: resultStyle.VerticalAlignment = VerticalAlignmentStyle.Bottom; break; case VAlign.Middle: resultStyle.VerticalAlignment = VerticalAlignmentStyle.Center; break; case VAlign.Top: resultStyle.VerticalAlignment = VerticalAlignmentStyle.Top; break; } } if (!string.IsNullOrWhiteSpace(style.NumberFormat)) { resultStyle.NumberFormat = style.NumberFormat; } resultStyle.WrapText = true; return(resultStyle); }