在Open Office XML中添加空格和空白行 [英] Adding spacing and blank lines to Open Office XML

查看:955
本文介绍了在Open Office XML中添加空格和空白行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to output a word file using Open Office XML, but can't seem to get spacing correct.

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

推荐答案

通常,OpenXML将修剪每个Text成员.要保留每个Text成员中的空格,因此将使用此test test而不是test test,请设置Text成员的特殊Space属性:

Usually, OpenXML will trim every Text member. 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 txt = new Text("text here ") { Space = SpaceProcessingModeValues.Preserve };

这篇关于在Open Office XML中添加空格和空白行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