如何在 OpenXML/PresentationML/C# 中的 PowerPoint (PPTX) 中插入换行符 [英] How to insert a newline in PowerPoint (PPTX) in OpenXML / PresentationML / C#

查看:94
本文介绍了如何在 OpenXML/PresentationML/C# 中的 PowerPoint (PPTX) 中插入换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然 Word 和 PowerPoint 都使用 OpenXML,但换行的处理方式不同.在 Word/WordprocessingML 中,您可以 run.Append(new Break())(参见 此处) 插入换行符.不幸的是,在 PresentationML 中,这会导致演示文稿无效并在 PowerPoint 中加载时出错.

While Word and PowerPoint both use OpenXML, newlines are handled differently. In Word/WordprocessingML you can run.Append(new Break()) (see here) to insert a newline. Unfortunately in PresentationML this leads to a nonvalid presentation and with errors when loading it in PowerPoint.

如何在 PowerPoint ShapeTextBody 中添加换行符?

How to add a newline in the TextBody of a PowerPoint Shape?

推荐答案

Open Office SDK 2.5 的 Open XML Productivity Tool 有这个很棒的反射代码工具,可以获取您拥有的任何 OpenXML 文件的 C# 代码.但尤其是经过大量编辑后,演示文稿中的文本会被拆分为各种 Run 元素,并且 reflect code 不是很紧凑.下面是 ShapeTextBody 示例.

The Open XML Productivity Tool of Open Office SDK 2.5 has this great Reflect Code tool to get C# code of whatever OpenXML file you have. But especially after much editing, the text in a presentation gets splitted in various Run elements and the reflect code isn't very compact. Here's an example of a TextBody of a Shape.

new TextBody(
  new A.BodyProperties(),
  new A.Paragraph(
    new A.Run( new A.Text("first line") ),
    new A.Break(),
    new A.Run( new A.Text("second line") )
  ),
  new A.Paragraph(
    new A.Run( new A.Text("new paragraph") )
  )
)

注意,BreakParagraph 的子级,而不是 Run 的子级(就像在 WordprocessingML).

Note, the Break is child of the Paragraph, not child of a Run (as it is in WordprocessingML).

请注意,Break 会换行(PowerPoint 中的 Shift-Return),如果您想要一个新段落(PowerPoint 中的返回),则需要一个新的 Paragraph.

Note, that the Break makes a newline (Shift-Return in PowerPoint), if you want a new paragraph (Return in PowerPoint), you'll need a new Paragraph.

这篇关于如何在 OpenXML/PresentationML/C# 中的 PowerPoint (PPTX) 中插入换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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