ReplaceText

TextFrame.ReplaceText method

用另一个指定文本替换所有指定文本的出现。

public void ReplaceText(string oldText, string newText, ITextSearchOptions options, 
    IFindResultCallback callback)
参数类型描述
oldTextString要被替换的字符串。
newTextString用于替换所有出现的 oldText 的字符串。
optionsITextSearchOptions文本搜索选项 ITextSearchOptions
callbackIFindResultCallback保存替换操作结果的回调对象 IFindResultCallback

示例

以下示例代码展示了如何将一个指定字符串替换为另一个指定字符串。

[C#]
using (Presentation presentation = new Presentation("SomePresentation.pptx")){
	// 用 '***' 替换所有单独的 'the' 出现
	((AutoShape)presentation.Slides[0].Shapes[0]).TextFrame.ReplaceText("the", "***", new TextSearchOptions()
	{ WholeWordsOnly = true }, null);
	presentation.Save("SomePresentation-out2.pptx", SaveFormat.Pptx);
}

另请参见