Aspose.Words 开发时遇到的问题
生活随笔
收集整理的這篇文章主要介紹了
Aspose.Words 开发时遇到的问题
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
問題一
Document?doc.Save(Response, "學(xué)員報名表.pdf", ContentDisposition.Inline, null); 執(zhí)行后沒有效果,因為異步的時候需要加,如果不是異步,即沒有使用UpdatePanel,那么就不要加此方法Triggers。
解決
<asp:UpdatePanel ID="UpdatePanel1" runat="server"><Triggers><asp:PostBackTrigger ControlID="btnExportAndPrint" /></Triggers><ContentTemplate><asp:Button runat="server" ID="btnExportAndPrint" class="btn btn-primary" Text="打印報名表" OnClick="btnExportAndPrint_Click"/></ContentTemplate> </asp:UpdatePanel>?
我的程序
protected void btnExportAndPrint_Click(object sender, EventArgs e){string studentNo = txtStudentCode.Text;if (!string.IsNullOrWhiteSpace(studentNo)){OLD_StudentUser student = OLD_StudentUserDAL.GetByStudentNo(studentNo);string templateFile = Server.MapPath("../Template/Word/學(xué)員報名表.doc");//string photoPath = Server.MapPath("../IDCardPhoto/142201199201264557.Bmp"); //測試方法string photoPath = Server.MapPath(student.ZP); Document doc = new Document(templateFile);doc = ExportAndPrintHelper.ExportAndPrintRegister(doc,student,studentNo,photoPath);if (doc != null){doc.Save(Response, "學(xué)員報名表.pdf", ContentDisposition.Inline, null);}}else{Response.Write("<script>alert('學(xué)員學(xué)號為空!')</script>");}} public class ExportAndPrintHelper{/// <summary>/// 導(dǎo)出和打印學(xué)員報名表/// </summary>/// <param name="doc"></param>/// <param name="student"></param>/// <param name="StudentNo"></param>/// <param name="photoPath"></param>/// <returns></returns>public static Document ExportAndPrintRegister(Document doc, OLD_StudentUser student, string studentNo, string photoPath){DocumentBuilder builder = new DocumentBuilder(doc);if (!string.IsNullOrWhiteSpace(studentNo)){#region 基礎(chǔ)信息if (doc.Range.Bookmarks["Code"] != null){doc.Range.Bookmarks["Code"].Text = DateTime.Now.ToShortDateString();}if (doc.Range.Bookmarks["Name"] != null){doc.Range.Bookmarks["Name"].Text = student.Name;}if (doc.Range.Bookmarks["Sex"] != null){doc.Range.Bookmarks["Sex"].Text = student.Sex;}if (doc.Range.Bookmarks["Born"] != null){doc.Range.Bookmarks["Born"].Text = student.DirthDate.ToString("yyyy.MM.dd");}if (doc.Range.Bookmarks["StudentNo"] != null){doc.Range.Bookmarks["StudentNo"].Text = student.StudentsNo;}if (doc.Range.Bookmarks["Politics"] != null){doc.Range.Bookmarks["Politics"].Text = student.Politics;}if (doc.Range.Bookmarks["IDCardNo"] != null){doc.Range.Bookmarks["IDCardNo"].Text = student.SID;}if (doc.Range.Bookmarks["EducationLevel"] != null){doc.Range.Bookmarks["EducationLevel"].Text = student.EducationLevel;}if (doc.Range.Bookmarks["Units"] != null){doc.Range.Bookmarks["Units"].Text = student.Units;}if (doc.Range.Bookmarks["Job"] != null){doc.Range.Bookmarks["Job"].Text = student.Job;}if (doc.Range.Bookmarks["Phone"] != null){doc.Range.Bookmarks["Phone"].Text = student.Phone;}if (doc.Range.Bookmarks["RelativesPhone"] != null){doc.Range.Bookmarks["RelativesPhone"].Text = student.RelativesPhone;}if (doc.Range.Bookmarks["ResidenceAdd"] != null){doc.Range.Bookmarks["ResidenceAdd"].Text = student.ResidenceAdd;}if (doc.Range.Bookmarks["Address"] != null){doc.Range.Bookmarks["Address"].Text = student.Address;}if (doc.Range.Bookmarks["NowTime"] != null){doc.Range.Bookmarks["NowTime"].Text = DateTime.Now.ToShortDateString();}if (doc.Range.Bookmarks["Photo"] != null){builder.MoveToBookmark("Photo");var img = builder.InsertImage(photoPath);img.Width = 76;img.Height = 94;}#endregion#region 所報課程List<OLD_CourseRegistration> courses = OLD_CourseRegistrationDAL.GetByStudentNo(studentNo);for (int i = 9; i < courses.Count + 9; i++){OLD_Class classes = OLD_ClassDAL.GetByClassName(courses[i - 9].ClassName);builder.MoveToCell(0, i, 2, 0);builder.Write(courses[i - 9].ClassName.ToString());builder.MoveToCell(0, i, 3, 0);builder.Write(classes.TeacherName.ToString());builder.MoveToCell(0, i, 4, 0);builder.Write(classes.SKdate.ToString());builder.MoveToCell(0, i, 5, 0);builder.Write(classes.ClassAdd.ToString());builder.MoveToCell(0, i, 6, 0);builder.Write(classes.FY.ToString());}for (int cancel = 22; cancel >= courses.Count + 9; cancel--){builder.DeleteRow(0, cancel);}#endregionreturn doc;}else{return null;}}} View Code?word圖片
執(zhí)行保存之后的圖片
轉(zhuǎn)載于:https://www.cnblogs.com/BrokenIce/p/5988347.html
總結(jié)
以上是生活随笔為你收集整理的Aspose.Words 开发时遇到的问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 方差与样本方差、协方差与样本协方差
- 下一篇: abap 一些小知识点的总结