I have a strange problem generating a .docx with Open XML. I have a TableCell
that has a Paragraph
then Run
then Text
generated like this:
tblRow.Append(new TableCell(new Paragraph(GetPropertiesForStyle("TableDescription"), new Run(new Text(colName)))));
The GetPropertiesForStyle
method returns the ParagraphProperties
for the specific paragraph and sets the style. This all works fine, however within the table row the first cell seems to have double spacing before and the last cell has double spacing after - all the cells in the middle look perfectly fine.
My style configuration looks like this:
new Style(
new StyleName() { Val = "TableDescription" },
new StyleParagraphProperties(
new ParagraphBorders(
new BottomBorder() { Val = BorderValues.None }
),
new SpacingBetweenLines() { Before = "100", After = "100", Line = "200", LineRule = LineSpacingRuleValues.Exact },
new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center }
)
),
I've checked the produced XML using the productivity tool and it's applying the properties perfectly fine. Each TableCell
has the following configuration (there are some extra margin properties on there and a shader fill which I've omitted for brevity).
<w:tc>
<w:p>
<w:pPr>
<w:pStyle w:val="TableDescription" />
</w:pPr>
<w:r>
<w:t>Reporting Period</w:t>
</w:r>
</w:p>
</w:tc>
Any ideas what's going on?
Managed to fix this by adding the following to my style:
new ContextualSpacing() { Val = false }
Which tells word to uncheck the Don't add space between paragraphs of the same style in paragraph options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With