示例#1
0
        /// <summary>
        /// Gets a borders object that should be used for rendering.
        /// </summary>
        /// <exception cref="System.ArgumentException">
        ///   Thrown when the cell is not in this list.
        ///   This situation occurs if the given cell is merged "away" by a previous one.
        /// </exception>
        public Borders GetEffectiveBorders(Cell cell)
        {
            CellInfo cellInfo = this.CellIndex[cell] as CellInfo;

            if (cellInfo == null)
            {
                throw new ArgumentException("cell is not a relevant cell", "cell");
            }

            if (cellInfo.Borders == null)
            {
                Borders borders = GetCellBorders(cell);
                if (borders != null)
                {
                    Document doc = borders.Document;
                    borders        = borders.Clone();
                    borders.parent = cell;
                    doc            = borders.Document;
                }
                else
                {
                    borders = new Borders(cell.parent);
                }

                if (cell.mergeRight > 0)
                {
                    Cell rightBorderCell = cell.Table[cell.Row.Index, cell.Column.Index + cell.mergeRight];
                    if (rightBorderCell.borders != null && rightBorderCell.borders.right != null)
                    {
                        borders.Right = rightBorderCell.borders.right.Clone();
                    }
                    else
                    {
                        borders.right = null;
                    }
                }

                if (cell.mergeDown > 0)
                {
                    Cell bottomBorderCell = cell.Table[cell.Row.Index + cell.mergeDown, cell.Column.Index];
                    if (bottomBorderCell.borders != null && bottomBorderCell.borders.bottom != null)
                    {
                        borders.Bottom = bottomBorderCell.borders.bottom.Clone();
                    }
                    else
                    {
                        borders.bottom = null;
                    }
                }

                Cell leftNeighbor   = GetNeighbor(cellInfo, NeighborPosition.Left);
                Cell rightNeighbor  = GetNeighbor(cellInfo, NeighborPosition.Right);
                Cell topNeighbor    = GetNeighbor(cellInfo, NeighborPosition.Top);
                Cell bottomNeighbor = GetNeighbor(cellInfo, NeighborPosition.Bottom);
                if (leftNeighbor != null)
                {
                    Borders nbrBrdrs = GetCellBorders(leftNeighbor);
                    if (nbrBrdrs != null &&
                        GetEffectiveBorderWidth(nbrBrdrs, BorderType.Right) >= GetEffectiveBorderWidth(borders, BorderType.Left))
                    {
                        borders.SetValue("Left", GetBorderFromBorders(nbrBrdrs, BorderType.Right));
                    }
                }
                if (rightNeighbor != null)
                {
                    Borders nbrBrdrs = GetCellBorders(rightNeighbor);
                    if (nbrBrdrs != null &&
                        GetEffectiveBorderWidth(nbrBrdrs, BorderType.Left) > GetEffectiveBorderWidth(borders, BorderType.Right))
                    {
                        borders.SetValue("Right", GetBorderFromBorders(nbrBrdrs, BorderType.Left));
                    }
                }
                if (topNeighbor != null)
                {
                    Borders nbrBrdrs = GetCellBorders(topNeighbor);
                    if (nbrBrdrs != null &&
                        GetEffectiveBorderWidth(nbrBrdrs, BorderType.Bottom) >= GetEffectiveBorderWidth(borders, BorderType.Top))
                    {
                        borders.SetValue("Top", GetBorderFromBorders(nbrBrdrs, BorderType.Bottom));
                    }
                }
                if (bottomNeighbor != null)
                {
                    Borders nbrBrdrs = GetCellBorders(bottomNeighbor);
                    if (nbrBrdrs != null &&
                        GetEffectiveBorderWidth(nbrBrdrs, BorderType.Top) > GetEffectiveBorderWidth(borders, BorderType.Bottom))
                    {
                        borders.SetValue("Bottom", GetBorderFromBorders(nbrBrdrs, BorderType.Top));
                    }
                }

                cellInfo.Borders = borders;
            }
            return(cellInfo.Borders);
        }