以下是如何创建邮件合并并将数据合并到其中的详细信息。
第 1 步:创建一个新的 Word 文档并添加部分和段落。
Document doc = new Document();Section sec = doc.AddSection();Paragraph para = sec.AddParagraph();
第 2 步:在段落中添加两个邮件合并模板。
para.AppendText("Quantity: ");para.AppendField("Quantity", FieldType.FieldMergeField);para.AppendBreak( BreakType.LineBreak);para.AppendText("Date: ");para.AppendField("Date", FieldType.FieldMergeField);
第 3 步:通过字段名设置邮件合并模板的值。
string[] fieldName = { "Quantity", "Date"};string[] fieldValue = { "1800", DateTime.Now .ToShortDateString()};
第 4 步:将指定的值合并到模板中。
doc.MailMerge.Execute(fieldName, fieldValue);
第 5 步:将文档保存到文件中。
doc.SaveToFile("result.docx", FileFormat.Docx);
邮件合并的有效截图:

完整代码:
using Spire.Doc;using Spire.Doc.Documents;using System;namespace MailMerge{class Program{static void Main(string[] args){Document doc = new Document();Section sec = doc.AddSection();Paragraph para = sec.AddParagraph();para.AppendText("Quantity: ");para.AppendField("Quantity", FieldType.FieldMergeField);para.AppendBreak(BreakType.LineBreak);para.AppendText("Date: ");para.AppendField("Date", FieldType.FieldMergeField);string[] fieldName = { "Quantity", "Date" };string[] fieldValue = { "1800", DateTime.Now.ToShortDateString() };doc.MailMerge.Execute(fieldName, fieldValue);doc.SaveToFile("result.docx", FileFormat.Docx);}}
欢迎下载|体验更多E-iceblue产品
如需获取更多产品相关信息请咨询在线客服
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!