コード例 #1
0
ファイル: XMLFileFormat.cs プロジェクト: bezzad/ReoGrid
            internal RGXmlBorder(int row, int col, RangeBorderStyle borderStyle, string pos)
            {
                this.row = row;
                this.col = col;
                this.pos = pos;

                if (borderStyle.Color != SolidColor.Black)
                {
                    color = TextFormatHelper.EncodeColor(borderStyle.Color);
                }
                if (borderStyle.Style != BorderLineStyle.Solid)
                {
                    style = borderStyle.Style.ToString();
                }
            }
コード例 #2
0
        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();
            });
        }
コード例 #3
0
ファイル: HTMLExporter.cs プロジェクト: fredatgithub/ReoGrid
 private static void WriteCellBorder(StringBuilder sb, string name, RangeBorderStyle borderStyle)
 {
     WriteHtmlStyle(sb, name, string.Format("{0} {1}",
                                            ToHTMLBorderLineStyle(borderStyle.Style), TextFormatHelper.EncodeColor(borderStyle.Color)));
 }
コード例 #4
0
ファイル: HTMLExporter.cs プロジェクト: fredatgithub/ReoGrid
        /// <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) ? "&nbsp;" :
#if !CLIENT_PROFILE
                                   HtmlEncode(cell.DisplayText)
#else
                                   cell.DisplayText
#endif // CLIENT_PROFILE
                            ;
                        }
                        else
                        {
                            text = "&nbsp;";
                        }

                        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>");
                }
            }
        }
コード例 #5
0
ファイル: StyleUtility.cs プロジェクト: datadiode/ReoGrid
        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);
        }