- 1 public ActionResult Index()
- 2 {
- 3 stringtmppath = Server.MapPath("~/2.doc");
- 4Document doc =newDocument(tmppath);//载入模板
- 5
- 6
- 7Dictionary<string,string> dictionnary =newDictionary<string,string>();
- 8dictionnary.Add("姓名","杨幂");
- 9dictionnary.Add("学历","本科");
- 10dictionnary.Add("联系方式","12345123");
- 11dictionnary.Add("邮箱","");
- 12dictionnary.Add("内容","上去就是干");
- 13
- 14 foreach(varitemin dictionnary)
- 15 {
- 16 varkey =string.Format("&{0}&", item.Key);
- 17
- 18 //doc.Range.Replace()
- 19
- 20doc.Range.Replace(key, item.Value,new FindReplaceOptions())
- 21 // doc.MailMerge.Execute(key, item.Value,false,false); //此函数已被标记弃用
- 22 }
- 23 //if (doc.Range.Bookmarks["Name"] != null)
- 24 //{
- 25 // Bookmark mark = doc.Range.Bookmarks["name"];
- 26 // mark.Text = aModel.Name;
- 27 //}
- 28
- 29 vardocStream =new MemoryStream();
- 30 doc.Save(docStream, SaveFormat.Doc);
- 31 //doc.Save(docStream, SaveOptions.CreateSaveOptions(SaveFormat.Doc));
- 32 returnFile(docStream.ToArray(),"application/msword","Template.doc");
- 33}
来源: