public ActionResult ExportDetails(string keyValue) { HttpResponse resp = System.Web.HttpContext.Current.Response; var user = ERCHTMS.Code.OperatorProvider.Provider.Current(); Aspose.Words.Document doc = new Aspose.Words.Document(Server.MapPath("~/Resource/ExcelTemplate/安全设施变动模板.docx")); Aspose.Words.DocumentBuilder db = new Aspose.Words.DocumentBuilder(doc); var entity = new SafetychangeBLL().GetEntity(keyValue); var applyaudit = scaffoldauditrecordbll.GetApplyAuditList(keyValue, 0); var accpaudit = scaffoldauditrecordbll.GetApplyAuditList(keyValue, 1); DataTable dt = new DataTable(); dt.Columns.Add("applytime"); dt.Columns.Add("applyno"); dt.Columns.Add("workunit"); dt.Columns.Add("workfzr"); dt.Columns.Add("workcontent"); dt.Columns.Add("changename"); dt.Columns.Add("procedures"); dt.Columns.Add("applyfirst"); dt.Columns.Add("onetime"); dt.Columns.Add("applysecond"); dt.Columns.Add("twotime"); dt.Columns.Add("applythree"); dt.Columns.Add("threetime"); dt.Columns.Add("acceptance"); dt.Columns.Add("accpfirst"); dt.Columns.Add("fourtime"); dt.Columns.Add("accpsecond"); dt.Columns.Add("fivetime"); dt.Columns.Add("accpthree"); dt.Columns.Add("sixtime"); DataRow row = dt.NewRow(); string time = "年 月 日 时 分"; string defaulttimestr = "yyyy年MM月dd日HH时mm分"; string pic = Server.MapPath("~/content/Images/no_1.png");//默认图片 string onetime = time, twotime = time, threetime = time, fourtime = time, fivetime = time, sixtime = time; if (applyaudit.Count > 0) { for (int i = 0; i < applyaudit.Count; i++) { var filepath = applyaudit[i].AuditSignImg == null ? "" : (Server.MapPath("~/") + applyaudit[i].AuditSignImg.ToString().Replace("../../", "").ToString()).Replace(@"\/", "/").ToString(); var stime = Convert.ToDateTime(applyaudit[i].AuditDate); if (i == 0) { //applyfirst = applyaudit[i].AuditUserName; if (System.IO.File.Exists(filepath)) { row["applyfirst"] = filepath; } else { row["applyfirst"] = pic; } onetime = stime.ToString(defaulttimestr); } else if (i == 1) { if (System.IO.File.Exists(filepath)) { row["applysecond"] = filepath; } else { row["applysecond"] = pic; } //applysecond = applyaudit[i].AuditUserName; twotime = stime.ToString(defaulttimestr); } else { if (System.IO.File.Exists(filepath)) { row["applythree"] = filepath; } else { row["applythree"] = pic; } //applythree = applyaudit[i].AuditUserName; threetime = stime.ToString(defaulttimestr); } } } if (accpaudit.Count > 0) { for (int i = 0; i < accpaudit.Count; i++) { var filepath = accpaudit[i].AuditSignImg == null ? "" : (Server.MapPath("~/") + accpaudit[i].AuditSignImg.ToString().Replace("../../", "").ToString()).Replace(@"\/", "/").ToString(); var stime = Convert.ToDateTime(accpaudit[i].AuditDate); if (i == 0) { if (System.IO.File.Exists(filepath)) { row["accpfirst"] = filepath; } else { row["accpfirst"] = pic; } //accpfirst = accpaudit[i].AuditUserName; fourtime = stime.ToString(defaulttimestr); } else if (i == 1) { if (System.IO.File.Exists(filepath)) { row["accpsecond"] = filepath; } else { row["accpsecond"] = pic; } //accpsecond = accpaudit[i].AuditUserName; fivetime = stime.ToString(defaulttimestr); } else { if (System.IO.File.Exists(filepath)) { row["accpthree"] = filepath; } else { row["accpthree"] = pic; } //accpthree = accpaudit[i].AuditUserName; sixtime = stime.ToString(defaulttimestr); } } } row["applytime"] = entity.APPLYTIME.Value.Year + "年" + entity.APPLYTIME.Value.Month + "月" + entity.APPLYTIME.Value.Day + "日"; row["applyno"] = entity.APPLYNO; row["workunit"] = entity.WORKUNIT; row["workfzr"] = entity.WORKFZR; row["workcontent"] = entity.WORKCONTENT; row["changename"] = entity.CHANGENAME + entity.CHANGETYPE; row["procedures"] = entity.PROCEDURES; row["acceptance"] = entity.ACCEPTANCE; row["onetime"] = onetime; row["twotime"] = twotime; row["threetime"] = threetime; row["fourtime"] = fourtime; row["fivetime"] = fivetime; row["sixtime"] = sixtime; dt.Rows.Add(row); doc.MailMerge.Execute(dt); //doc.MailMerge.Execute(new string[] { "applytime", "applyno", "workunit", "workfzr", "workcontent", "changename", "procedures", "applyfirst", "onetime", "applysecond", "twotime", "applythree", "threetime", "acceptance", "accpfirst", "fourtime", "accpsecond", "fivetime", "accpthree", "sixtime" } //, new string[] { applytime, applyno, workunit, workfzr, workcontent, changename, procedures, applyfirst, onetime, applysecond, twotime, applythree, threetime, acceptance, accpfirst, fourtime, accpsecond, fivetime, accpthree, sixtime }); string fileName = "安全设施变动(验收)审批单_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc"; doc.Save(resp, Server.UrlEncode(fileName), ContentDisposition.Attachment, Aspose.Words.Saving.SaveOptions.CreateSaveOptions(SaveFormat.Doc)); return(Success("导出成功!")); }