开发者

Replacing some text in PowerPoint

开发者 https://www.devze.com 2023-03-22 23:10 出处:网络
I use Microsoft.Office.Interop.PowerPoint to replace some specific token at each slide from a *.pptx presentation.

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

精彩评论

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