简体   繁体   English

打开XML段落间距

[英]Open XML Paragraph Spacing

I have a strange problem generating a .docx with Open XML. 我在使用Open XML生成.docx时遇到一个奇怪的问题。 I have a TableCell that has a Paragraph then Run then Text generated like this: 我有一个TableCell ,它具有一个Paragraph然后Run然后生成Text如下所示:

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. GetPropertiesForStyle方法返回特定段落的ParagraphProperties并设置样式。 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. 我已经使用了生产力工具检查了生成的XML,并且它很好地应用了属性。 Each TableCell has the following configuration (there are some extra margin properties on there and a shader fill which I've omitted for brevity). 每个TableCell具有以下配置(那里有一些额外的边距属性,以及为简洁起见已省略的着色器填充)。

<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. 这会告诉单词取消选中段落选项中相同样式的段落之间不添加空格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM