Beispiel #1
0
        private string GetBorderInfo(int r, int c, BorderPositions borderPos)
        {
            StringBuilder sb = new StringBuilder();

            if ((borderPos & BorderPositions.Top) > 0)
            {
                ReoGridHBorder top = grid.RetrieveHBorder(r, c);
                sb.AppendLine(string.Format("Top   [{0,3},{1,3}]", r, c));

                if (top != null)
                {
                    sb.AppendLine(string.Format("Cols  [{0,7}]", top.Span));
                    sb.AppendLine(string.Format("Pos   [{0,7}]", top.Pos));
                    sb.AppendLine(string.Format("Style [{0,7}]", top.Style == null ? "" : " YES "));
                }
                else
                {
                    sb.AppendLine("Empty");
                }
            }
            if ((borderPos & BorderPositions.Bottom) > 0)
            {
                ReoGridHBorder bottom = grid.RetrieveHBorder(r + 1, c);
                sb.AppendLine(string.Format("Bottom[{0,3},{1,3}]", r + 1, c));

                if (bottom != null)
                {
                    sb.AppendLine(string.Format("Cols  [{0,7}]", bottom.Span));
                    sb.AppendLine(string.Format("Pos   [{0,7}]", bottom.Pos));
                    sb.AppendLine(string.Format("Style [{0,7}]", bottom.Style == null ? "" : " YES "));
                }
                else
                {
                    sb.AppendLine("Empty");
                }
            }
            if ((borderPos & BorderPositions.Left) > 0)
            {
                ReoGridVBorder left = grid.RetrieveVBorder(r, c);
                sb.AppendLine(string.Format("Left  [{0,3},{1,3}]", r, c));

                if (left != null)
                {
                    sb.AppendLine(string.Format("Rows  [{0,7}]", left.Span));
                    sb.AppendLine(string.Format("Pos   [{0,7}]", left.Pos));
                    sb.AppendLine(string.Format("Style [{0,7}]", left.Style == null ? "" : " YES "));
                }
                else
                {
                    sb.AppendLine("Empty");
                }
            }
            if ((borderPos & BorderPositions.Right) > 0)
            {
                ReoGridVBorder right = grid.RetrieveVBorder(r, c + 1);
                sb.AppendLine(string.Format("Right [{0,3},{1,3}]", r, c + 1));

                if (right != null)
                {
                    sb.AppendLine(string.Format("Rows  [{0,7}]", right.Span));
                    sb.AppendLine(string.Format("Pos   [{0,7}]", right.Pos));
                    sb.AppendLine(string.Format("Style [{0,7}]", right.Style == null ? "" : " YES "));
                }
                else
                {
                    sb.AppendLine("Empty");
                }
            }
            return(sb.ToString());
        }
Beispiel #2
0
        internal PartialGrid GetPartialGrid(RangePosition range, PartialGridCopyFlag flag, ExPartialGridCopyFlag exFlag,
                                            bool checkIntersectedRange = false)
        {
            range = FixRange(range);

            if (checkIntersectedRange)
            {
                var intersectedRange = CheckIntersectedMergingRange(range);
                if (intersectedRange != RangePosition.Empty)
                {
                    throw new RangeIntersectionException(intersectedRange);
                }
            }

            int rows = range.Rows;
            int cols = range.Cols;

            PartialGrid data = new PartialGrid()
            {
                Columns = cols,
                Rows    = rows,
            };

            if ((flag & PartialGridCopyFlag.CellData) == PartialGridCopyFlag.CellData ||
                (flag & PartialGridCopyFlag.CellStyle) == PartialGridCopyFlag.CellStyle)
            {
                data.Cells = new CellArray();

                for (int r = range.Row; r <= range.EndRow; r++)
                {
                    for (int c = range.Col; c <= range.EndCol; c++)
                    {
                        var cell = this.cells[r, c];

                        int toRow = r - range.Row;
                        int toCol = c - range.Col;

                        //if (cell == null && data.Cells[toRow, toCol] == null)
                        //{
                        //	c++;
                        //	continue;
                        //}

                        Cell toCell = null;

                        if (cell != null)
                        {
                            toCell = new Cell(this);
                            CellUtility.CopyCell(toCell, cell);
                        }
                        else
                        {
                            StyleParentKind pKind = StyleParentKind.Own;
                            var             style = StyleUtility.FindCellParentStyle(this, r, c, out pKind);

                            style = StyleUtility.DistinctStyle(style, Worksheet.DefaultStyle);

                            if (style != null)
                            {
                                toCell                 = new Cell(this);
                                toCell.Colspan         = 1;
                                toCell.Rowspan         = 1;
                                toCell.InnerStyle      = style;
                                toCell.StyleParentKind = StyleParentKind.Own;
                            }
                        }

                        if (toCell != null)
                        {
                            data.Cells[toRow, toCol] = toCell;
                        }

                        //c += (cell == null || cell.Colspan < 1) ? 1 : cell.Colspan;
                    }
                }
            }

            if ((flag & PartialGridCopyFlag.HBorder) == PartialGridCopyFlag.HBorder)
            {
                data.HBorders = new HBorderArray();

                hBorders.Iterate(range.Row, range.Col, rows + 1, cols, true, (r, c, hBorder) =>
                {
                    // only copy borders they belong to the cell (unless BorderOutsideOwner is specified)
                    if (((exFlag & ExPartialGridCopyFlag.BorderOutsideOwner) == ExPartialGridCopyFlag.BorderOutsideOwner) ||
                        (hBorder != null && hBorder.Pos == HBorderOwnerPosition.None) ||
                        (
                            (r != range.Row ||
                             (hBorder != null &&
                              (hBorder.Pos & HBorderOwnerPosition.Top) == HBorderOwnerPosition.Top))
                            &&
                            (r != range.EndRow + 1 ||
                             (hBorder != null &&
                              (hBorder.Pos & HBorderOwnerPosition.Bottom) == HBorderOwnerPosition.Bottom)))
                        )
                    {
                        int toCol = c - range.Col;
                        ReoGridHBorder thBorder = ReoGridHBorder.Clone(hBorder);
                        if (thBorder != null && thBorder.Span > cols - toCol)
                        {
                            thBorder.Span = cols - toCol;
                        }
                        data.HBorders[r - range.Row, toCol] = thBorder;
                    }
                    return(1);
                });
            }

            if ((flag & PartialGridCopyFlag.VBorder) == PartialGridCopyFlag.VBorder)
            {
                data.VBorders = new VBorderArray();

                vBorders.Iterate(range.Row, range.Col, rows, cols + 1, true, (r, c, vBorder) =>
                {
                    // only copy borders they belong to the cell (unless BorderOutsideOwner is specified)
                    if (((exFlag & ExPartialGridCopyFlag.BorderOutsideOwner) == ExPartialGridCopyFlag.BorderOutsideOwner) ||
                        (vBorder != null && vBorder.Pos == VBorderOwnerPosition.None) ||
                        (
                            (c != range.Col ||
                             (vBorder != null &&
                              (vBorder.Pos & VBorderOwnerPosition.Left) == VBorderOwnerPosition.Left))
                            &&
                            (c != range.EndCol + 1 ||
                             (vBorder != null &&
                              (vBorder.Pos & VBorderOwnerPosition.Right) == VBorderOwnerPosition.Right)))
                        )
                    {
                        int toRow = r - range.Row;
                        ReoGridVBorder tvBorder = ReoGridVBorder.Clone(vBorder);
                        if (tvBorder != null && tvBorder.Span > rows - toRow)
                        {
                            tvBorder.Span = rows - toRow;
                        }
                        data.VBorders[toRow, c - range.Col] = tvBorder;
                    }
                    return(1);
                });
            }

            return(data);
        }
Beispiel #3
0
        internal void MergeRange(RangePosition range, bool checkIntersection = true, bool updateUIAndEvent = true)
        {
            if (range.IsEmpty)
            {
                return;
            }

            RangePosition fixedRange = FixRange(range);

            if (fixedRange.Cols <= 1 && fixedRange.Rows <= 1)
            {
                return;
            }

            if (checkIntersection)
            {
                RangePosition intersectedRange = CheckIntersectedMergingRange(fixedRange);
                if (!intersectedRange.IsEmpty)
                {
                    throw new RangeIntersectionException(intersectedRange);
                }
            }

            int row   = fixedRange.Row;
            int col   = fixedRange.Col;
            int torow = fixedRange.EndRow;
            int tocol = fixedRange.EndCol;

            // find start and end cell
            Cell startCell = cells[row, col];
            Cell endCell   = cells[torow, tocol];

            if (startCell == null)
            {
                startCell = CreateCell(row, col);
            }
            if (endCell == null)
            {
                endCell = CreateCell(torow, tocol);
            }

            for (int r = row; r <= torow; r++)
            {
                for (int c = col; c <= tocol; c++)
                {
                    Cell cell = CreateAndGetCell(r, c);

                    // reference to start and end pos
                    cell.MergeStartPos = startCell.InternalPos;
                    cell.MergeEndPos   = endCell.InternalPos;

                    // close col and row span
                    cell.Colspan = 0;
                    cell.Rowspan = 0;

                    // apply text to merged start cell
                    if (cell != startCell)
                    {
                        cell.InnerData = cell.InnerDisplay = null;
                    }

                    if (r == row)
                    {
                        if (c > col)
                        {
                            CutBeforeVBorder(r, c);
                        }
                    }
                    else
                    {
                        hBorders[r, c] = new ReoGridHBorder {
                            Span = 0
                        };
                    }

                    if (c == col)
                    {
                        if (r > row)
                        {
                            CutBeforeHBorder(r, c);
                        }
                    }
                    else
                    {
                        vBorders[r, c] = new ReoGridVBorder {
                            Span = 0
                        };
                    }
                }
            }

            // update the spans for start cell
            startCell.Rowspan = (short)fixedRange.Rows;
            startCell.Colspan = (short)fixedRange.Cols;

            // fix selection
            if (this.selectionRange.IntersectWith(fixedRange))
            {
                this.selectionRange = this.CheckMergedRange(fixedRange);
            }

            // fix focus pos
            if (fixedRange.Contains(this.focusPos))
            {
                this.focusPos = fixedRange.StartPos;
            }

            if (updateUIAndEvent)
            {
                RequestInvalidate();

                if (RangeMerged != null)
                {
                    RangeMerged(this, new RangeEventArgs(fixedRange));
                }
            }
        }