Ejemplo n.º 1
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;

            for (int r = 0; r < rows.Count(); ++r)
            {
                List <OpenXmlWordCell> newRow = new List <OpenXmlWordCell>();
                int  sumspan       = 0;
                var  row           = rows[r];
                int  rowGridBefore = GetRowGridBefore(row);
                bool isEmpty       = true;
                foreach (var rowCell in row.Elements <TableCell>())
                {
                    var c = new OpenXmlWordCell(docHolder, widthInfo, rowCell, TableRows.Count, sumspan);
                    if (newRow.Count == 0)
                    {
                        c.MergedColsCount += rowGridBefore;
                    }
                    newRow.Add(c);
                    sumspan += c.MergedColsCount;
                    isEmpty  = isEmpty && c.IsEmpty;
                }
                if (isEmpty)
                {
                    continue;
                }
                maxCellsCount = Math.Max(newRow.Count, maxCellsCount);
                if (r == 0 && TableRows.Count > 0 &&
                    BigramsHolder.CheckMergeRow(
                        TableRows.Last().ConvertAll(x => x.Text),
                        newRow.ConvertAll(x => x.Text)))
                {
                    MergeRow(TableRows.Last(), newRow);
                }
                else
                {
                    TableRows.Add(newRow);
                }

                if ((maxRowsToProcess != -1) && (TableRows.Count >= maxRowsToProcess))
                {
                    break;
                }
            }

            if (maxCellsCount <= 4 || CheckNameColumnIsEmpty(TableRows, saveRowsCount))
            {
                //remove this suspicious table
                TableRows.RemoveRange(saveRowsCount, TableRows.Count - saveRowsCount);
            }
        }
Ejemplo n.º 2
0
        void CopyPortion(List <List <TJsonCell> > portion, bool ignoreMergedRows)
        {
            for (int i = 0; i < portion.Count; i++)
            {
                var r = portion[i];
                List <OpenXmlWordCell> newRow = new List <OpenXmlWordCell>();

                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.Add(cell);
                }
                TableRows.Add(newRow);
            }
        }