Esempio n. 1
0
        private bool ResolveIntersectionConflict(ExcelCell A, ExcelCell B)
        {
            var BLeft   = B.Column.XPosition;
            var BRight  = B.Column.XPosition + B.OriginalWidth;
            var BTop    = B.Row.YPosition;
            var BBottom = B.Row.YPosition + B.OriginalHeight;

            return(ResolveIntersectionConflict(A, BLeft, BRight, BTop, BBottom));
        }
Esempio n. 2
0
        private void SetCellStyle(ExcelCell excelCell, ReportItem reportItem, Row row)
        {
            if (reportItem.Style == null)
            {
                return;
            }
            var si = reportItem.Style.GetStyleInfo(Report, row);

            excelCell.Style = si;
        }
Esempio n. 3
0
        public void AddRow(TableRow tr, Row row)
        {
            if (CurrentExcelTable.Table == null)
            {
                return;
            }
            float rowHeight = tr.CanGrow ? tr.HeightOfRow(Report, g, row) : tr.Height.Points;

            var shiftingRows = Rows.Where(x => x.YPosition >= rowPosition);

            ShiftBottomRows(shiftingRows, rowHeight);

            var currentRow = AddRow(rowPosition, rowHeight);

            foreach (var cell in tr.TableCells.Items)
            {
                var column    = CurrentExcelTable.Table.TableColumns.Items[cell.ColIndex];
                var xPosition = CurrentExcelTable.Table.Left.Points;
                for (int i = 0; i < cell.ColIndex; i++)
                {
                    xPosition += CurrentExcelTable.Table.TableColumns.Items[i].Width.Points;
                }
                var currentColumn = AddColumn(xPosition, column.Width.Points);
                var cellTextBox   = cell.ReportItems.Items.FirstOrDefault();
                if (cellTextBox == null || (cellTextBox as Textbox) == null)
                {
                    continue;
                }
                string    value       = (cellTextBox as Textbox).RunText(Report, row);
                ExcelCell currentCell = new ExcelCell(cellTextBox, value, currentRow, currentColumn);
                currentCell.ExcelTable     = CurrentExcelTable;
                currentCell.OriginalWidth  = column.Width.Points;
                currentCell.OriginalHeight = rowHeight;

                if (cell.ColSpan > 1)
                {
                    float spanWidth = 0f;
                    for (int i = cell.ColIndex; i < cell.ColIndex + cell.ColSpan; i++)
                    {
                        spanWidth += CurrentExcelTable.Table.TableColumns.Items[i].Width.Points;
                    }
                    currentCell.OriginalWidth = spanWidth;
                }
                currentCell.GrowedBottomPosition = rowPosition + rowHeight;
                SetCellStyle(currentCell, cellTextBox, row);
                Cells.Add(currentCell);
            }

            rowPosition += rowHeight;
            CurrentExcelTable.GrowedBottomPosition = rowPosition;
        }
Esempio n. 4
0
        private void SetCellStyle(ExcelCell excelCell, ReportItem reportItem, Row row)
        {
            StyleInfo si = new StyleInfo();

            if (reportItem.Style != null)
            {
                var itemStyleInfo = reportItem.Style.GetStyleInfo(Report, row);
                if (itemStyleInfo != null)
                {
                    si = itemStyleInfo;
                }
            }
            excelCell.Style = si;
        }
Esempio n. 5
0
        public int GetBottomAttachCells(ExcelCell cell)
        {
            int result = 0;

            if (cell.BottomAttachRow != null)
            {
                var bi = Rows.IndexOf(cell.BottomAttachRow);
                var ti = Rows.IndexOf(cell.Row);
                result = (bi - ti) - 1;
                return(result < 0 ? 0 : result);
            }

            return(Rows.Count(y => y.YPosition > cell.Row.YPosition &&
                              y.YPosition < (cell.Row.YPosition + cell.ActualHeight) - Tolerance));
        }
Esempio n. 6
0
        public int GetRightAttachCells(ExcelCell cell)
        {
            int result = 0;

            if (cell.RightAttachCol != null)
            {
                var ri = Columns.IndexOf(cell.RightAttachCol);
                var li = Columns.IndexOf(cell.Column);
                result = (ri - li) - 1;
                return(result < 0 ? 0 : result);
            }

            result = Columns.Count(x => x.XPosition > cell.Column.XPosition &&
                                   x.XPosition < (cell.Column.XPosition + cell.ActualWidth) - Tolerance);
            return(result < 0 ? 0 : result);
        }
Esempio n. 7
0
        private void CutCellHeight(ExcelCell cell, float toPos)
        {
            var TopPosition    = cell.Row.YPosition;
            var BottomPosition = TopPosition + cell.OriginalHeight;

            if (!(toPos > TopPosition && toPos < BottomPosition))
            {
                return;
            }
            cell.BottomAttachRow = GetRowAtPosition(toPos);
            ExcelRow endRow = GetRowAtPosition(BottomPosition);

            if (endRow != null && endRow.IsEmpty)
            {
                Rows.Remove(endRow);
            }
            cell.CorrectedHeight = toPos - TopPosition;
        }
Esempio n. 8
0
        private void CutCellWidthFromRight(ExcelCell cell, float toPos)
        {
            var LeftPosition  = cell.Column.XPosition;
            var RightPosition = LeftPosition + cell.OriginalWidth;

            if (!(toPos > LeftPosition && toPos < RightPosition))
            {
                return;
            }
            cell.RightAttachCol = GetColumnAtPosition(toPos);
            ExcelColumn endColumn = GetColumnAtPosition(RightPosition);

            if (endColumn != null && endColumn.IsEmpty)
            {
                Columns.Remove(endColumn);
            }
            cell.CorrectedWidth = toPos - LeftPosition;
        }
Esempio n. 9
0
        public void AddTextbox(Textbox reportItem, string value, Row row)
        {
            if (reportItem.InPageHeaderOrFooter())
            {
                return;
            }

            if (reportItem.IsTableOrMatrixCell(Report) ||
                reportItem.Top == null || reportItem.Left == null ||
                reportItem.Height == null || reportItem.Width == null)
            {
                return;
            }


            float topPosition  = reportItem.Top.Points;
            float leftPosition = reportItem.Left.Points;
            float height       = reportItem.CanGrow ? reportItem.RunTextCalcHeight(Report, g, row) : reportItem.Height.Points;
            float width        = reportItem.Width.Points;

            FillAbsolutePosition(reportItem, ref topPosition, ref leftPosition);
            float OriginalBottomPosition = topPosition + reportItem.Height.Points;
            float bottomPosition         = topPosition + height;
            float rightPosition          = leftPosition + width;

            topPosition = GetCellAboveRelativePosition(topPosition);

            var currentRow    = AddRow(topPosition, height);
            var currentColumn = AddColumn(leftPosition, width);

            ExcelCell currentCell = new ExcelCell(reportItem, value, currentRow, currentColumn);

            currentCell.OriginalBottomPosition = OriginalBottomPosition;
            SetCellStyle(currentCell, reportItem, row);
            Cells.Add(currentCell);
            currentCell.OriginalHeight       = height;
            currentCell.GrowedBottomPosition = topPosition + height;
        }
Esempio n. 10
0
        private void CutCellWidthFromLeft(ExcelCell cell, float toPos)
        {
            var LeftPosition  = cell.Column.XPosition;
            var RightPosition = LeftPosition + cell.OriginalWidth;

            if (!(toPos > LeftPosition && toPos < RightPosition))
            {
                return;
            }
            ExcelColumn StartColumn    = GetColumnAtPosition(LeftPosition);
            ExcelColumn newStartColumn = GetColumnAtPosition(toPos);

            if (newStartColumn == null)
            {
                var index = InsertColumn(toPos);
                newStartColumn = Columns[index];
                Columns.Remove(newStartColumn);
            }
            var       newCell   = new ExcelCell(cell.ReportItem, cell.Value, cell.Row, newStartColumn);
            ExcelCell existCell = newStartColumn.Cells.FirstOrDefault(x => x.Row == cell.Row);

            if (existCell != null)
            {
                ResolveIntersectionConflict(cell, existCell);
            }
            newCell.Style = cell.Style;
            Cells.Add(newCell);
            newCell.Row.Cells.Add(newCell);
            newStartColumn.Cells.Add(newCell);
            RemoveCell(cell);

            LeftPosition        = newStartColumn.XPosition;
            RightPosition       = LeftPosition + cell.OriginalWidth;
            cell.RightAttachCol = GetColumnAtPosition(RightPosition);
            cell.CorrectedWidth = RightPosition - LeftPosition;
        }
Esempio n. 11
0
 private void RemoveCell(ExcelCell cell)
 {
     Cells.Remove(cell);
     cell.Column.Cells.Remove(cell);
     cell.Row.Cells.Remove(cell);
 }
