protected void gv_Result_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[1].Text = CommunicationType.FindOne(CK.K["CommunicationTypeId"] == e.Row.Cells[1].Text).CommunicationTypeText; } }
public void Output_Word_zdts() { try { if (id == 0) { //ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "alert('数据加载错误,请重新再试!')", true); Page.ClientScript.RegisterStartupScript(this.GetType(), "alter", "alert('数据加载错误,请重新再试!')", true); return; } GroupCommunicationWork gcw = GroupCommunicationWork.FindById(id); string basePath = Server.MapPath("../../"); object missing = Type.Missing; object filePath = basePath + "Template/团组交流工作情况表.doc"; var docApp = new Microsoft.Office.Interop.Word.Application(); docApp.Visible = false; //打开Word文件 var doc = docApp.Documents.Open(ref filePath, false, false, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); object oFalse = false; object oTrue = true; object oMissing = System.Reflection.Missing.Value; //交流形式 doc.Bookmarks["CommunicationTypeText"].Range.Text = CommunicationType.FindOne(CK.K["CommunicationTypeId"] == gcw.CommunicationTypeId).CommunicationTypeText; //组团地区 doc.Bookmarks["GroupArea"].Range.Text = gcw.GroupArea == null ? "" : gcw.GroupArea; //交流团组名称 doc.Bookmarks["GroupName"].Range.Text = gcw.GroupName == null ? "" : gcw.GroupName; //交流团团长 doc.Bookmarks["GroupMonitor"].Range.Text = gcw.GroupMonitor == null ? "" : gcw.GroupMonitor; //团组成员名称 if (gcw.GroupMembers != null) { doc.Bookmarks["GroupMembers"].Range.InsertFile(GenerateHtml(gcw.GroupMembers), ref oMissing, ref oFalse, ref oTrue, ref oFalse); } //交流形成 if (gcw.CommunicationGenerate != null) { doc.Bookmarks["CommunicationGenerate"].Range.InsertFile(GenerateHtml(gcw.CommunicationGenerate), ref oMissing, ref oFalse, ref oTrue, ref oFalse); } //交流工作总结 if (gcw.CommunicationSummarize != null) { doc.Bookmarks["CommunicationSummarize"].Range.InsertFile(GenerateHtml(gcw.CommunicationSummarize), ref oMissing, ref oFalse, ref oTrue, ref oFalse); } //专项工作报告 if (gcw.CommunicationReport != null) { doc.Bookmarks["CommunicationReport"].Range.InsertFile(GenerateHtml(gcw.CommunicationReport), ref oMissing, ref oFalse, ref oTrue, ref oFalse); } //交流照片 if (gcw.CommunicationPhotos != null) { doc.Bookmarks["CommunicationPhotos"].Range.InsertFile(GenerateHtml(gcw.CommunicationPhotos), ref oMissing, ref oFalse, ref oTrue, ref oFalse); } string fileNameWithOutExtention = Guid.NewGuid().ToString(); doc.SaveAs(basePath + "upload/word_tzjlgz/" + fileNameWithOutExtention + ".pdf", Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF); object f = false; doc.Close(ref f, ref missing, ref missing); FileStream fs = new FileStream(basePath + "upload/word_tzjlgz/" + fileNameWithOutExtention + ".pdf", FileMode.Open); byte[] file = new byte[fs.Length]; fs.Read(file, 0, file.Length); fs.Close(); Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("团组交流工作情况表-" + gcw.GroupName + ".pdf", System.Text.Encoding.UTF8)); Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); Response.ContentType = "application/octet-stream"; Response.BinaryWrite(file); Response.End(); } catch (Exception ex) { Page.ClientScript.RegisterStartupScript(this.GetType(), "alter", "alert('数据加载错误,请重新再试!')", true); text(ex.ToString()); //ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "alert('数据加载失败,请重新再试!')", true); return; } }