Esempio n. 1
0
 bool IsHeaderRow(DataRow row, out TableHeader columnOrdering)
 {
     columnOrdering = null;
     if (!TableHeaderRecognizer.WeakHeaderCheck(Adapter, row.Cells))
     {
         return(false);
     }
     try
     {
         columnOrdering = new TableHeader();
         TableHeaderRecognizer.ReadHeader(Adapter, row.GetRowIndex(), columnOrdering);
         return(true);
     }
     catch (Exception e)
     {
         Logger.Debug(String.Format("Cannot parse possible header, row={0}, error={1}, so skip it may be it is a data row ", e.ToString(), row.GetRowIndex()));
     }
     return(false);
 }
Esempio n. 2
0
        static void AddColumn(TableHeader ordering, DeclarationField field, Cell cell)
        {
            TColumnInfo s = new TColumnInfo();

            s.BeginColumn      = cell.Col;
            s.EndColumn        = cell.Col + cell.MergedColsCount;
            s.ColumnPixelWidth = cell.CellWidth;
            //s.ColumnPixelStart is unknown and initialized in FinishOrderingBuilding
            s.Field = field;
            if (IsIncomeColumn(field))
            {
                string dummy = "";
                int?   year  = null;
                if (TableHeaderRecognizer.GetValuesFromTitle(cell.GetText(), ref dummy, ref year, ref dummy) && year.HasValue)
                {
                    ordering.YearFromIncome = year.Value;
                }
            }

            ordering.Add(s);
        }
Esempio n. 3
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);
                }
            }
        }