/// <summary> /// Convert to union font style flag from worksheet styleset object. /// </summary> /// <param name="style"></param> /// <returns></returns> public static FontStyles CreateFontStyle(WorksheetRangeStyle style) { FontStyles fontStyle = FontStyles.Regular; if (style.HasStyle(PlainStyleFlag.FontStyleBold) && style.Bold) { fontStyle |= FontStyles.Bold; } if (style.HasStyle(PlainStyleFlag.FontStyleItalic) && style.Italic) { fontStyle |= FontStyles.Italic; } if (style.HasStyle(PlainStyleFlag.FontStyleStrikethrough) && style.Strikethrough) { fontStyle |= FontStyles.Strikethrough; } if (style.HasStyle(PlainStyleFlag.FontStyleUnderline) && style.Underline) { fontStyle |= FontStyles.Underline; } return(fontStyle); }
/// <summary> /// Export grid as html5 into specified stream /// </summary> /// <param name="s">Stream contains the exported HTML5 content</param> /// <param name="sheet">Instance of worksheet</param> /// <param name="pageTitle">Custom page title of HTML page</param> /// <param name="htmlHeader">True to export default HTML header tag; false to export table content only</param> public static void Export(Stream s, Worksheet sheet, string pageTitle, bool htmlHeader = true) { using (StreamWriter sw = new StreamWriter(s)) { StringBuilder sb = new StringBuilder(); Cell cell; if (htmlHeader) { sw.WriteLine("<!DOCTYPE html>"); sw.WriteLine("<html>"); sw.WriteLine("<head>"); sw.WriteLine(" <title>{0}</title>", pageTitle); sw.WriteLine(" <meta content=\"text/html; charset=UTF-8\">"); sw.WriteLine("</head>"); sw.WriteLine("<body>"); } sw.WriteLine(" <table style='border-collapse:collapse;border:none;'>"); int maxRow = sheet.MaxContentRow; int maxCol = sheet.MaxContentCol; for (int r = 0; r <= maxRow; r++) { var row = sheet.RetrieveRowHeader(r); sw.WriteLine(string.Format(" <tr style='height:{0}px;'>", row.InnerHeight)); for (int c = 0; c <= maxCol;) { var col = sheet.RetrieveColumnHeader(c); cell = sheet.GetCell(r, c); if (cell != null && (cell.Colspan <= 0 || cell.Rowspan <= 0)) { c++; continue; } sb.Length = 0; sb.Append(" <td"); if (cell != null && cell.Rowspan > 1) { sb.Append(" rowspan='" + cell.Rowspan + "'"); } if (cell != null && cell.Colspan > 1) { sb.Append(" colspan='" + cell.Colspan + "'"); } sb.AppendFormat(" style='width:{0}px;", cell == null ? col.Width : cell.Width); bool halignOutputted = false; if (cell != null) { // render horizontal align if (cell.RenderHorAlign == ReoGridRenderHorAlign.Right) { WriteHtmlStyle(sb, "text-align", "right"); halignOutputted = true; } else if (cell.RenderHorAlign == ReoGridRenderHorAlign.Center) { WriteHtmlStyle(sb, "text-align", "center"); halignOutputted = true; } } WorksheetRangeStyle style = sheet.GetCellStyles(r, c); if (style != null) { // back color if (style.HasStyle(PlainStyleFlag.BackColor) && style.BackColor != SolidColor.White) { WriteHtmlStyle(sb, "background-color", TextFormatHelper.EncodeColor(style.BackColor)); } // text color if (style.HasStyle(PlainStyleFlag.TextColor) && style.TextColor != SolidColor.Black) { WriteHtmlStyle(sb, "color", TextFormatHelper.EncodeColor(style.TextColor)); } // font size if (style.HasStyle(PlainStyleFlag.FontSize)) { WriteHtmlStyle(sb, "font-size", style.FontSize.ToString() + "pt"); } // horizontal align if (!halignOutputted && style.HasStyle(PlainStyleFlag.HorizontalAlign)) { WriteHtmlStyle(sb, "text-align", XmlFileFormatHelper.EncodeHorizontalAlign(style.HAlign)); } // vertical align if (style.HasStyle(PlainStyleFlag.VerticalAlign)) { WriteHtmlStyle(sb, "vertical-align", XmlFileFormatHelper.EncodeVerticalAlign(style.VAlign)); } } RangeBorderInfoSet rbi = sheet.GetRangeBorders(cell == null ? new RangePosition(r, c, 1, 1) : new RangePosition(cell.InternalRow, cell.InternalCol, cell.Rowspan, cell.Colspan)); if (!rbi.Top.IsEmpty) { WriteCellBorder(sb, "border-top", rbi.Top); } if (!rbi.Left.IsEmpty) { WriteCellBorder(sb, "border-left", rbi.Left); } if (!rbi.Right.IsEmpty) { WriteCellBorder(sb, "border-right", rbi.Right); } if (!rbi.Bottom.IsEmpty) { WriteCellBorder(sb, "border-bottom", rbi.Bottom); } sb.Append("'>"); sw.WriteLine(sb.ToString()); //cell = Grid.GetCell(r, c); string text = null; if (cell != null) { text = string.IsNullOrEmpty(cell.DisplayText) ? " " : #if !CLIENT_PROFILE HtmlEncode(cell.DisplayText) #else cell.DisplayText #endif // CLIENT_PROFILE ; } else { text = " "; } sw.WriteLine(text); sw.WriteLine(" </td>"); c += cell == null ? 1 : cell.Colspan; } sw.WriteLine(" </tr>"); } sw.WriteLine(" </table>"); if (htmlHeader) { sw.WriteLine("</body>"); sw.WriteLine("</html>"); } } }
internal bool Equals(WorksheetRangeStyle styleA, WorksheetRangeStyle styleB) { if (styleA == null && styleB != null || styleA != null && styleB == null || styleA.Flag != styleB.Flag) { return(false); } if (styleA.HasStyle(PlainStyleFlag.BackColor) && styleA.BackColor != styleB.BackColor) { return(false); } if (styleA.HasStyle(PlainStyleFlag.FillPatternColor) && styleA.FillPatternColor != styleB.FillPatternColor) { return(false); } if (styleA.HasStyle(PlainStyleFlag.FillPatternStyle) && styleA.FillPatternStyle != styleB.FillPatternStyle) { return(false); } if (styleA.HasStyle(PlainStyleFlag.TextColor) && styleA.TextColor != styleB.TextColor) { return(false); } if (styleA.HasStyle(PlainStyleFlag.FontName) && styleA.FontName != styleB.FontName) { return(false); } if (styleA.HasStyle(PlainStyleFlag.FontSize) && styleA.FontSize != styleB.FontSize) { return(false); } if (styleA.HasStyle(PlainStyleFlag.FontStyleBold) && styleA.Bold != styleB.Bold) { return(false); } if (styleA.HasStyle(PlainStyleFlag.FontStyleItalic) && styleA.Italic != styleB.Italic) { return(false); } if (styleA.HasStyle(PlainStyleFlag.FontStyleStrikethrough) && styleA.Strikethrough != styleB.Strikethrough) { return(false); } if (styleA.HasStyle(PlainStyleFlag.FontStyleUnderline) && styleA.Underline != styleB.Underline) { return(false); } if (styleA.HasStyle(PlainStyleFlag.HorizontalAlign) && styleA.HAlign != styleB.HAlign) { return(false); } if (styleA.HasStyle(PlainStyleFlag.VerticalAlign) && styleA.VAlign != styleB.VAlign) { return(false); } if (styleA.HasStyle(PlainStyleFlag.TextWrap) && styleA.TextWrapMode != styleB.TextWrapMode) { return(false); } if (styleA.HasStyle(PlainStyleFlag.Indent) && styleA.Indent != styleB.Indent) { return(false); } if (styleA.HasStyle(PlainStyleFlag.Padding) && styleA.Padding != styleB.Padding) { return(false); } if (styleA.HasStyle(PlainStyleFlag.RotationAngle) && styleA.RotationAngle != styleB.RotationAngle) { return(false); } return(true); }