在this site中,有一个关于使用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);
}发布于 2012-08-16 12:28:49
第一段接受两个数组的代码是用于.NET的Aspose Word,这是一个独立于MS Word的组件。
MS Word MailMerge.Execute()是一种不同的方法,它只接受一个可选参数。
要在安装了C#和office的情况下自动执行邮件合并,请参阅以下文章:
KB301659 How to automate Microsoft Word to perform Mail Merge from Visual C#
http://everythingsharepoint.blogspot.in/2011/12/c-microsoft-word-2010-automated-mail.html
http://everythingsharepoint.blogspot.in/2011/12/c-microsoft-word-2010-automated-mail_01.html
https://stackoverflow.com/questions/11980564
复制相似问题