我有两个“DEMO”字
我想用mergefield替换它
但是使用我的代码只更改了一个“演示”...
如何用字段替换文本?
谢谢
Application app = new Application();
Document word = new Document();
word = app.Documents.Add(ref path, ref missing, ref missing, ref missing);
object objType = WdFieldType.wdFieldMergeField;
object hashVal = null;
Hashtable hash = new Hashtable();
hash.Add("DEMO", "mergefield11111");
foreach (object s in hash.Keys)
{
Range rng = app.ActiveDocument.Content;
Find findObject = app.Selection.Find;
object ff = s;
hashVal = hash[s];
findObject.Text = ff.ToString();
findObject.ClearFormatting();
if (rng.Find.Execute(ref ff,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, WdReplace.wdReplaceOne, ref missing, ref missing,
ref missing, ref missing))
{
Field field = app.Selection.Fields.Add(app.Selection.Range, ref objType, ref hashVal, ref missing);
}
}
app.Documents.Open("test1.docx");