向Open Office XML添加间距和空行

cdu*_*dub 0 c# ms-word openxml openxml-sdk

我正在尝试使用Open Office XML输出word文件,但似乎无法获得正确的间距.

Variable name:ATTEND
 Description:Student's attendance status during the 
Run Code Online (Sandbox Code Playgroud)

我希望word文件是这样的(在:)之后有空格:

Variable name: ATTEND
Description:Student's attendance status during the 
Run Code Online (Sandbox Code Playgroud)

我的代码如下,间距消失:

start of my function
// Add a new main document part. 
            MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();

            // Create the Document DOM.
            mainPart.Document = new Document();

            Body body = mainPart.Document.AppendChild(new Body());

            ParagraphProperties paragraphProperties = new ParagraphProperties
            (
                new ParagraphStyleId() { Val = "No Spacing" },
                new SpacingBetweenLines() { After = "0" }
            );

            Paragraph para = body.AppendChild(new Paragraph(paragraphProperties));
            Run run = para.AppendChild(new Run());

            RunProperties runProperties = run.AppendChild(new RunProperties(new Bold()));
            run.AppendChild(new Text("Variable name: "));

            run = para.AppendChild(new Run());
            run.AppendChild(new Text(" ATTEND"));

            para = body.AppendChild(new Paragraph());

            run = para.AppendChild(new Run());

            runProperties = run.AppendChild(new RunProperties(new Bold()));
            run.AppendChild(new Text("Description: "));

            run = para.AppendChild(new Run());
            run.AppendChild(new Text(" Student's attendance status during the "));


            // Save changes to the main document part. 
            wordDocument.MainDocumentPart.Document.Save();
        }
Run Code Online (Sandbox Code Playgroud)

jn1*_*1kk 6

通常,OpenXML会削减每个Text成员.为了保留每个Text成员中的空格,所以你将使用它test test来代替test test,设置成员的特殊Space属性Text:

Text txt = new Text("text here ") { Space = SpaceProcessingModeValues.Preserve };