2012-09-19 83 views
5

我有一個奇怪的問題,使用Open XML生成.docx。我有一個TableCell具有Paragraph然後Run那麼產生這樣Text打開XML段落間距

tblRow.Append(new TableCell(new Paragraph(GetPropertiesForStyle("TableDescription"), new Run(new Text(colName))))); 

GetPropertiesForStyle方法返回ParagraphProperties的特定段落,並設置樣式。這一切都可以正常工作,但是在表格行中,第一個單元格在之前似乎具有雙倍間距,而最後一個單元格之後具有雙倍間距 - 中間的所有單元格都非常精細。

enter image description here

我的風格的配置是這樣的:

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 } 
    ) 
), 

我使用的生產力工具檢查所產生XML和它的應用性能完全正常。每個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> 

任何想法是怎麼回事?

回答

5

管理加入到解決這個問題下面以我的風格:

new ContextualSpacing() { Val = false } 

告訴字取消選中不要在段落的選項相同的樣式的段落之間添加空間。