I'm generating a simple Word (docx) document using the Open XML SDK. One think I'm struggling with is how to stop table cell contents from wrapping. Here's my code for generating a table cell:
private TableCell CreateTableCell(string text, int padding)
{
string marginWidth = padding.ToString(CultureInfo.InvariantCulture);
return new TableCell(
new Paragraph(new Run(new Text(text))),
new TableCellProperties(
new TableCellWidth { Type = TableWidthUnitValues.Auto },
new NoWrap(),
new TableCellMargin(
new LeftMargin { Type = TableWidthUnitValues.Dxa, Width = marginWidth },
new TopMargin { Type = TableWidthUnitValues.Dxa, Width = marginWidth },
new RightMargin { Type = TableWidthUnitValues.Dxa, Width = marginWidth },
new BottomMargin { Type = TableWidthUnitValues.Dxa, Width = marginWidth })));
}
This results in the table cell width having a type of "dxa"---rather than "auto"---even though I've specified auto. And, if I replace all these "dxa" values with "auto" manually, in the xml document, then the document is as required. So, clearly my "auto" value is being ignored.
What am I missing here?