示例#1
0
        internal Rect GetCellBounds(int p_row, int p_column, bool p_ignoreMerged)
        {
            if (Excel == null)
            {
                return(new Rect());
            }

            // 包含合并情况
            CellLayoutModel model = null;

            if (!p_ignoreMerged)
            {
                model = Excel.GetCellLayoutModel(RowViewportIndex, ColumnViewportIndex, SheetArea.Cells);
            }
            CellLayout layout = (model == null) ? null : model.FindCell(p_row, p_column);

            if (layout != null)
            {
                return(new Rect(layout.X, layout.Y, layout.Width, layout.Height));
            }

            RowLayoutModel    rowLayoutModel    = Excel.GetRowLayoutModel(RowViewportIndex, SheetArea.Cells);
            ColumnLayoutModel columnLayoutModel = Excel.GetColumnLayoutModel(ColumnViewportIndex, SheetArea.Cells);

            if (rowLayoutModel == null || columnLayoutModel == null)
            {
                return(new Rect());
            }

            RowLayout    layout2 = rowLayoutModel.Find(p_row);
            ColumnLayout layout3 = columnLayoutModel.Find(p_column);
            double       x       = -1.0;
            double       y       = -1.0;
            double       width   = 0.0;
            double       height  = 0.0;

            if (layout2 != null)
            {
                y      = layout2.Y;
                height = layout2.Height;
            }
            if (layout3 != null)
            {
                x     = layout3.X;
                width = layout3.Width;
            }
            return(new Rect(x, y, width, height));
        }
示例#2
0
        internal Rect GetRangeBounds(CellRange range, out bool isLeftVisible, out bool isRightVisible, out bool isTopVisible, out bool isBottomVisible)
        {
            isLeftVisible   = true;
            isRightVisible  = true;
            isTopVisible    = true;
            isBottomVisible = true;
            RowLayoutModel    rowLayoutModel            = GetRowLayoutModel();
            ColumnLayoutModel viewportColumnLayoutModel = Excel.GetViewportColumnLayoutModel(ColumnViewportIndex);
            int row    = (rowLayoutModel.Count > 0) ? rowLayoutModel[0].Row : -1;
            int num2   = (rowLayoutModel.Count > 0) ? rowLayoutModel[rowLayoutModel.Count - 1].Row : -1;
            int column = (viewportColumnLayoutModel.Count > 0) ? viewportColumnLayoutModel[0].Column : -1;
            int num4   = (viewportColumnLayoutModel.Count > 0) ? viewportColumnLayoutModel[viewportColumnLayoutModel.Count - 1].Column : -1;

            if (!range.Intersects(row, column, (num2 - row) + 1, (num4 - column) + 1))
            {
                return(Rect.Empty);
            }
            int          index   = Math.Max(range.Row, row);
            int          num6    = Math.Max(range.Column, column);
            int          num7    = Math.Min((range.Row + range.RowCount) - 1, num2);
            int          num8    = Math.Min((range.Column + range.ColumnCount) - 1, num4);
            RowLayout    layout  = rowLayoutModel.Find(index);
            RowLayout    layout2 = rowLayoutModel.Find(num7);
            ColumnLayout layout3 = viewportColumnLayoutModel.Find(num6);
            ColumnLayout layout4 = viewportColumnLayoutModel.Find(num8);
            double       x       = -1.0;
            double       y       = -1.0;
            double       height  = 0.0;
            double       width   = 0.0;

            if ((layout != null) && (layout2 != null))
            {
                y      = layout.Y;
                height = (layout2.Y + layout2.Height) - layout.Y;
            }
            else if (rowLayoutModel.Count > 0)
            {
                y      = rowLayoutModel[0].Y;
                height = (rowLayoutModel[rowLayoutModel.Count - 1].Y + rowLayoutModel[rowLayoutModel.Count - 1].Height) - y;
            }
            if ((layout3 != null) && (layout4 != null))
            {
                x     = layout3.X;
                width = (layout4.X + layout4.Width) - layout3.X;
            }
            else if (viewportColumnLayoutModel.Count > 0)
            {
                x     = viewportColumnLayoutModel[0].X;
                width = (viewportColumnLayoutModel[viewportColumnLayoutModel.Count - 1].X + viewportColumnLayoutModel[viewportColumnLayoutModel.Count - 1].Width) - x;
            }
            if (range.Column < column)
            {
                isLeftVisible = false;
            }
            if (range.Row < row)
            {
                isTopVisible = false;
            }
            if ((num4 != -1) && (((range.Column + range.ColumnCount) - 1) > num4))
            {
                isRightVisible = false;
            }
            if ((num2 != -1) && (((range.Row + range.RowCount) - 1) > num2))
            {
                isBottomVisible = false;
            }
            return(new Rect(PointToClient(new Point(x, y)), new Size(width, height)));
        }
