ReplaceText

ITextFrame.ReplaceText 方法

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

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);
}

另请参见