如何使用 C# 以编程方式将 RTF 文本插入到 PowerPoint 文本框架中? [英] How can I programmatically insert RTF text into a PowerPoint text frame using C#?
问题描述
有没有办法以编程方式将 RTF 格式的文本插入到 PowerPoint TextFrame 中?
Is there any way to programmatically insert RTF-formatted text into a PowerPoint TextFrame?
string myString = <some RTF formatted text>;
MyPlaceholder.TextFrame.TextRange.Text = myString;
这个答案让我很接近:是否可以使用 OpenXml 将 RTF 文本片段插入到 Word 文档 (.docx) 中?
但我无法弄清楚如何在 PowerPoint 而不是 Word 中执行此操作.
But I am having trouble figuring out how to do this in PowerPoint rather than Word.
我想要做的是将文本从我的应用程序中的 RichEditBox 复制到 PowerPoint 幻灯片上并保持字体颜色、格式等.我能够成功地将文本带入 PowerPoint.我就是不能带上格式(比如字体颜色).
What I am trying to do is copy text from a RichEditBox in my application onto a PowerPoint slide and maintain font-color, format, etc. I am able to successfully bring the text into PowerPoint. I just can't bring in the formatting (such as font-color) with it.
谢谢.
推荐答案
我终于能够通过使用以下代码行从 RichEditBox 保存到流,然后写入文件来完成此操作:
I was finally able to accomplish this by saving from the RichEditBox to a stream using the following line of code and then writing to a file:
tempRichEditBox.Document.SaveToStream(Windows.UI.Text.TextGetOptions.FormatRtf, randAccStream);
然后我使用这一行将文件导入到 PowerPoint 中.字体颜色和格式保持不变.
I then used this line to import the file into PowerPoint. The font color and formatting are maintained.
var rtfShape = PptSlide.Shapes.AddOLEObject(FileName: rtfFileName);
这篇关于如何使用 C# 以编程方式将 RTF 文本插入到 PowerPoint 文本框架中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!