开发者

Replacing some text in PowerPoint

I use Microsoft.Office.Interop.PowerPoint to replace some specific token at each slide from a *.pptx presentation.

The problem is that the开发者_运维技巧 text box in which the token resides has lines which are formatted in different ways (e.g. lines with different font size).

I actually tried doing the replacement by both

shape.TextFrame.TextRange.Text = strStartText + replacementString + strEndText;

and

shape.TextFrame.TextRange.Text = 
    shape.TextFrame.TextRange.Text.Replace(oldString, replacementString);

But it unifies and thus spoils all the formatting of my textbox. All the lines and words are now having the same size/colour etc.

Is there any solution to this?


PowerPoint's .TextRange objects have a .Replace method that works similarly to VB/VBA's Replace command, but it preserves formatting.

Example, assuming you have a reference to the shape in the variable oSh:

With oSh
    With .TextFrame.TextRange
        .Replace findwhat:=oldString, replacewhat:= replacementString
    End With
End With
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