简体   繁体   English

在Open Office XML中添加空格和空白行

[英]Adding spacing and blank lines to Open Office XML

I am trying to output a word file using Open Office XML, but can't seem to get spacing correct. 我正在尝试使用Open Office XML输出word文件,但似乎无法正确获得间距。

Variable name:ATTEND
 Description:Student's attendance status during the 

I want the word file to be this (with spaces after the :): 我希望单词文件是这个(在:之后带有空格):

Variable name: ATTEND
Description:Student's attendance status during the 

My code is as follow, and the spacing disappears: 我的代码如下,并且间距消失了:

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();
        }

Usually, OpenXML will trim every Text member. 通常,OpenXML将修剪每个Text成员。 To preserve the spaces in each Text member, so you will have this test test instead of test test , set the special Space property of the Text member: 要保留每个Text成员中的空格,因此您将拥有此test test而不是test test ,请设置Text成员的特殊Space属性:

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

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

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