简体   繁体   English

使用 OpenXmlSDK 的 PPTX 段落中缺少空格

[英]Missing whitespace within PPTX paragraphs using OpenXmlSDK

Using the OpenXmlSDK 2.0 I am reading and writing to powerpoint documents.使用 OpenXmlSDK 2.0 我正在阅读和写入 powerpoint 文档。 We have a situation where a simple string within a powerpoint document has its whitespace stripped.我们有一种情况,PowerPoint 文档中的一个简单字符串的空格被剥离。

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.重新创建下面的标记可能有点棘手,但是使用 powerpoint 标记完整地编写句子然后应用格式似乎会产生下面的结果。

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.这一切看起来工作正常,并且在 PowerPoint 客户端中正确打开。 But when opening, making changes elsewhere in the presentation using the OpenXmlSDK, saving and closing the document the markup has been simplified to:但是在打开时,使用 OpenXmlSDK 在演示文稿的其他地方进行更改,保存和关闭文档时,标记已被简化为:

<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?或者我们可以用另一种方式来构建这些运行以包含空间?

You need to do <a:t xml:space="preserve"> </a:t>你需要做 <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). xml:space="preserve" 告诉它挂在空格上(写自 memory - 可能语法错误)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM