コード例 #1
0
        internal static WorksheetRangeStyle FindCellParentStyle(Worksheet sheet, int row, int col, out StyleParentKind pKind)
        {
            RowHeader rowhead = sheet.RetrieveRowHeader(row);

            if (rowhead == null)
            {
                pKind = new StyleParentKind();
                return(new WorksheetRangeStyle());
            }

            if (rowhead.InnerStyle != null)
            {
                pKind = StyleParentKind.Row;
                return(rowhead.InnerStyle);
            }
            else
            {
                ColumnHeader colhead = sheet.RetrieveColumnHeader(col);

                if (colhead.InnerStyle != null)
                {
                    pKind = StyleParentKind.Col;
                    return(colhead.InnerStyle);
                }
                else
                {
                    pKind = StyleParentKind.Root;
                    return(sheet.RootStyle);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Remove repeated styles if it does same as default style.
        /// This function also can be used to create a default style for specified cell.
        /// </summary>
        /// <param name="grid">Instance of worksheet.</param>
        /// <param name="cell">The style from this cell will be checked.</param>
        /// <returns>Checked style, null if given cell or style of cell is null.</returns>
        internal static WorksheetRangeStyle CheckAndRemoveCellStyle(Worksheet grid, Cell cell)
        {
            if (cell.InnerStyle == null || cell.InnerStyle == null)
            {
                return(null);
            }

            // if cell keeps parent style, then return null (means no cell own styles existed)
            if (cell.StyleParentKind == StyleParentKind.Root ||
                cell.StyleParentKind == StyleParentKind.Col ||
                cell.StyleParentKind == StyleParentKind.Row)
            {
                return(null);
            }

            int row = cell.InternalRow;
            int col = cell.InternalCol;

            WorksheetRangeStyle style = cell.InnerStyle;

            StyleParentKind     pKind        = StyleParentKind.Own;
            WorksheetRangeStyle defaultStyle = FindCellParentStyle(grid, row, col, out pKind);

            return(DistinctStyle(style, defaultStyle));
        }
コード例 #3
0
ファイル: Cell.cs プロジェクト: bezzad/ReoGrid
        internal void CreateOwnStyle()
        {
            this.InnerStyle = new WorksheetRangeStyle(this.InnerStyle);

            this.StyleParentKind = StyleParentKind.Own;

#if DEBUG
            if ((++_count % 50) == 0)
            {
                unvell.Common.Logger.Log("style", "new style created, count: " + _count);
            }
#endif // DEBUG
        }
コード例 #4
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);
        }