コード例 #1
0
        public void DuplicateBorder()
        {
            SetUp();

            var range = new RangePosition(4, 4, 4, 4);

            worksheet.SetRangeBorders(range, BorderPositions.All, RangeBorderStyle.BlackSolid);

            var subgrid = worksheet.GetPartialGrid(range);

            worksheet[0, 4] = subgrid;             // top
            worksheet[4, 0] = subgrid;             // left
            worksheet[8, 4] = subgrid;             // bottom
            worksheet[4, 8] = subgrid;             // right
            AssertTrue(worksheet._Debug_Validate_All());

            // top
            RangeBorderInfoSet border = worksheet.GetRangeBorders(new RangePosition(0, 4, 4, 4));

            AssertEquals(border.Top.Style, BorderLineStyle.Solid);
            AssertEquals(border.Left.Style, BorderLineStyle.Solid);
            AssertEquals(border.Right.Style, BorderLineStyle.Solid);
            AssertEquals(border.Bottom.Style, BorderLineStyle.Solid);
            AssertEquals(border.NonUniformPos, BorderPositions.None);             // border at all positions are same

            // left
            border = worksheet.GetRangeBorders(new RangePosition(4, 0, 4, 4));
            AssertEquals(border.Top.Style, BorderLineStyle.Solid);
            AssertEquals(border.Left.Style, BorderLineStyle.Solid);
            AssertEquals(border.Right.Style, BorderLineStyle.Solid);
            AssertEquals(border.Bottom.Style, BorderLineStyle.Solid);
            AssertEquals(border.NonUniformPos, BorderPositions.None);             // border at all positions are same

            // bottom
            border = worksheet.GetRangeBorders(new RangePosition(8, 4, 4, 4));
            AssertEquals(border.Top.Style, BorderLineStyle.Solid);
            AssertEquals(border.Left.Style, BorderLineStyle.Solid);
            AssertEquals(border.Right.Style, BorderLineStyle.Solid);
            AssertEquals(border.Bottom.Style, BorderLineStyle.Solid);
            AssertEquals(border.NonUniformPos, BorderPositions.None);             // border at all positions are same

            // right
            border = worksheet.GetRangeBorders(new RangePosition(4, 8, 4, 4));
            AssertEquals(border.Top.Style, BorderLineStyle.Solid);
            AssertEquals(border.Left.Style, BorderLineStyle.Solid);
            AssertEquals(border.Right.Style, BorderLineStyle.Solid);
            AssertEquals(border.Bottom.Style, BorderLineStyle.Solid);
            AssertEquals(border.NonUniformPos, BorderPositions.None);             // border at all positions are same
        }
コード例 #2
0
        /// <summary>
        /// Load border info from spreadsheet
        /// </summary>
        /// <param name="sheet">current worksheet instance</param>
        public void ReadFromGrid(ReoGridControl grid)
        {
            var sheet = grid.CurrentWorksheet;

            if (sheet.SelectionRange.IsEmpty)
            {
                this.Enabled = false;
            }
            else
            {
                RangeBorderInfoSet info = sheet.GetRangeBorders(sheet.SelectionRange, BorderPositions.All, false);

                if (!info.Left.IsEmpty)
                {
                    borders[BorderPositions.Left] = info.Left;
                }
                if (!info.Right.IsEmpty)
                {
                    borders[BorderPositions.Right] = info.Right;
                }
                if (!info.Top.IsEmpty)
                {
                    borders[BorderPositions.Top] = info.Top;
                }
                if (!info.Bottom.IsEmpty)
                {
                    borders[BorderPositions.Bottom] = info.Bottom;
                }
                if (!info.InsideHorizontal.IsEmpty)
                {
                    borders[BorderPositions.InsideHorizontal] = info.InsideHorizontal;
                }
                if (!info.InsideVertical.IsEmpty)
                {
                    borders[BorderPositions.InsideVertical] = info.InsideVertical;
                }

                rows = sheet.SelectionRange.Rows > 2 ? 2 : sheet.SelectionRange.Rows;
                cols = sheet.SelectionRange.Cols > 2 ? 2 : sheet.SelectionRange.Cols;

                mixBorders |= info.NonUniformPos;
            }
        }
コード例 #3
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>");
                }
            }
        }