How can I programmatically insert RTF text into a PowerPoint text frame using C#?

烂漫一生 提交于 2021-02-08 11:21:11

问题


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;

This answer gets me close: Is it possible to insert pieces of RTF text into a Word document (.docx) using OpenXml?

But I am having trouble figuring out how to do this in PowerPoint rather than Word.

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.

Thanks.


回答1:


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);

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);


来源:https://stackoverflow.com/questions/64777175/how-can-i-programmatically-insert-rtf-text-into-a-powerpoint-text-frame-using-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!