日期:2014-05-17 浏览次数:21064 次
Word.Application docApp = new Word.Application();
docApp.Visible = true;
docApp.Activate();
string templatePath = AppDomain.CurrentDomain.BaseDirectory + "checkTemplate.dot";
Word.Document doc = docApp.Documents.Add(templatePath, ref oMissing, ref oMissing, ref oMissing);
StringBuilder sb = new StringBuilder(100);
sb.Append(' ', minLen);
string tag = "#DataNo#";
string str = "真实的数据";
object replaceAll = Word.WdReplace.wdReplaceAll;
object missing = Type.Missing;
//首先清除任何现有的格式设置选项,然后设置搜索字符串 strOldText。
docApp.Selection.Find.ClearFormatting();
docApp.Selection.Find.Text = tag;
docApp.Selection.Find.Replacement.ClearFormatting();
docApp.Selection.Find.Replacement.Text = str;
//执行替换操作
docApp.Selection.Find.Execute(
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref replaceAll, ref missing, ref missing, ref missing, ref missing);