0

我正在尝试使用 Open Office XML 输出 word 文件,但似乎无法正确设置间距。

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

我希望单词文件是这样的(:) 后有空格:

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

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

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

1 回答 1

6

通常,OpenXML 会修剪每个Text成员。为了保留每个Text成员中的空格,因此您将使用 thistest test而不是test test,设置成员的特殊Space属性Text

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

于 2012-07-16T17:05:34.980 回答