2

I have a confusion about the workings of the Word OpenXml elements Run, Break and Text when it comes to the Text's space="preserve" directive.

If I have a set of elements such as:

 <w:p>
    <w:r>
       <w:t xml:space="preserve">Medical Admissions are counted where blah</w:t>
    </w:r>
    <w:r>
        <w:br />
        <w:t xml:space="preserve">Surgical Admissions are counted where blah</w:t>
    </w:r>
</w:p>

Then Word shows this as below - note the leading space before Surgical:

   Medical Admissions are counted where the  blah blah blah</w:t>
    Surgical Admissions are counted where the blah</w:t>

If I remove the space="preserve" attribute, then all is good unless the Run ends in a trailing space. Then I need to preserve the trailing space, but then the unwanted leading space reappears.

Both Run elements have space="preserve", so why does Word not show a space on the first Run in the Paragraph, but does show a space after the Break, even though there is no leading whitespace to be preserved?

I've tried putting the Break element into its own Run element - same result.

Neil Moss
  • 6,598
  • 2
  • 26
  • 42
  • 1
    I've created blank document and replaced paragraph's xml to one you specified. I see no leading space when I open document in MSWord(2013). – Shelest Aug 26 '15 at 14:46

1 Answers1

0

You could use the Unicode character U+2008 PUNCTUATION SPACE instead of the usual U+0020 SPACE. This will create a breaking space that is preserved in a text element within a run.

David A Stumpf
  • 753
  • 5
  • 13