【发布时间】:2009-09-30 19:40:49
【问题描述】:
我有一个 Word 文档,我想打开它并用单词“test”替换社会安全号码的所有实例。
我已经有了打开文档的代码。这是进行替换的代码。但是,此时我在使用正则表达式时遇到了问题: _wordApp.Selection.Find.Text = ; 在我的代码中。使用正则表达式是一种好方法还是有更好的方法?请记住,我必须匹配任何社会安全号码......因此: \b[0-9]{3}-[0-9]{2}-[0-9]{4}\b 或 \b [0-9]{3}[0-9]{2}[0-9]{4}\b
提前谢谢...
object replaceAll = Werd.WdReplace.wdReplaceAll;
_wordApp.Selection.Find.ClearFormatting();
_wordApp.Selection.Find.Text = ;
_wordApp.Selection.Find.Replacement.ClearFormatting();
_wordApp.Selection.Find.Replacement.Text = "test";
_wordApp.Selection.Find.Execute(ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref replaceAll, ref nullobj, ref nullobj, ref nullobj, ref nullobj);
【问题讨论】: