private void Bind_basic() { DataTable dt_SpecialWorkType = SpecialWorkType.Find(CK.K["IsDelete"] == false).ToDataTable(); ddl_SpecialWorkType.DataSource = dt_SpecialWorkType; ddl_SpecialWorkType.DataValueField = "SpecialWorkTypeId"; ddl_SpecialWorkType.DataTextField = "SpecialWorkTypeText"; ddl_SpecialWorkType.DataBind(); ddl_SpecialWorkType.Items.Insert(0, new ListItem("请选择", "0")); //导出文件年份 int earliestYear = 2000; int nowYear = DateTime.Now.Year; DataTable dt_Year = new DataTable(); dt_Year.Columns.Add("Year"); dt_Year.Columns.Add("YearText"); for (int i = earliestYear; i <= nowYear; i++) { DataRow dr_Year = dt_Year.NewRow(); dr_Year["Year"] = i; dr_Year["YearText"] = i + "年"; dt_Year.Rows.Add(dr_Year); } ddl_year.DataSource = dt_Year; ddl_year.DataTextField = "YearText"; ddl_year.DataValueField = "Year"; ddl_year.DataBind(); ddl_year.SelectedValue = nowYear.ToString(); }
public void Output_Word_zdts() { try { if (communicationId == 0) { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "alert('数据加载错误,请重新再试!')", true); return; } int selectedYear = Convert.ToInt32(ddl_year.SelectedValue); SpecialWork com = SpecialWork.FindById(communicationId); string basePath = Server.MapPath("../../"); Document doc = new Document(basePath + "Template/专项工作情况表.doc"); //对口交流地区 Bookmark bookmark = doc.Range.Bookmarks["Exchange"]; bookmark.Text = com.Exchange == null ? "" : com.Exchange; //交流对象类别 bookmark = doc.Range.Bookmarks["Type"]; bookmark.Text = com.Type == null ? "" : com.Type; //姓名 bookmark = doc.Range.Bookmarks["Name"]; bookmark.Text = com.Name == null ? "" : com.Name; //性别 bookmark = doc.Range.Bookmarks["Sex"]; bookmark.Text = com.Sex == null ? "" : (bool)com.Sex ? "女" : "男"; //出生年月 bookmark = doc.Range.Bookmarks["Birthday"]; bookmark.Text = com.Birthday == null ? "" : ((DateTime)com.Birthday).ToString("yyyy.MM.dd"); //工作单位 bookmark = doc.Range.Bookmarks["Company"]; bookmark.Text = com.Company == null ? "" : com.Company; //联系电话 bookmark = doc.Range.Bookmarks["PhoneNo"]; bookmark.Text = com.PhoneNo == null ? "" : com.PhoneNo; //类别 bookmark = doc.Range.Bookmarks["SpecialWorkTypeText"]; bookmark.Text = SpecialWorkType.FindOne(CK.K["SpecialWorkTypeId"] == com.SpecialWorkTypeId && CK.K["IsDelete"] == false).SpecialWorkTypeText; //任期开始 bookmark = doc.Range.Bookmarks["WorkStartDate"]; bookmark.Text = com.WorkStartDate == null ? "" : ((DateTime)com.WorkStartDate).ToString("yyyy.MM.dd"); //任期结束 bookmark = doc.Range.Bookmarks["WorkEndDate"]; bookmark.Text = com.WorkEndDate == null ? "" : ((DateTime)com.WorkEndDate).ToString("yyyy.MM.dd"); //联系地址 bookmark = doc.Range.Bookmarks["Address"]; bookmark.Text = com.Address == null ? "" : com.Address; //得票数 bookmark = doc.Range.Bookmarks["Ballot"]; bookmark.Text = com.Ballot == null ? "" : com.Ballot.ToString(); //是否连任 bookmark = doc.Range.Bookmarks["IsReelect"]; bookmark.Text = com.IsReelect == null ? "" : (bool)com.IsReelect ? "是" : "否"; //社会关系及人脉 bookmark = doc.Range.Bookmarks["Background"]; bookmark.Text = com.Background == null ? "" : com.Background; //工作单位情况 bookmark = doc.Range.Bookmarks["Situation"]; bookmark.Text = com.Situation == null ? "" : com.Situation; //交流情况表 DataTable dt_fa = SituationToSpecialWork.Find(CK.K["Communication_Id"] == communicationId && 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["Si_" + 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["Si_" + i + "_Lo"]; bookmark.Text = dt_fa.Rows[i]["Location"].ToString(); //交流情况 bookmark = doc.Range.Bookmarks["Si_" + i + "_Si"]; bookmark.Text = dt_fa.Rows[i]["SituationName"].ToString(); } } ////插入图片 if (!com.PhotoName.IsNullOrEmpty()) { DocumentBuilder builder = new DocumentBuilder(doc); builder.MoveToBookmark("Photo"); var img = builder.InsertImage(basePath + "upload/photos/" + com.PhotoName); img.Width = 115; img.Height = 150; img.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center; } string fileNameWithOutExtention = Guid.NewGuid().ToString(); doc.Save(basePath + "upload/word_zxgz/" + fileNameWithOutExtention + ".pdf", SaveFormat.Pdf); FileStream fs = new FileStream(basePath + "upload/word_zxgz/" + 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 + "-" + com.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) { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "alert('数据加载失败,请重新再试!')", true); return; } }