简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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