如何使用open xml对齐中心段落c#

时间:2018-03-30 07:39:54

标签: c# ms-word openxml openxml-sdk

我正在尝试对齐以使段落居中,但对段落没有任何感情。我正在使用OpenXml。以下是代码:

//paragraph properties 
ParagraphProperties User_heading_pPr = new ParagraphProperties();

//trying to align center a paragraph
Justification justification1 = new Justification() { Val = JustificationValues.Center };

// build paragraph piece by piece
Text text = new Text(DateTime.Now.ToString() + " , ");
Text text1 = new Text(gjenerimi + " , ");
Text text2 = new Text(merreshifren());
var run = new Run();
run.Append(text,text1,text2);
Paragraph newParagraph = new Paragraph(run);
User_heading_pPr.Append(justification1);
newParagraph.Append(User_heading_pPr);

以下是我尝试对齐段落中心的方法。

1 个答案:

答案 0 :(得分:0)

颠倒您指定文字和段落属性的顺序:

User_heading_pPr.Append(justification1);
Paragraph newParagraph = new Paragraph(User_heading_pPr);
newParagraph.Append(run);

在有效且格式良好的Word Open XML中,段落属性必须在运行之前。因此,您必须以相同的方式构建Open XML文档。

这与对象模型有点不同,我们通常用它来处理它们 - 顺序很重要!