我使用 Microsoft.Office.Interop.PowerPoint
替换 *.pptx 演示文稿中每张幻灯片上的某些特定标记。
问题在于 token 所在的文本框具有不同格式的行(例如具有不同字体大小的行)。
我实际上尝试过用两者进行替换
shape.TextFrame.TextRange.Text = strStartText + replacementString + strEndText;
和
shape.TextFrame.TextRange.Text =
shape.TextFrame.TextRange.Text.Replace(oldString, replacementString);
但它统一了,从而破坏了我的文本框的所有格式。 所有线条和文字现在都具有相同的大小/颜色等。
有什么解决办法吗?
最佳答案
PowerPoint 的 .TextRange 对象有一个 .Replace 方法,其工作方式与 VB/VBA 的 Replace 命令类似,但它保留格式。
示例,假设您在变量 oSh 中引用了形状:
With oSh
With .TextFrame.TextRange
.Replace findwhat:=oldString, replacewhat:= replacementString
End With
End With
关于office-interop - 替换 PowerPoint 中的某些文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6802716/