OpenXml.WordProcessing.Justification always comes as OpenXmlUnknownElement

857 views Asked by At

I'm building a table using OpenXml and setting the Justification property for every cell. It doesn't really matter where I assign this property, either in the Run element or as a TableCellProperty, when the document is open using the Productivity Tool for MS Office the Justification element always comes as OpenXmlUnknownElement. This is an example:

TableCell tc = new tbl.TableCell();
tc.Append(new tbl.TableCellProperties(new tbl.Justification() { Val = tbl.JustificationValues.Right }));

The text is justified but when converting the docx file into pdf, the justification is gone, and I guess because of this OpenXmlUnknownElement issue.

Edit: The problem I have is that when setting the Justification property on the ParagrahProperties for the paragraph, it doesn't make the alignment. It only works if the ParagrahProperties is a direct child of TableCell:

tc.AppendChild<tbl.ParagraphProperties>(paragraphProperties);

But then I get a OpenXmlUnknownElement. If I append the properties directly to the paragraph I don't get the OpenXmlUnknownElement but it doesn't make the aligment at all

1

There are 1 answers

2
jn1kk On BEST ANSWER

You need to read the documentation. TableCellProperties doesn't take the a Justification element. Link

If you are trying to align elements within a cell, you need to put it into ParagraphProperties.