在这个站点中是一个关于使用 2 个数组和 MailMerge.Execute 方法进行邮件合并的示例,但该方法不接受 2 个参数。
无论如何,有没有办法用 2 个数组或 2 个列表做类似的事情?
谢谢。
这是他们使用的代码:
// Open an existing document.
Document doc = new Document(MyDir + "MailMerge.ExecuteArray.doc");
// Fill the fields in the document with user data.
doc.MailMerge.Execute(
new string[] {"FullName", "Company", "Address", "Address2", "City"},
new object[] {"James Bond", "MI5 Headquarters", "Milbank", "", "London"});
这是我要实现的方法:
private void ReplaceMailMergeField(String plantilla, String[] campos, Object[] valores)
{
Object oMissing = System.Reflection.Missing.Value;
Object oTrue = true;
Object oFalse = false;
Word.Application wordApp = new Word.Application();
Word.Document wordDoc = new Word.Document();
wordApp.Visible = true;
Object templatePath = plantilla;
wordDoc = wordApp.Documents.Add(ref templatePath, ref oMissing, ref oMissing, ref oMissing);
wordDoc.MailMerge.Execute(campos, valores);
}