Aspose.Words的Replace函数可以实现对Word文档字符串的正则匹配及内容替换。
Aspose.Words -
Replace实现正则匹配及替换
1 Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| using Aspose.Words; using System.Text.RegularExpressions;
namespace ReplaceTest { class Program { static string MyDir = "C:\\Dev\\Test\\";
static void Main(string[] args) { Aspose.Words.Document mainDoc = new Document(MyDir + "in.docx");
mainDoc.Range.Replace(new Regex("__pattern1__"), "REPLACE1");
mainDoc.Save(MyDir + "out.docx"); } } }
|