public static int CountInnerVerticalBorders(TableRow row) { int cellIndex = 0; HashSet <int> visibleBorders = new HashSet <int>(); var cells = row.Descendants <TableCell>().ToList(); foreach (var c in cells) { bool rightBorder = true; bool leftBorder = true; if (c?.TableCellProperties?.TableCellBorders != null) { var cellBorders = c.TableCellProperties.TableCellBorders; if (!WordDocHolder.BorderIsVisible(cellBorders.LeftBorder)) { leftBorder = false; } if (!WordDocHolder.BorderIsVisible(cellBorders.RightBorder)) { rightBorder = false; } } if (cellIndex > 0 && leftBorder) { visibleBorders.Add(cellIndex); } if (cellIndex + 1 < cells.Count && rightBorder) { visibleBorders.Add(cellIndex + 1); } cellIndex += 1; } return(visibleBorders.Count); }
public OpenXmlWordCell(WordDocHolder docHolder, TableCell[] row, int cellIndexInRow, TableWidthInfo tableWidth, int rowIndexInTable, int unmergedColumnIndex, TableBorders tblBorders) { TableCell inputCell = row[cellIndexInRow]; InitTextProperties(docHolder, inputCell); if (inputCell?.TableCellProperties?.TableCellBorders != null) { var borders = inputCell.TableCellProperties.TableCellBorders; HasBottomBorder = WordDocHolder.BorderIsVisible(borders.BottomBorder); HasTopBorder = WordDocHolder.BorderIsVisible(borders.TopBorder); HasRightBorder = WordDocHolder.BorderIsVisible(borders.RightBorder); if (!HasRightBorder && cellIndexInRow + 1 < row.Length && row[cellIndexInRow + 1].TableCellProperties?.TableCellBorders != null) { HasRightBorder = WordDocHolder.BorderIsVisible(row[cellIndexInRow + 1].TableCellProperties?.TableCellBorders?.LeftBorder); } if (!HasRightBorder && tblBorders?.InsideVerticalBorder != null && (uint)tblBorders.InsideVerticalBorder.Size > 0) { HasRightBorder = true; } } var vmerge = inputCell.TableCellProperties.GetFirstChild <VerticalMerge>(); VerticallyMerged = null; if (vmerge != null) { if ((vmerge.Val == null) || (vmerge.Val == MergedCellValues.Continue)) { // null -> MergedCellValues.Continue VerticallyMerged = MergedCellValues.Continue; } else if (vmerge.Val == MergedCellValues.Restart) { VerticallyMerged = MergedCellValues.Restart; } } if (tblBorders?.InsideHorizontalBorder != null && (uint)tblBorders.InsideHorizontalBorder.Size > 0) { TableHasInsideHorizontalBorders = true; } var gridSpan = inputCell.TableCellProperties.GetFirstChild <GridSpan>(); IsMerged = gridSpan != null && gridSpan.Val > 1; FirstMergedRow = -1; // init afterwards MergedRowsCount = -1; // init afterwards MergedColsCount = (gridSpan == null) ? 1 : (int)gridSpan.Val; Row = rowIndexInTable; Col = unmergedColumnIndex; if (inputCell.TableCellProperties != null && inputCell.TableCellProperties.TableCellWidth != null && inputCell.TableCellProperties.TableCellWidth.Type != null && inputCell.TableCellProperties.TableCellWidth.Type != TableWidthUnitValues.Auto ) { CellWidth = TableWidthInfo.TryReadWidth( inputCell.TableCellProperties.TableCellWidth.Width, inputCell.TableCellProperties.TableCellWidth.Type, tableWidth.TableWidthInPixels); } else { if (Col < tableWidth.ColumnWidths.Count) { CellWidth = tableWidth.ColumnWidths[Col]; } } AdditTableIndention = tableWidth.TableIndentionInPixels; }