internal RGXmlHBorder(int row, int col, int cols, RangeBorderStyle borderStyle, HBorderOwnerPosition pos) : base(row, col, borderStyle, XmlFileFormatHelper.EncodeHBorderOwnerPos(pos)) { this.cols = cols; }
internal RGXmlVBorder(int row, int col, int rows, RangeBorderStyle borderStyle, VBorderOwnerPosition pos) : base(row, col, borderStyle, XmlFileFormatHelper.EncodeVBorderOwnerPos(pos)) { this.rows = rows; }
public RSCellStyleObject(Worksheet sheet, Cell cell) { this.sheet = sheet; this.Cell = cell; this["backgroundColor"] = new ExternalProperty( () => TextFormatHelper.EncodeColor(cell.InnerStyle.BackColor), (v) => { SolidColor color; if (TextFormatHelper.DecodeColor(ScriptRunningMachine.ConvertToString(v), out color)) { this.sheet.SetCellStyleOwn(cell.InternalPos, new WorksheetRangeStyle { Flag = PlainStyleFlag.BackColor, BackColor = color, }); this.sheet.RequestInvalidate(); } }); this["color"] = new ExternalProperty( () => TextFormatHelper.EncodeColor(cell.InnerStyle.TextColor), (v) => { SolidColor color; if (TextFormatHelper.DecodeColor(ScriptRunningMachine.ConvertToString(v), out color)) { this.sheet.SetCellStyleOwn(cell.InternalPos, new WorksheetRangeStyle { Flag = PlainStyleFlag.TextColor, TextColor = color, }); this.sheet.RequestInvalidate(); } }); this["fontName"] = new ExternalProperty(() => cell.Style.FontName, (v) => cell.Style.FontName = ScriptRunningMachine.ConvertToString(v)); this["fontSize"] = new ExternalProperty( () => cell.Style.FontSize, (v) => cell.Style.FontSize = TextFormatHelper.GetFloatPixelValue(ScriptRunningMachine.ConvertToString(v), System.Drawing.SystemFonts.DefaultFont.Size)); this["align"] = new ExternalProperty( () => cell.Style.HAlign, (v) => { this.sheet.SetCellStyleOwn(cell.InternalPos, new WorksheetRangeStyle { Flag = PlainStyleFlag.HorizontalAlign, HAlign = XmlFileFormatHelper.DecodeHorizontalAlign(ScriptRunningMachine.ConvertToString(v)), }); this.sheet.RequestInvalidate(); }); this["valign"] = new ExternalProperty( () => cell.Style.VAlign, (v) => { this.sheet.SetCellStyleOwn(cell.InternalPos, new WorksheetRangeStyle { Flag = PlainStyleFlag.VerticalAlign, VAlign = XmlFileFormatHelper.DecodeVerticalAlign(ScriptRunningMachine.ConvertToString(v)), }); this.sheet.RequestInvalidate(); }); }
/// <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 static WorksheetRangeStyle ConvertFromXmlStyle(Worksheet grid, RGXmlCellStyle xmlStyle, CultureInfo culture) { WorksheetRangeStyle style = new WorksheetRangeStyle(); if (xmlStyle == null) { return(style); } // back color if (!string.IsNullOrEmpty(xmlStyle.backColor)) { SolidColor color; if (TextFormatHelper.DecodeColor(xmlStyle.backColor, out color)) { style.Flag |= PlainStyleFlag.BackColor; style.BackColor = color; } } // fill pattern if (xmlStyle.fillPattern != null) { SolidColor color; if (TextFormatHelper.DecodeColor(xmlStyle.fillPattern.color, out color)) { style.Flag |= PlainStyleFlag.FillPattern; style.FillPatternColor = color; style.FillPatternStyle = (HatchStyles)xmlStyle.fillPattern.patternStyleId; } } // text color if (!string.IsNullOrEmpty(xmlStyle.textColor)) { SolidColor color; if (TextFormatHelper.DecodeColor(xmlStyle.textColor, out color)) { style.Flag |= PlainStyleFlag.TextColor; style.TextColor = color; } } // horizontal align if (!string.IsNullOrEmpty(xmlStyle.hAlign)) { style.Flag |= PlainStyleFlag.HorizontalAlign; style.HAlign = XmlFileFormatHelper.DecodeHorizontalAlign(xmlStyle.hAlign); } // vertical align if (!string.IsNullOrEmpty(xmlStyle.vAlign)) { style.Flag |= PlainStyleFlag.VerticalAlign; style.VAlign = XmlFileFormatHelper.DecodeVerticalAlign(xmlStyle.vAlign); } // font name if (!string.IsNullOrEmpty(xmlStyle.font)) { style.Flag |= PlainStyleFlag.FontName; style.FontName = xmlStyle.font; } // font size if (xmlStyle.fontSize != null) { style.Flag |= PlainStyleFlag.FontSize; style.FontSize = TextFormatHelper.GetFloatValue(xmlStyle.fontSize, grid.RootStyle.FontSize, culture); } // bold if (xmlStyle.bold != null) { style.Flag |= PlainStyleFlag.FontStyleBold; style.Bold = xmlStyle.bold == "true"; } // italic if (xmlStyle.italic != null) { style.Flag |= PlainStyleFlag.FontStyleItalic; style.Italic = xmlStyle.italic == "true"; } // strikethrough if (xmlStyle.strikethrough != null) { style.Flag |= PlainStyleFlag.FontStyleStrikethrough; style.Strikethrough = xmlStyle.strikethrough == "true"; } // underline if (xmlStyle.underline != null) { style.Flag |= PlainStyleFlag.FontStyleUnderline; style.Underline = xmlStyle.underline == "true"; } // text-wrap if (!string.IsNullOrEmpty(xmlStyle.textWrap)) { style.Flag |= PlainStyleFlag.TextWrap; style.TextWrapMode = XmlFileFormatHelper.DecodeTextWrapMode(xmlStyle.textWrap); } // padding if (!string.IsNullOrEmpty(xmlStyle.indent)) { style.Flag |= PlainStyleFlag.Indent; int indent = TextFormatHelper.GetPixelValue(xmlStyle.indent, 0); if (indent > 0 && indent < 65535) { style.Indent = (ushort)indent; } } // padding if (!string.IsNullOrEmpty(xmlStyle.padding)) { style.Flag |= PlainStyleFlag.Padding; style.Padding = TextFormatHelper.DecodePadding(xmlStyle.padding); } // rotate angle int angle; if (!string.IsNullOrEmpty(xmlStyle.rotateAngle) && int.TryParse(xmlStyle.rotateAngle, out angle)) { style.Flag |= PlainStyleFlag.RotationAngle; style.RotationAngle = angle; } return(style); }
internal static RGXmlCellStyle ConvertToXmlStyle(WorksheetRangeStyle style) { if (style == null || style.Flag == PlainStyleFlag.None) { return(null); } RGXmlCellStyle xmlStyle = new RGXmlCellStyle(); if (StyleUtility.HasStyle(style, PlainStyleFlag.BackColor)) { xmlStyle.backColor = TextFormatHelper.EncodeColor(style.BackColor); } if (HasStyle(style, PlainStyleFlag.FillPattern)) { RGXmlCellStyleFillPattern xmlFillPattern = new RGXmlCellStyleFillPattern() { color = TextFormatHelper.EncodeColor(style.FillPatternColor), patternStyleId = (int)style.FillPatternStyle, }; xmlStyle.fillPattern = xmlFillPattern; } if (StyleUtility.HasStyle(style, PlainStyleFlag.TextColor)) { xmlStyle.textColor = TextFormatHelper.EncodeColor(style.TextColor); } if (StyleUtility.HasStyle(style, PlainStyleFlag.FontName)) { xmlStyle.font = style.FontName; } if (StyleUtility.HasStyle(style, PlainStyleFlag.FontSize)) { xmlStyle.fontSize = style.FontSize.ToString(); } if (StyleUtility.HasStyle(style, PlainStyleFlag.FontStyleBold)) { xmlStyle.bold = style.Bold.ToString().ToLower(); } if (StyleUtility.HasStyle(style, PlainStyleFlag.FontStyleItalic)) { xmlStyle.italic = style.Italic.ToString().ToLower(); } if (StyleUtility.HasStyle(style, PlainStyleFlag.FontStyleStrikethrough)) { xmlStyle.strikethrough = style.Strikethrough.ToString().ToLower(); } if (StyleUtility.HasStyle(style, PlainStyleFlag.FontStyleUnderline)) { xmlStyle.underline = style.Underline.ToString().ToLower(); } if (StyleUtility.HasStyle(style, PlainStyleFlag.HorizontalAlign)) { xmlStyle.hAlign = XmlFileFormatHelper.EncodeHorizontalAlign(style.HAlign); } if (StyleUtility.HasStyle(style, PlainStyleFlag.VerticalAlign)) { xmlStyle.vAlign = XmlFileFormatHelper.EncodeVerticalAlign(style.VAlign); } if (StyleUtility.HasStyle(style, PlainStyleFlag.TextWrap)) { xmlStyle.textWrap = XmlFileFormatHelper.EncodeTextWrapMode(style.TextWrapMode); } if (StyleUtility.HasStyle(style, PlainStyleFlag.Indent)) { xmlStyle.indent = style.Indent.ToString(); } if (StyleUtility.HasStyle(style, PlainStyleFlag.Padding)) { xmlStyle.padding = TextFormatHelper.EncodePadding(style.Padding); } if (StyleUtility.HasStyle(style, PlainStyleFlag.RotationAngle)) { xmlStyle.rotateAngle = style.RotationAngle.ToString(); } return(xmlStyle); }