public void Output_Word_zdts() { try { int selectedYear = Convert.ToInt32(ddl_year.SelectedValue); Enterprise ent = Enterprise.FindById(id); string basePath = Server.MapPath("../../"); Document doc = new Document(basePath + "Template/合作大学情况表.doc"); //企业名称 Bookmark bookmark = doc.Range.Bookmarks["Name"]; bookmark.Text = ent.Name == null ? "" : ent.Name; //企业地址 bookmark = doc.Range.Bookmarks["Domicile"]; bookmark.Text = ent.Domicile == null ? "" : ent.Domicile; //法定代表人 bookmark = doc.Range.Bookmarks["Referee"]; bookmark.Text = ent.Referee == null ? "" : ent.Referee; //联系人 bookmark = doc.Range.Bookmarks["Contacts"]; bookmark.Text = ent.Contacts == null ? "" : ent.Contacts; //联系电话 bookmark = doc.Range.Bookmarks["PhoneNo"]; bookmark.Text = ent.PhoneNo == null ? "" : ent.PhoneNo; //邮箱地址 bookmark = doc.Range.Bookmarks["Email"]; bookmark.Text = ent.Email == null ? "" : ent.Email; //性质 bookmark = doc.Range.Bookmarks["Type"]; bookmark.Text = ent.Type == null ? "" : ent.Type; //台投资人 bookmark = doc.Range.Bookmarks["InvestorOfTW"]; bookmark.Text = ent.InvestorOfTW == null ? "" : ent.InvestorOfTW; //陆投资人 bookmark = doc.Range.Bookmarks["InvestorOfH"]; bookmark.Text = ent.InvestorOfH == null ? "" : ent.InvestorOfH; //经营范围 bookmark = doc.Range.Bookmarks["Scope"]; bookmark.Text = ent.Scope == null ? "" : ent.Scope; //主要业务及产品 bookmark = doc.Range.Bookmarks["Product"]; bookmark.Text = ent.Product == null ? "" : ent.Product; //检查记录 DataTable dt_fa = Inspect.Find(CK.K["Enterprise_Id"] == id && CK.K["IsDelete"] == false && CK.K["Time"] >= (new DateTime(selectedYear, 1, 1)) && CK.K["Time"] <= (new DateTime(selectedYear, 12, 31))).ToDataTable(); if (dt_fa.Rows.Count > 0) { int fa_count = dt_fa.Rows.Count <= 5 ? dt_fa.Rows.Count : 5; for (int i = 0; i < fa_count; i++) { //时间 bookmark = doc.Range.Bookmarks["In_" + i + "_Time"]; bookmark.Text = dt_fa.Rows[i]["Time"].ToString().IsNullOrEmpty() ? "" : Convert.ToDateTime(dt_fa.Rows[i]["Time"].ToString()).ToString("yyyy.MM.dd"); //检查单位 bookmark = doc.Range.Bookmarks["In_" + i + "_Unit"]; bookmark.Text = dt_fa.Rows[i]["Unit"].ToString(); //检查结果 bookmark = doc.Range.Bookmarks["In_" + i + "_Res"]; bookmark.Text = dt_fa.Rows[i]["Result"].ToString(); } } //协调记录 DataTable dt_Exp = Coordinate.Find(CK.K["Enterprise_Id"] == id && CK.K["IsDelete"] == false && CK.K["Time"] >= (new DateTime(selectedYear, 1, 1)) && CK.K["Time"] <= (new DateTime(selectedYear, 12, 31))).ToDataTable(); if (dt_Exp.Rows.Count > 0) { int exp_count = dt_Exp.Rows.Count <= 5 ? dt_Exp.Rows.Count : 5; for (int i = 0; i < exp_count; i++) { //时间 bookmark = doc.Range.Bookmarks["Pr_" + i + "_Time"]; bookmark.Text = dt_Exp.Rows[i]["Time"].ToString().IsNullOrEmpty() ? "" : Convert.ToDateTime(dt_Exp.Rows[i]["Time"].ToString()).ToString("yyyy.MM.dd"); //问题及协调情况 bookmark = doc.Range.Bookmarks["Pr_" + i + "_Pr"]; bookmark.Text = dt_Exp.Rows[i]["Problem"].ToString(); } } string fileNameWithOutExtention = Guid.NewGuid().ToString(); doc.Save(basePath + "upload/word_tzqy/" + fileNameWithOutExtention + ".pdf", SaveFormat.Pdf); FileStream fs = new FileStream(basePath + "upload/word_tzqy/" + 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("台资企业情况表-" + ddl_year.SelectedItem.Text + "-" + ent.Name + ".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) { return; } }