office-interop - 替换 PowerPoint 中的某些文本

标签 office-interop str-replace powerpoint-2007

我使用 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/

相关文章:

c# - 带参数的 Office Interop 构造函数

c# - 操作方法 : Stop adding files to "Recent files" in Quick Access when opening/saving files with Microsoft. Office.Interop

php - 如何检测并删除或替换我正在上传的文件名中的数字符号 (#)

vba - 使用 vba 在 PowerPoint 2007 中定位幻灯片上的图像

vba - 使用 VBA 更改 Office 功能区中元素的属性

vb.net - GetOccurrence总是抛出异常

c# - 尽管我刚刚保存了文档,但Visio提示我保存文档时要保存它

javascript - 使用 javascript 添加到当前字符串

r - 仅在 R 中从文本中删除单个正斜杠

OpenXML -PresentationML 克隆 - 损坏 Powerpoint