Milind Anantwar
Milind Anantwar

Reputation: 82241

How to preserve formatting of textshape format of powerpoint slide using c#

I am using c# interop to get page content of shape text using below code:

var textRange = shape.TextFrame.TextRange;
var text = textRange.Text;

where text contains text of textshape. But all formatting gone. :(

We modify the content using our own editor and create ppt using the changed content:

string strToReplace = StripTagsRegex(xmlTempNode.InnerText);
strToReplace = strToReplace.Replace(" ", " ");
shape.TextFrame.TextRange.Text = strToReplace;//load new text to shape

I am getting the required text in final output(i.e. generated ppt).But all alignments,pragraphs,formatting are gone. Is there any way to preserve it??

Thanks for stopping by...!!

Upvotes: 0

Views: 1769

Answers (1)

Steve Rindsberg
Steve Rindsberg

Reputation: 14809

If you want to replace text within a PowerPoint shape and preserve the formatting, use PowerPoint's own Replace method.

In VBA:

With Shape.TextFrame.TextRange
  .Replace "this text", "with this text"
End With

Upvotes: 1

Related Questions