Does this work if you have to apply params to the parent cell and not to the paragraph?
Table table = new Table();
TableRow tableHeader = new TableRow();
table.AppendChild<TableRow>(tableHeader);
TableCell tableCell = new TableCell();
tableHeader.AppendChild<TableCell>(tableCell);
ParagraphProperties paragraphProperties = new ParagraphProperties();
Paragraph paragraph = new Paragraph(new Run(new Text("test")));
JustificationValues? justification = GetJustificationFromString("centre");
if (justification.HasValue)
{
paragraphProperties.AppendChild<Justification>(new Justification() { Val = justification.Value });
}
tableCell.AppendChild<ParagraphProperties>(paragraphProperties);
tableCell.AppendChild<Paragraph>(paragraph);
Console.WriteLine(table.OuterXml);
table.OuterXml before:
<w:tbl xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:tr>
<w:tc>
<w:p>
<w:r>
<w:t>test</w:t>
</w:r>
<w:pPr>
<w:jc w:val="center" />
</w:pPr>
</w:p>
</w:tc>
</w:tr>
</w:tbl>
table.OuterXml after:
<w:tbl xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:tr>
<w:tc>
<w:pPr>
<w:jc w:val="center" />
</w:pPr>
<w:p>
<w:r>
<w:t>test</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
</w:tbl>
I am new to OpenXml. Is the result saved in a text document and viewed in a word?
source
share