问题
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