« Instant On Laptops | Main | Moving a project from VS 2005 to VS 2008 »

August 22, 2008

Inserting Rich Text into PowerPoint

I was trying to programmatically insert some rich text into a specific text box in PowerPoint.

I had a rich text box in a winform application that had some formatted text. I wanted this to be moved into a specific textbox in my PPT.

The first approach I tried was to set the text directly:

txt.TextFrame.TextRange.Text=rtfbox.Rtf

 

But then the actual rich text markups were copied into the text. So the incoming data was getting interpreted as normal text. Makes sense..

So the next I tried was to copy the data from the richtext and then pasting it into the frame. When you do this manually, PowerPoint recognizes the format and pastes the data as formatted text.

Clipboard.SetText(rtfbox.Rtf)

txt.TextFrame.TextRange.PasteSpecial(PpPasteDataType.ppPasteRTF)

 

 

Now I started getting a strange error – "The specified value is out of range." - when the Paste command executes.

After some changing of options and a search that did not yield any results, I suddenly thought, maybe if I force the clipboard type to be RTF then it may work. Yep it did.

Clipboard.SetText(rtfPreview.Rtf, TextDataFormat.Rtf)

.TextFrame.TextRange.PasteSpecial(PpPasteDataType.ppPasteRTF)

 

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83451a61969e200e5542cbc5e8833

Listed below are links to weblogs that reference Inserting Rich Text into PowerPoint:

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Comments are moderated, and will not appear until the author has approved them.