文档半岛外围网上直营>>E-iceblue中文文档>>从 Word 文档中删除文本或图像水印
从 Word 文档中删除文本或图像水印
字替换功能使用户可以用新的字符串替换指定的字符串。将一次检测并替换所有字符串数。Spire.Doc for .NET提供了document.Replace方法来实现C#、VB.NET 中的替换功能。以下截图是替换后的结果。
通过调用 document.Replace 方法,用户可以用新值替换特定字符串,并设置替换是否区分大小写或影响整个单词。document.Replace 方法提供了五种可能性。
- 用新值字符串替换 matchString(将被替换)正则表达式的所有条目。
- 用文本范围持有者替换 matchString 正则表达式的所有条目。
- 替换 matchDoc(指定文档)中指定的 matchString,同时考虑区分大小写和全字选项。
- 将 mathString 的所有条目替换为新值字符串,同时考虑区分大小写和全字选项。
- 将 matchString 的所有条目替换为文本选择,同时考虑区分大小写和整个单词的选项。
本指南将介绍如何实现上述第四种可能性,将加载文档中的字符串“新西兰”替换为“NZ”。下载并安装 Spire.Doc for .NET。按照代码:
[C#]
using Spire.Doc;
namespace ReplaceString
{
class Program
{
static void Main(string[] args)
{
Document document = new Document();
document.LoadFromFile(@"E:\Work\Documents\WordDocuments\New Zealand.docx");
document.Replace("New Zealand", "NZ", false, true);
document.SaveToFile("Replace.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("Replace.docx");
}
}
}
[VB]
Imports Spire.Doc
Namespace ReplaceString
Friend Class Program
Shared Sub Main(ByVal args() As String)
Dim document As New Document()
document.LoadFromFile("E:\Work\Documents\WordDocuments\New Zealand.docx")
document.Replace("New Zealand", "NZ", False, True)
document.SaveToFile("Replace.docx", FileFormat.Docx)
System.Diagnostics.Process.Start("Replace.docx")
End Sub
End Class
End Namespace
Spire.Doc 是一个专业的 Word 组件,使开发人员/程序员能够执行广泛的处理任务,例如为其自定义的 .NET、Silverlight 和 WPF 应用程序生成、编写、修改和保存。

QQ交谈
在线咨询

渝公网安备
50010702500608号

客服热线