private void InitializeTheme() { Theme = new XLTheme { Text1 = XLColor.FromHtml("#FF000000"), Background1 = XLColor.FromHtml("#FFFFFFFF"), Text2 = XLColor.FromHtml("#FF1F497D"), Background2 = XLColor.FromHtml("#FFEEECE1"), Accent1 = XLColor.FromHtml("#FF4F81BD"), Accent2 = XLColor.FromHtml("#FFC0504D"), Accent3 = XLColor.FromHtml("#FF9BBB59"), Accent4 = XLColor.FromHtml("#FF8064A2"), Accent5 = XLColor.FromHtml("#FF4BACC6"), Accent6 = XLColor.FromHtml("#FFF79646"), Hyperlink = XLColor.FromHtml("#FF0000FF"), FollowedHyperlink = XLColor.FromHtml("#FF800080") }; }
public String GetHFText(String prevText) { var wsFont = _hfItem.HeaderFooter.Worksheet.Style.Font; var isRichText = RichText.FontName != null && RichText.FontName != wsFont.FontName || RichText.Bold != wsFont.Bold || RichText.Italic != wsFont.Italic || RichText.Strikethrough != wsFont.Strikethrough || RichText.FontSize > 0 && Math.Abs(RichText.FontSize - wsFont.FontSize) > XLHelper.Epsilon || RichText.VerticalAlignment != wsFont.VerticalAlignment || RichText.Underline != wsFont.Underline || !RichText.FontColor.Equals(wsFont.FontColor); if (!isRichText) { return(RichText.Text); } StringBuilder sb = new StringBuilder(); if (RichText.FontName != null && RichText.FontName != wsFont.FontName) { sb.Append("&\"" + RichText.FontName); } else { sb.Append("&\"-"); } if (RichText.Bold && RichText.Italic) { sb.Append(",Bold Italic\""); } else if (RichText.Bold) { sb.Append(",Bold\""); } else if (RichText.Italic) { sb.Append(",Italic\""); } else { sb.Append(",Regular\""); } if (RichText.FontSize > 0 && Math.Abs(RichText.FontSize - wsFont.FontSize) > XLHelper.Epsilon) { sb.Append("&" + RichText.FontSize); } if (RichText.Strikethrough && !wsFont.Strikethrough) { sb.Append("&S"); } if (RichText.VerticalAlignment != wsFont.VerticalAlignment) { if (RichText.VerticalAlignment == XLFontVerticalTextAlignmentValues.Subscript) { sb.Append("&Y"); } else if (RichText.VerticalAlignment == XLFontVerticalTextAlignmentValues.Superscript) { sb.Append("&X"); } } if (RichText.Underline != wsFont.Underline) { if (RichText.Underline == XLFontUnderlineValues.Single) { sb.Append("&U"); } else if (RichText.Underline == XLFontUnderlineValues.Double) { sb.Append("&E"); } } var lastColorPosition = prevText.LastIndexOf("&K"); if ( (lastColorPosition >= 0 && !RichText.FontColor.Equals(XLColor.FromHtml("#" + prevText.Substring(lastColorPosition + 2, 6)))) || (lastColorPosition == -1 && !RichText.FontColor.Equals(wsFont.FontColor)) ) { sb.Append("&K" + RichText.FontColor.Color.ToHex().Substring(2)); } sb.Append(RichText.Text); if (RichText.Underline != wsFont.Underline) { if (RichText.Underline == XLFontUnderlineValues.Single) { sb.Append("&U"); } else if (RichText.Underline == XLFontUnderlineValues.Double) { sb.Append("&E"); } } if (RichText.VerticalAlignment != wsFont.VerticalAlignment) { if (RichText.VerticalAlignment == XLFontVerticalTextAlignmentValues.Subscript) { sb.Append("&Y"); } else if (RichText.VerticalAlignment == XLFontVerticalTextAlignmentValues.Superscript) { sb.Append("&X"); } } if (RichText.Strikethrough && !wsFont.Strikethrough) { sb.Append("&S"); } return(sb.ToString()); }
static XLColor Func(Color2Type color) { return(color.SystemColor != null?XLColor.FromHtml("#FF" + color.SystemColor.LastColor) : color.RgbColorModelHex != null?XLColor.FromHtml("#FF" + color.RgbColorModelHex.Val) : XLColor.FromHtml("#FF000000")); }