Esempio n. 12
0
        private bool ResolveIntersectionConflict(ExcelCell A, float BLeft, float BRight, float BTop, float BBottom)
        {
            if (A == null)
            {
                return(false);
            }
            var ALeft   = A.Column.XPosition;
            var ARight  = A.Column.XPosition + A.OriginalWidth;
            var ATop    = A.Row.YPosition;
            var ABottom = A.Row.YPosition + A.OriginalHeight;

            bool leftEqualPosition   = Math.Abs(ALeft - BLeft) <= Tolerance;
            bool topEqualPosition    = Math.Abs(ATop - BTop) <= Tolerance;
            bool rightEqualPosition  = Math.Abs(ARight - BRight) <= Tolerance;
            bool bottomEqualPosition = Math.Abs(ABottom - BBottom) <= Tolerance;

            bool Cross_ALeft_BTop     = Intersection(ALeft, ATop, ALeft, ABottom, BLeft, BTop, BRight, BTop);
            bool Cross_ALeft_BBottom  = Intersection(ALeft, ATop, ALeft, ABottom, BLeft, BBottom, BRight, BBottom);
            bool Cross_ARight_BTop    = Intersection(ARight, ATop, ARight, ABottom, BLeft, BTop, BRight, BTop);
            bool Cross_ARight_BBottom = Intersection(ARight, ATop, ARight, ABottom, BLeft, BBottom, BRight, BBottom);

            //currently not used
            bool Cross_ATop_BLeft     = Intersection(ALeft, ATop, ARight, ATop, BLeft, BTop, BLeft, BBottom);
            bool Cross_ATop_BRight    = Intersection(ALeft, ATop, ARight, ATop, BRight, BTop, BRight, BBottom);
            bool Cross_ABottom_BLeft  = Intersection(ALeft, ABottom, ARight, ABottom, BLeft, BTop, BLeft, BBottom);
            bool Cross_ABottom_BRight = Intersection(ALeft, ABottom, ARight, ABottom, BRight, BTop, BRight, BBottom);

            bool isCrossed = !(ABottom < BTop || BBottom < ATop || ARight < BLeft || BRight < ALeft);

            if (!isCrossed && !leftEqualPosition && !topEqualPosition && !rightEqualPosition && !bottomEqualPosition)
            {
                return(true);
            }

            if (!topEqualPosition && !bottomEqualPosition)
            {
                //Cut Upper cell to top position of a Lower cell

                //if A is upper
                if (ATop < BTop && ABottom < BBottom && isCrossed)
                {
                    CutCellHeight(A, BTop);
                    return(true);
                }
                //Cut A cell to top position of a B cell
                //    ┌───┐
                //    │  A│
                // ┌──┼───┼─┐
                // │B │   │ │
                // └──┼───┼─┘
                //    └───┘
                //
                if (Cross_ALeft_BTop && Cross_ALeft_BBottom && BLeft < ALeft && BRight > ARight)
                {
                    CutCellHeight(A, BTop);
                    return(true);
                }

                //Cut A cell to left position of a B cell
                //   ┌───┐
                //   │  B│
                //┌──┼─┐ │
                //│A │ │ │
                //└──┼─┘ │
                //   └───┘
                //
                if (Cross_ATop_BLeft && Cross_ABottom_BLeft && ALeft < BLeft && ARight < BRight)
                {
                    CutCellWidthFromRight(A, BLeft);
                    return(true);
                }
            }

            //Cut Left cell to left position of a Right cell

            // ┌──┬───┬─┐  ┌──┬─┬─┐
            // │A │   │ │  │A │ │ │
            // └──┼───┼─┘  └──┼─┘ │
            //    │  B│       │  B│
            //    └───┘       └───┘

            if (topEqualPosition && ABottom < BBottom && ALeft < BLeft && isCrossed)
            {
                CutCellWidthFromRight(A, BLeft);
                return(true);
            }

            //Cut Left cell to left position of a Right cell
            if (ALeft < BLeft && ARight < BRight && ARight > BLeft &&
                (
                    //┌───┬─┬───┐
                    //│A  │ │  B│
                    //└───┴─┴───┘
                    (topEqualPosition && bottomEqualPosition)
                    //┌────┐
                    //│  ┌─┼──┐
                    //│A │ │ B│
                    //│  └─┼──┘
                    //└────┘
                    || (!topEqualPosition && !bottomEqualPosition && Cross_ARight_BTop && Cross_ARight_BBottom)
                    //┌──┬─┬──┐
                    //│A │ │ B│
                    //│  └─┼──┘
                    //└────┘
                    || (topEqualPosition && !bottomEqualPosition && Cross_ARight_BBottom)
                    //┌────┐
                    //│  ┌─┼──┐
                    //│A │ │ B│
                    //└──┴─┴──┘
                    || (!topEqualPosition && bottomEqualPosition && Cross_ARight_BTop)
                ))
            {
                CutCellWidthFromRight(A, BLeft);
                return(true);
            }

            //Cut A cell to right position of a Left cell
            //┌──┬──┐
            //│  │ A│
            //├──┼──┘
            //│B │
            //└──┘
            if (topEqualPosition && leftEqualPosition && !bottomEqualPosition && !rightEqualPosition &&
                Cross_ABottom_BRight)
            {
                CutCellWidthFromLeft(A, BRight);
                return(true);
            }

            //B region full contain A
            if ((BTop < ATop || topEqualPosition) &&
                (BLeft < ALeft || leftEqualPosition) &&
                (BRight > ARight || rightEqualPosition) &&
                (BBottom > ABottom || bottomEqualPosition))
            {
                //delete A
                RemoveCell(A);
                if (!A.Column.Cells.Any())
                {
                    Columns.Remove(A.Column);
                }
                return(true);
            }

            return(false);
        }
Esempio n. 13
0
        public ExcelRow GetBottomAttachRow(ExcelCell cell)
        {
            var c = Rows.LastOrDefault(x => x.YPosition < (cell.Row.YPosition + cell.ActualHeight) - Tolerance);

            return(c);
        }
Esempio n. 14
0
        public ExcelColumn GetRightAttachColumn(ExcelCell cell)
        {
            var c = Columns.LastOrDefault(x => x.XPosition < (cell.Column.XPosition + cell.ActualWidth) - Tolerance);

            return(c);
        }