private void ProcessTableBorder(DocxNode node, DocxTableProperties docxProperties, TableProperties tableProperties) { string borderStyle = node.ExtractAttributeValue(DocxBorder.borderName); if (borderStyle == "1") { TableBorders tableBorders = new TableBorders(); DocxBorder.ApplyDefaultBorders(tableBorders); tableProperties.Append(tableBorders); } else { borderStyle = node.ExtractStyleValue(DocxBorder.borderName); string leftBorder = node.ExtractStyleValue(DocxBorder.leftBorderName); string topBorder = node.ExtractStyleValue(DocxBorder.topBorderName); string rightBorder = node.ExtractStyleValue(DocxBorder.rightBorderName); string bottomBorder = node.ExtractStyleValue(DocxBorder.bottomBorderName); TableBorders tableBorders = new TableBorders(); DocxBorder.ApplyBorders(tableBorders, borderStyle, leftBorder, topBorder, rightBorder, bottomBorder, docxProperties.HasDefaultBorder); if (tableBorders.HasChildren) { tableProperties.Append(tableBorders); } } }
internal void Process(TableProperties tableProperties, DocxTableProperties docxProperties, DocxNode node) { ProcessWidth(node, tableProperties); ProcessTableBorder(node, docxProperties, tableProperties); ProcessTableCellMargin(docxProperties, tableProperties); }
private void ProcessTableCellMargin(DocxTableProperties docxProperties, TableProperties tableProperties) { if (docxProperties.CellPadding != null) { TableCellMarginDefault cellMargin = new TableCellMarginDefault(); Int16 width = (Int16)DocxUnits.GetDxaFromPixel(docxProperties.CellPadding.Value); cellMargin.TableCellLeftMargin = new TableCellLeftMargin() { Width = width, Type = TableWidthValues.Dxa }; cellMargin.TopMargin = new TopMargin() { Width = width.ToString(), Type = TableWidthUnitValues.Dxa }; cellMargin.TableCellRightMargin = new TableCellRightMargin() { Width = width, Type = TableWidthValues.Dxa }; cellMargin.BottomMargin = new BottomMargin() { Width = width.ToString(), Type = TableWidthUnitValues.Dxa }; tableProperties.Append(cellMargin); } }
internal void Process(TableCell cell, DocxTableProperties docxProperties, DocxNode node) { TableCellProperties cellProperties = new TableCellProperties(); ProcessColSpan(node, cellProperties); ProcessWidth(node, cellProperties); if (HasRowSpan) { cellProperties.Append(new VerticalMerge() { Val = MergedCellValues.Restart }); } //Processing border should be after colspan ProcessBorders(node, docxProperties, cellProperties); string backgroundColor = node.ExtractStyleValue(DocxColor.backGroundColor); if (!string.IsNullOrEmpty(backgroundColor)) { DocxColor.ApplyBackGroundColor(backgroundColor, cellProperties); } ProcessVerticalAlignment(node, cellProperties); if (cellProperties.HasChildren) { cell.Append(cellProperties); } }
internal override void Process(DocxNode node, ref Paragraph paragraph) { if (node.IsNull() || node.Parent == null || !CanConvert(node) || IsHidden(node)) { return; } paragraph = null; if (node.HasChildren) { Table table = new Table(); DocxTableProperties tableProperties = new DocxTableProperties(); tableProperties.FetchTableProperties(node); tableProperties.ApplyTableProperties(table, node); foreach (DocxNode child in node.Children) { if (string.Compare(child.Tag, DocxTableProperties.trName, StringComparison.InvariantCultureIgnoreCase) == 0) { node.CopyExtentedStyles(child); ProcessTr(child, table, tableProperties); } else if (tableProperties.IsGroupElement(child.Tag)) { node.CopyExtentedStyles(child); ProcessGroupElement(child, table, tableProperties); } } node.Parent.Append(table); } }
private void ProcessTr(DocxNode tr, Table table, DocxTableProperties tableProperties) { if (tr.HasChildren) { TableRow row = new TableRow(); DocxTableRowStyle style = new DocxTableRowStyle(); style.Process(row, tableProperties); int colIndex = 0; foreach (DocxNode td in tr.Children) { ProcessVerticalSpan(ref colIndex, row, tableProperties); tableProperties.IsCellHeader = string.Compare(td.Tag, DocxTableProperties.thName, StringComparison.InvariantCultureIgnoreCase) == 0; if (string.Compare(td.Tag, DocxTableProperties.tdName, StringComparison.InvariantCultureIgnoreCase) == 0 || tableProperties.IsCellHeader) { tr.CopyExtentedStyles(td); ProcessTd(colIndex++, td, row, tableProperties); } } if (colIndex < tableProperties.RowSpanInfo.Count) { ProcessVerticalSpan(ref colIndex, row, tableProperties); } table.Append(row); } }
private void ProcessTableBorder(DocxNode node, DocxTableProperties docxProperties, TableProperties tableProperties) { string borderStyle = node.ExtractAttributeValue(DocxBorder.borderName); if (borderStyle == "1") { TableBorders tableBorders = new TableBorders(); DocxBorder.ApplyDefaultBorders(tableBorders); tableProperties.Append(tableBorders); } else { borderStyle = node.ExtractStyleValue(DocxBorder.borderName); string leftBorder = node.ExtractStyleValue(DocxBorder.leftBorderName); string topBorder = node.ExtractStyleValue(DocxBorder.topBorderName); string rightBorder = node.ExtractStyleValue(DocxBorder.rightBorderName); string bottomBorder = node.ExtractStyleValue(DocxBorder.bottomBorderName); TableBorders tableBorders = new TableBorders(); DocxBorder.ApplyBorders(tableBorders, borderStyle, leftBorder, topBorder, rightBorder, bottomBorder, docxProperties.HasDefaultBorder); if (tableBorders.HasChildren) { tableProperties.Append(tableBorders); } } }
internal void Process(TableCell cell, DocxTableProperties docxProperties, DocxNode node) { TableCellProperties cellProperties = new TableCellProperties(); ProcessColSpan(node, cellProperties); ProcessWidth(node, cellProperties); if (HasRowSpan) { cellProperties.Append(new VerticalMerge() { Val = MergedCellValues.Restart }); } //Processing border should be after colspan ProcessBorders(node, docxProperties, cellProperties); string backgroundColor = node.ExtractStyleValue(DocxColor.backGroundColor); if (!string.IsNullOrEmpty(backgroundColor)) { DocxColor.ApplyBackGroundColor(backgroundColor, cellProperties); } ProcessVerticalAlignment(node, cellProperties); if (cellProperties.HasChildren) { cell.Append(cellProperties); } }
private void ProcessVerticalSpan(ref int colIndex, TableRow row, DocxTableProperties docxProperties) { int rowSpan; docxProperties.RowSpanInfo.TryGetValue(colIndex, out rowSpan); while (rowSpan > 0) { TableCell cell = new TableCell(); cell.TableCellProperties = new TableCellProperties(); cell.TableCellProperties.Append(new VerticalMerge()); // There should be a more elegant solution for drawing borders. cell.TableCellProperties.Append(new LeftBorder() { Val = BorderValues.Single, Color = "auto", Size = (UInt32Value)4U, Space = (UInt32Value)0U }); // cell.AppendChild(new Paragraph()); row.Append(cell); docxProperties.RowSpanInfo[colIndex] = --rowSpan; ++colIndex; docxProperties.RowSpanInfo.TryGetValue(colIndex, out rowSpan); } }
private void ProcessTableCellMargin(DocxTableProperties docxProperties, TableProperties tableProperties) { if (docxProperties.CellPadding != null) { TableCellMarginDefault cellMargin = new TableCellMarginDefault(); Int16 width = (Int16)DocxUnits.GetDxaFromPixel(docxProperties.CellPadding.Value); cellMargin.TableCellLeftMargin = new TableCellLeftMargin() { Width = width, Type = TableWidthValues.Dxa }; cellMargin.TopMargin = new TopMargin() { Width = width.ToString(), Type = TableWidthUnitValues.Dxa }; cellMargin.TableCellRightMargin = new TableCellRightMargin() { Width = width, Type = TableWidthValues.Dxa }; cellMargin.BottomMargin = new BottomMargin() { Width = width.ToString(), Type = TableWidthUnitValues.Dxa }; tableProperties.Append(cellMargin); } }
private void ProcessGroupElement(DocxNode tbody, Table table, DocxTableProperties tableProperties) { foreach (DocxNode tr in tbody.Children) { if (string.Compare(tr.Tag, DocxTableProperties.trName, StringComparison.InvariantCultureIgnoreCase) == 0) { tbody.CopyExtentedStyles(tr); ProcessTr(tr, table, tableProperties); } } }
internal void Process(TableRow row, DocxTableProperties docxProperties) { TableRowProperties trProperties = new TableRowProperties(); if (docxProperties.CellSpacing != null) { trProperties.Append(new TableCellSpacing() { Width = DocxUnits.GetDxaFromPixel(docxProperties.CellSpacing.Value).ToString(), Type = TableWidthUnitValues.Dxa }); } if (trProperties.ChildElements.Count > 0) { row.Append(trProperties); } }
internal void Process(TableRow row, DocxTableProperties docxProperties) { TableRowProperties trProperties = new TableRowProperties(); if (docxProperties.CellSpacing != null) { trProperties.Append(new TableCellSpacing() { Width = DocxUnits.GetDxaFromPixel(docxProperties.CellSpacing.Value).ToString(), Type = TableWidthUnitValues.Dxa }); } if (trProperties.ChildElements.Count > 0) { row.Append(trProperties); } }
private void ProcessBorders(DocxNode node, DocxTableProperties docxProperties, TableCellProperties cellProperties) { string borderStyle = node.ExtractStyleValue(DocxBorder.borderName); string leftBorder = node.ExtractStyleValue(DocxBorder.leftBorderName); string topBorder = node.ExtractStyleValue(DocxBorder.topBorderName); string rightBorder = node.ExtractStyleValue(DocxBorder.rightBorderName); string bottomBorder = node.ExtractStyleValue(DocxBorder.bottomBorderName); TableCellBorders cellBorders = new TableCellBorders(); DocxBorder.ApplyBorders(cellBorders, borderStyle, leftBorder, topBorder, rightBorder, bottomBorder, docxProperties.HasDefaultBorder); if (cellBorders.HasChildren) { cellProperties.Append(cellBorders); } }
private void ProcessBorders(DocxNode node, DocxTableProperties docxProperties, TableCellProperties cellProperties) { string borderStyle = node.ExtractStyleValue(DocxBorder.borderName); string leftBorder = node.ExtractStyleValue(DocxBorder.leftBorderName); string topBorder = node.ExtractStyleValue(DocxBorder.topBorderName); string rightBorder = node.ExtractStyleValue(DocxBorder.rightBorderName); string bottomBorder = node.ExtractStyleValue(DocxBorder.bottomBorderName); TableCellBorders cellBorders = new TableCellBorders(); DocxBorder.ApplyBorders(cellBorders, borderStyle, leftBorder, topBorder, rightBorder, bottomBorder, docxProperties.HasDefaultBorder); if (cellBorders.HasChildren) { cellProperties.Append(cellBorders); } }
private void ProcessVerticalSpan(ref int colIndex, TableRow row, DocxTableProperties docxProperties) { int rowSpan; docxProperties.RowSpanInfo.TryGetValue(colIndex, out rowSpan); while (rowSpan > 0) { TableCell cell = new TableCell(); cell.TableCellProperties = new TableCellProperties(); cell.TableCellProperties.Append(new VerticalMerge()); cell.AppendChild(new Paragraph()); row.Append(cell); docxProperties.RowSpanInfo[colIndex] = --rowSpan; ++colIndex; docxProperties.RowSpanInfo.TryGetValue(colIndex, out rowSpan); } }
private void ProcessTd(int colIndex, DocxNode td, TableRow row, DocxTableProperties tableProperties) { TableCell cell = new TableCell(); bool hasRowSpan = false; string rowSpan = td.ExtractAttributeValue(DocxTableProperties.rowSpan); Int32 rowSpanValue; if (Int32.TryParse(rowSpan, out rowSpanValue)) { tableProperties.RowSpanInfo[colIndex] = rowSpanValue - 1; hasRowSpan = true; } DocxTableCellStyle style = new DocxTableCellStyle(); style.HasRowSpan = hasRowSpan; style.Process(cell, tableProperties, td); if (td.HasChildren) { Paragraph para = null; //If the cell is th header, apply font-weight:bold to the text if (tableProperties.IsCellHeader) { SetThStyleToRun(td); } foreach (DocxNode child in td.Children) { td.CopyExtentedStyles(child); if (child.IsText) { if (!IsEmptyText(child.InnerHtml)) { if (para == null) { para = cell.AppendChild(new Paragraph()); OnParagraphCreated(DocxTableCellStyle.GetHtmlNodeForTableCellContent(td), para); } Run run = para.AppendChild(new Run(new Text() { Text = ClearHtml(child.InnerHtml), Space = SpaceProcessingModeValues.Preserve })); RunCreated(child, run); } } else { child.ParagraphNode = DocxTableCellStyle.GetHtmlNodeForTableCellContent(td); child.Parent = cell; td.CopyExtentedStyles(child); ProcessChild(child, ref para); } } } //The last element of the table cell must be a paragraph. var lastElement = cell.Elements().LastOrDefault(); if (lastElement == null || !(lastElement is Paragraph)) { cell.AppendChild(new Paragraph()); } row.Append(cell); }
private void ProcessTd(int colIndex, DocxNode td, TableRow row, DocxTableProperties tableProperties) { TableCell cell = new TableCell(); bool hasRowSpan = false; string rowSpan = td.ExtractAttributeValue(DocxTableProperties.rowSpan); Int32 rowSpanValue; if (Int32.TryParse(rowSpan, out rowSpanValue)) { tableProperties.RowSpanInfo[colIndex] = rowSpanValue - 1; hasRowSpan = true; } DocxTableCellStyle style = new DocxTableCellStyle(); style.HasRowSpan = hasRowSpan; style.Process(cell, tableProperties, td); if (td.HasChildren) { Paragraph para = null; //If the cell is th header, apply font-weight:bold to the text if (tableProperties.IsCellHeader) { SetThStyleToRun(td); } foreach (DocxNode child in td.Children) { td.CopyExtentedStyles(child); if (child.IsText) { if (!IsEmptyText(child.InnerHtml)) { if (para == null) { para = cell.AppendChild(new Paragraph()); OnParagraphCreated(DocxTableCellStyle.GetHtmlNodeForTableCellContent(td), para); } Run run = para.AppendChild(new Run(new Text() { Text = ClearHtml(child.InnerHtml), Space = SpaceProcessingModeValues.Preserve })); RunCreated(child, run); } } else { child.ParagraphNode = DocxTableCellStyle.GetHtmlNodeForTableCellContent(td); child.Parent = cell; td.CopyExtentedStyles(child); ProcessChild(child, ref para); } } } //The last element of the table cell must be a paragraph. var lastElement = cell.Elements().LastOrDefault(); if (lastElement == null || !(lastElement is Paragraph)) { cell.AppendChild(new Paragraph()); } row.Append(cell); }
private void ProcessVerticalSpan(ref int colIndex, TableRow row, DocxTableProperties docxProperties) { int rowSpan; docxProperties.RowSpanInfo.TryGetValue(colIndex, out rowSpan); while (rowSpan > 0) { TableCell cell = new TableCell(); cell.TableCellProperties = new TableCellProperties(); cell.TableCellProperties.Append(new VerticalMerge()); cell.AppendChild(new Paragraph()); row.Append(cell); docxProperties.RowSpanInfo[colIndex] = --rowSpan; ++colIndex; docxProperties.RowSpanInfo.TryGetValue(colIndex, out rowSpan); } }
private void ProcessTBody(DocxNode tbody, Table table, DocxTableProperties tableProperties) { foreach (DocxNode tr in tbody.Children) { if (string.Compare(tr.Tag, DocxTableProperties.trName, StringComparison.InvariantCultureIgnoreCase) == 0) { tbody.CopyExtentedStyles(tr); ProcessTr(tr, table, tableProperties); } } }
internal override void Process(DocxNode node, ref Paragraph paragraph) { if (node.IsNull() || node.Parent == null || !CanConvert(node) || IsHidden(node)) { return; } paragraph = null; if (node.HasChildren) { Table table = new Table(); DocxTableProperties tableProperties = new DocxTableProperties(); tableProperties.FetchTableProperties(node); tableProperties.ApplyTableProperties(table, node); foreach (DocxNode child in node.Children) { if (string.Compare(child.Tag, DocxTableProperties.trName, StringComparison.InvariantCultureIgnoreCase) == 0) { node.CopyExtentedStyles(child); ProcessTr(child, table, tableProperties); } else if (string.Compare(child.Tag, DocxTableProperties.tbody, StringComparison.InvariantCultureIgnoreCase) == 0) { node.CopyExtentedStyles(child); ProcessTBody(child, table, tableProperties); } } node.Parent.Append(table); } }
internal void Process(TableProperties tableProperties, DocxTableProperties docxProperties, DocxNode node) { ProcessWidth(node, tableProperties); ProcessTableBorder(node, docxProperties, tableProperties); ProcessTableCellMargin(docxProperties, tableProperties); }
private void ProcessTr(DocxNode tr, Table table, DocxTableProperties tableProperties) { if (tr.HasChildren) { TableRow row = new TableRow(); DocxTableRowStyle style = new DocxTableRowStyle(); style.Process(row, tableProperties); int colIndex = 0; foreach (DocxNode td in tr.Children) { ProcessVerticalSpan(ref colIndex, row, tableProperties); tableProperties.IsCellHeader = string.Compare(td.Tag, DocxTableProperties.thName, StringComparison.InvariantCultureIgnoreCase) == 0; if (string.Compare(td.Tag, DocxTableProperties.tdName, StringComparison.InvariantCultureIgnoreCase) == 0 || tableProperties.IsCellHeader) { tr.CopyExtentedStyles(td); ProcessTd(colIndex++, td, row, tableProperties); } } if (colIndex < tableProperties.RowSpanInfo.Count) { ProcessVerticalSpan(ref colIndex, row, tableProperties); } table.Append(row); } }