2

Using the OpenXmlSDK 2.0 I am reading and writing to powerpoint documents. We have a situation where a simple string within a powerpoint document has its whitespace stripped.

The example sentence within a single paragraph occurs when several inline markup changes are made to the one paragraph. It can be a little tricky to recreate the markup below, but writing the sentence in full using the powerpoint markup and then applying the formatting seems to produce the results below.

The quick brown fox.

This results in markup roughly similar to:

<a:p>
    <a:r>
        <a:t>The</a:t>
    </a:r>

    <a:r>
        <a:t> </a:t>
    </a:r>

    <a:r>
        <a:t b="1">quick</a:t>
    </a:r>

    <a:r>
        <a:t> </a:t>
    </a:r>

    <a:r>
        <a:t i="1">brown</a:t>
    </a:r>

    <a:r>
        <a:t> fox</a:t>
    </a:r>

</a:p>

This all looks like it's working fine, and opens correctly within the PowerPoint client. But when opening, making changes elsewhere in the presentation using the OpenXmlSDK, saving and closing the document the markup has been simplified to:

<a:p>
    <a:r>
        <a:t>The</a:t>
    </a:r>

    <a:r>
        <a:t /> <!-- Whitespace missing, causes PowerPoint to ignore it. -->
    </a:r>

    <a:r>
        <a:t b="1">quick</a:t>
    </a:r>

    <a:r>
        <a:t /> <!-- Whitespace missing, causes PowerPoint to ignore it. -->
    </a:r>

    <a:r>
        <a:t i="1">brown</a:t>
    </a:r>

    <a:r>
        <a:t> fox</a:t>
    </a:r>

</a:p>

Is there a trick to indicate in the markup to retain the space? Or another way we can structure these runs to include the spaces?

damoe
  • 221
  • 1
  • 3
  • I've done this without the SDK - just plain Linq and System.IO.Packaging. For the SlidePart, you just want to set `slide = XElement.Load(New StreamReader(slidePart.GetStream), LoadOptions.PreserveWhitespace)`. The SDK already thinks it knows what it is doing, so I don't think you'll have much luck there. Other options may be to preserve your whitespace via code in advance in one of the text tags. It appears you may just be doing some kind of split on words, using whitespace as the delimiter. Maybe try a different approach? – Todd Main May 28 '11 at 04:25
  • Thanks, the approach I've gone with so far is to clean up the markup in code before continuing. I felt like I was missing something in the SDK, it doesn't seem like desired behaviour. Also the WordProcessing Text element seemed to have a specific "space" attribute. – damoe May 30 '11 at 06:32
  • Why aren't the SDK people fixing this already? It's already been more than 1 year since the problem was reported... sigh... – Harvey Darvey Oct 23 '12 at 06:51

1 Answers1

0

You need to do <a:t xml:space="preserve"> </a:t>

The xml:space="preserve" tells it to hang on to the whitespace (written from memory - may have the syntax wrong).

David Thielen
  • 28,723
  • 34
  • 119
  • 193
  • This is ideally what I was looking for, however the xml:space attribute is not able to be added through the SDK for the Text element within the DrawingML namespace. The WordProcessing element supports this element but not the . – damoe May 25 '11 at 08:04