0

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();
        }
Deduplicator
  • 44,692
  • 7
  • 66
  • 118
cdub
  • 24,555
  • 57
  • 174
  • 303

1 Answers1

6

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

jn1kk
  • 5,012
  • 2
  • 45
  • 72