Ejemplo n.º 1
0
        bool CheckBottomBorder(int row, int column, ref bool hasText)
        {
            if (row + 1 >= TableRows.Count)
            {
                return(true);
            }
            int cellNo = FindMergedCellByColumnNo(TableRows[row].RowCells, column);

            if (cellNo == -1)
            {
                throw new BadCellAddress(row, column);
            }
            OpenXmlWordCell cell = TableRows[row].RowCells[cellNo];

            cellNo = FindMergedCellByColumnNo(TableRows[row + 1].RowCells, column);
            if (cellNo == -1)
            {
                throw new BadCellAddress(row, column); // change in column count, we hope that there is a border. Why?
            }
            var cellUnder = TableRows[row + 1].RowCells[cellNo];

            //  очень сложное место, см тесты 10639_32.doc, 18261_22.doc,  65098_5.docx
            hasText = hasText || !cell.IsEmpty;
            if (!cellUnder.IsEmpty && hasText)
            {
                if (TableRows[row + 1].HasPersonName || TableRows[row].HasPersonName)
                {
                    return(true);
                }
            }


            if (cellUnder.VerticallyMerged == MergedCellValues.Continue)
            {
                return(false);
            }
            if (cell.HasBottomBorder)
            {
                return(true);
            }

            if (cellUnder.HasTopBorder)
            {
                return(true);
            }
            return(cell.TableHasInsideHorizontalBorders);
        }
Ejemplo n.º 2
0
        bool HasTopBorder(int row, int column)
        {
            if (row <= 0)
            {
                return(true);
            }
            int cellNo = FindMergedCellByColumnNo(TableRows[row].RowCells, column);

            if (cellNo == -1)
            {
                throw new BadCellAddress(row, column);
            }
            OpenXmlWordCell cell = TableRows[row].RowCells[cellNo];

            if (cell.VerticallyMerged == MergedCellValues.Continue)
            {
                return(false);
            }
            if (cell.HasTopBorder)
            {
                return(true);
            }
            cellNo = FindMergedCellByColumnNo(TableRows[row - 1].RowCells, column);
            if (cellNo == -1)
            {
                throw new BadCellAddress(row, column); // change in column count, we hope that there is a border. Why?
            }
            var cellAbove = TableRows[row - 1].RowCells[cellNo];

            if (cellAbove.HasBottomBorder)
            {
                return(true);
            }
            if (!cellAbove.IsEmpty)
            {
                return(false);
            }
            return(cell.TableHasInsideHorizontalBorders);
        }
Ejemplo n.º 3
0
        void CopyPortion(List <List <TJsonCell> > portion, bool ignoreMergedRows)
        {
            for (int i = 0; i < portion.Count; i++)
            {
                var             r      = portion[i];
                OpenXmlTableRow newRow = new OpenXmlTableRow();
                newRow.InnerBorderCount = 1; // more than 0

                foreach (var c in r)
                {
                    var cell = new OpenXmlWordCell(c);
                    cell.Row = TableRows.Count;
                    if (ignoreMergedRows)
                    {
                        cell.MergedRowsCount = 1;
                    }
                    cell.CellWidth = 10; //  no cell width serialized in html
                    newRow.RowCells.Add(cell);
                }
                TableRows.Add(newRow);
            }
        }
Ejemplo n.º 4
0
        void ProcessWordTable(WordDocHolder docHolder, Table table, int maxRowsToProcess)
        {
            var            rows          = table.Descendants <TableRow>().ToList();
            TableWidthInfo widthInfo     = InitializeTableWidthInfo(docHolder, table);
            int            saveRowsCount = TableRows.Count;
            int            maxCellsCount = 0;
            TableBorders   tblBorders    = GetTableBorders(table);

            for (int r = 0; r < rows.Count(); ++r)
            {
                OpenXmlTableRow newRow        = new OpenXmlTableRow();
                int             sumspan       = 0;
                var             tableRow      = rows[r];
                int             rowGridBefore = GetRowGridBefore(tableRow);
                bool            isEmpty       = true;
                var             row           = tableRow.Elements <TableCell>().ToArray();
                for (var i = 0; i < row.Length; ++i)
                {
                    var c = new OpenXmlWordCell(docHolder, row, i, widthInfo, TableRows.Count, sumspan, tblBorders);
                    if (newRow.RowCells.Count == 0)
                    {
                        c.MergedColsCount += rowGridBefore;
                    }
                    if (newRow.RowCells.Count > 0 && !newRow.RowCells.Last().HasRightBorder)
                    {
                        newRow.RowCells.Last().Text            += c.Text;
                        newRow.RowCells.Last().CellWidth       += c.CellWidth;
                        newRow.RowCells.Last().MergedColsCount += c.MergedColsCount;
                        newRow.RowCells.Last().HasRightBorder   = c.HasRightBorder;
                        sumspan += c.MergedColsCount;
                    }
                    else
                    {
                        newRow.RowCells.Add(c);
                        sumspan += c.MergedColsCount;
                    }
                    isEmpty = isEmpty && c.IsEmpty;
                }
                if (isEmpty)
                {
                    continue;
                }
                maxCellsCount = Math.Max(newRow.RowCells.Count, maxCellsCount);
                if (r == 0 && TableRows.Count > 0 &&
                    BigramsHolder.CheckMergeRow(
                        TableRows.Last().RowCells.ConvertAll(x => x.Text),
                        newRow.RowCells.ConvertAll(x => x.Text)))
                {
                    MergeRow(TableRows.Last().RowCells, newRow.RowCells);
                }
                else
                {
                    TableRows.Add(newRow);
                }

                if ((maxRowsToProcess != -1) && (TableRows.Count >= maxRowsToProcess))
                {
                    break;
                }
            }
            if ((TableRows.Count > 0) && !TableHeaderRecognizer.IsNamePositionAndIncomeTable(GetDataCells(0)))
            {
                if (maxCellsCount <= 4 || CheckNameColumnIsEmpty(saveRowsCount))
                {
                    //remove this suspicious table
                    TableRows.RemoveRange(saveRowsCount, TableRows.Count - saveRowsCount);
                }
            }
        }