简体   繁体   中英

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(ie generated ppt).But all alignments,pragraphs,formatting are gone. Is there any way to preserve it??

Thanks for stopping by...!!

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

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