博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Aspose.Words 开发时遇到的问题
阅读量:5330 次
发布时间:2019-06-14

本文共 5778 字,大约阅读时间需要 19 分钟。

问题一

Document doc.Save(Response, "学员报名表.pdf", ContentDisposition.Inline, null); 执行后没有效果,因为异步的时候需要加,如果不是异步,即没有使用UpdatePanel,那么就不要加此方法Triggers。

解决

 

我的程序

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/学员报名表.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, "学员报名表.pdf", ContentDisposition.Inline, null);                }            }            else            {                Response.Write("");            }        }
public class ExportAndPrintHelper    {        ///         ///  导出和打印学员报名表        ///         ///         ///         ///         ///         /// 
public static Document ExportAndPrintRegister(Document doc, OLD_StudentUser student, string studentNo, string photoPath) { DocumentBuilder builder = new DocumentBuilder(doc); if (!string.IsNullOrWhiteSpace(studentNo)) { #region 基础信息 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
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); } #endregion return doc; } else { return null; } } }
View Code

 word图片

执行保存之后的图片

转载于:https://www.cnblogs.com/BrokenIce/p/5988347.html

你可能感兴趣的文章
省市县,循环组装,整合大数组
查看>>
stm32中字节对齐问题(__align(n),__packed用法)
查看>>
like tp
查看>>
posix多线程有感--线程高级编程(线程属性函数总结)(代码)
查看>>
spring-使用MyEcilpse创建demo
查看>>
DCDC(4.5V to 23V -3.3V)
查看>>
kettle导数到user_用于left join_20160928
查看>>
activity 保存数据
查看>>
typescript深copy和浅copy
查看>>
linux下的静态库与动态库详解
查看>>
hbuilder调底层运用,多张图片上传
查看>>
较快的maven的settings.xml文件
查看>>
Git之初体验 持续更新
查看>>
随手练——HDU 5015 矩阵快速幂
查看>>
Maven之setting.xml配置文件详解
查看>>
SDK目录结构
查看>>
malloc() & free()
查看>>
HDU 2063 过山车
查看>>
高精度1--加法
查看>>
String比较
查看>>