TableWidthInfo InitializeTableWidthInfo(WordDocHolder docHolder, Table table) { TableWidthInfo widthInfo = new TableWidthInfo(); TableProperties tProp = table.GetFirstChild <TableProperties>(); if (tProp != null) { if (tProp.TableWidth != null) { widthInfo.TableWidthInPixels = TableWidthInfo.TryReadWidth( tProp.TableWidth.Width, tProp.TableWidth.Type, docHolder.DocumentPageSizeInPixels); } if (tProp.TableIndentation != null) { widthInfo.TableIndentionInPixels = TableWidthInfo.TryReadWidth( tProp.TableIndentation.Width, tProp.TableIndentation.Type, docHolder.DocumentPageSizeInPixels); } widthInfo.TableIndentionInPixels += docHolder.DocumentPageLeftMaginInPixels; } else { widthInfo.TableWidthInPixels = docHolder.DocumentPageSizeInPixels; } TableGrid tGrid = table.GetFirstChild <TableGrid>(); if (tGrid != null) { widthInfo.ColumnWidths = new List <int>(); foreach (var col in tGrid.Elements <GridColumn>()) { widthInfo.ColumnWidths.Add( TableWidthInfo.TryReadWidth( col.Width, TableWidthUnitValues.Dxa, widthInfo.TableWidthInPixels)); } } return(widthInfo); }
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; }