示例#3
0
        internal Rect GetRangeBounds(CellRange range, SheetArea area)
        {
            SheetSpanModel spanModel = null;

            if (Excel.ActiveSheet != null)
            {
                switch (area)
                {
                case SheetArea.Cells:
                    spanModel = Excel.ActiveSheet.SpanModel;
                    break;

                case (SheetArea.CornerHeader | SheetArea.RowHeader):
                    spanModel = Excel.ActiveSheet.RowHeaderSpanModel;
                    break;

                case SheetArea.ColumnHeader:
                    spanModel = Excel.ActiveSheet.ColumnHeaderSpanModel;
                    break;
                }
            }
            if (spanModel != null)
            {
                CellRange range2 = spanModel.Find(range.Row, range.Column);
                if (((range2 != null) && (range2.RowCount >= range.RowCount)) && (range2.ColumnCount >= range.ColumnCount))
                {
                    range = range2;
                }
            }
            RowLayoutModel    rowLayoutModel    = Excel.GetRowLayoutModel(RowViewportIndex, area);
            ColumnLayoutModel columnLayoutModel = Excel.GetColumnLayoutModel(ColumnViewportIndex, area);
            int row    = (rowLayoutModel.Count > 0) ? rowLayoutModel[0].Row : -1;
            int num2   = (rowLayoutModel.Count > 0) ? rowLayoutModel[rowLayoutModel.Count - 1].Row : -1;
            int column = (columnLayoutModel.Count > 0) ? columnLayoutModel[0].Column : -1;
            int num4   = (columnLayoutModel.Count > 0) ? columnLayoutModel[columnLayoutModel.Count - 1].Column : -1;

            if (!range.Intersects(row, column, (num2 - row) + 1, (num4 - column) + 1))
            {
                return(Rect.Empty);
            }
            int          index   = Math.Max(range.Row, row);
            int          num6    = Math.Max(range.Column, column);
            int          num7    = Math.Min((range.Row + range.RowCount) - 1, num2);
            int          num8    = Math.Min((range.Column + range.ColumnCount) - 1, num4);
            RowLayout    layout  = rowLayoutModel.Find(index);
            RowLayout    layout2 = rowLayoutModel.Find(num7);
            ColumnLayout layout3 = columnLayoutModel.Find(num6);
            ColumnLayout layout4 = columnLayoutModel.Find(num8);
            double       x       = -1.0;
            double       y       = -1.0;
            double       height  = 0.0;
            double       width   = 0.0;

            if ((layout != null) && (layout2 != null))
            {
                y      = layout.Y;
                height = (layout2.Y + layout2.Height) - layout.Y;
            }
            else if (rowLayoutModel.Count > 0)
            {
                y      = rowLayoutModel[0].Y;
                height = (rowLayoutModel[rowLayoutModel.Count - 1].Y + rowLayoutModel[rowLayoutModel.Count - 1].Height) - y;
            }
            if ((layout3 != null) && (layout4 != null))
            {
                x     = layout3.X;
                width = (layout4.X + layout4.Width) - layout3.X;
            }
            else if (columnLayoutModel.Count > 0)
            {
                x     = columnLayoutModel[0].X;
                width = (columnLayoutModel[columnLayoutModel.Count - 1].X + columnLayoutModel[columnLayoutModel.Count - 1].Width) - x;
            }
            return(new Rect(PointToClient(new Point(x, y)), new Size(width, height)));
        }