问题一

Document doc.Save(Response, "学员报名表.pdf", ContentDisposition.Inline, null); 执行后没有效果,因为异步的时候需要加,如果不是异步,即没有使用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/学员报名表.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("<script>alert('学员学号为空!')</script>");
}
}
public class ExportAndPrintHelper
{
/// <summary>
/// 导出和打印学员报名表
/// </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 基础信息
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 = ;
img.Height = ;
}
#endregion #region 所报课程
List<OLD_CourseRegistration> courses = OLD_CourseRegistrationDAL.GetByStudentNo(studentNo);
for (int i = ; i < courses.Count + ; i++)
{
OLD_Class classes = OLD_ClassDAL.GetByClassName(courses[i - ].ClassName);
builder.MoveToCell(, i, , );
builder.Write(courses[i - ].ClassName.ToString());
builder.MoveToCell(, i, , );
builder.Write(classes.TeacherName.ToString());
builder.MoveToCell(, i, , );
builder.Write(classes.SKdate.ToString());
builder.MoveToCell(, i, , );
builder.Write(classes.ClassAdd.ToString());
builder.MoveToCell(, i, , );
builder.Write(classes.FY.ToString());
} for (int cancel = ; cancel >= courses.Count + ; cancel--)
{
builder.DeleteRow(, cancel);
}
#endregion return doc;
}
else
{
return null;
}
}
}

word图片

执行保存之后的图片

Aspose.Words 开发时遇到的问题的更多相关文章

  1. 【夯实PHP基础】php开发时遇到白页的调试方法

    本文地址   分享提纲: 1. 设置报错报错级别,显示报错 2. 白页的可能原因     1.[设置报错报错级别,显示报错] php开发时,访问地址也对,但就是不出来页面,显示的是 白的页面,所以就可 ...

  2. Golang Web开发时前端出现谜之空白换行的坑

    在使用Golang做Web开发时,有时候渲染出来的模板在前台显示时会出现一些奇怪的空白换行,具体特征就是查看css样式表并没有相关定义的空白部分. 分析: 查看出现问题页面的网页源代码,复制空白换行部 ...

  3. grunt-connect-proxy解决开发时跨域问题

    最近的项目中前后端是完全分离开发的,前端用grunt管理项目.这样就会导致一个问题:开发时前端调用后台的接口时因为不在一个服务器,所以会出现跨域问题.但是也不能用JSONP或CROS方式实现真正的跨域 ...

  4. J2EE开发时的包命名规则

    http://www.blogjava.net/paulwong/archive/2012/04/15/374675.html 转一个J2EE开发时的包命名规则,养成良好的开发习惯 代码编写规范目的: ...

  5. Brophp框架开发时连接数据库读取UTF8乱码的解决(转)

    Brophp框架开发时连接数据库读取UTF8乱码的解决办法 (2012-09-15 10:41:22) 转载▼ 标签: 杂谈 it php 分类: 建站技术 Brophp框架开发时连接数据库读取UTF ...

  6. iOS开发时,在Xcode中添加多个Targets进行版本控制

    在iOS开发中,很可能有以下场景:需要开发多个版本,或因需区分收费版,免费版,或因为网络环境需要区分测试版,发布版,或因渠道不同需要区分企业版,AppStore版等等.解决办法无非就是CheckOut ...

  7. WCF开发时如何选择正确的实例模式(InstanceMode)?

    WCF开发时如何选择正确的实例模式(InstanceMode)?   在使用WCF实例模型时,你是否思考过这几个的问题: ”WCF中的实例模式如何正确应用”? ”使用WCF中的实例模式有何原则可以遵循 ...

  8. 微信jsSDK公众号开发时网页提示 invalid signature错误的解决方法

    微信公众号开发jsSDK,链接地址不能加?参数,可以通过#传递参数. 不然.页面wx.ready()时就会报错,用 wx.error(function (res) { alert("接口验证 ...

  9. 程序员网站开发时应该注意的SEO问题

    一.链接的统一性 搜索引擎排名最主要的因素就是网站内容和链接,假如网站内部链接不一致,在很大程度上直接影响着网站在搜索引擎中的排名.例如彩票专营店导航栏中的“首页”链接,程序员在开发时可能会有以下几种 ...

随机推荐

  1. Java JDBC批处理插入数据操作

    在此笔记里,我们将看到我们如何可以使用像Statement和PreparedStatement JDBC API来批量在任何数据库中插入数据.此外,我们将努力探索一些场景,如在内存不足时正常运行,以及 ...

  2. JAVA NIO异步通信框架MINA选型和使用的几个细节(概述入门,UDP, 心跳)

    Apache MINA 2 是一个开发高性能和高可伸缩性网络应用程序的网络应用框架.它提供了一个抽象的事件驱动的异步 API,可以使用 TCP/IP.UDP/IP.串口和虚拟机内部的管道等传输方式.A ...

  3. MS14-025引起的问题 - 1

    windows2008有一个叫组策略首选项(Group Policy Preference)的新特性.这个特性可以方便管理员在整个域内部署策略.本文会详细介绍这个组策略首选项的一些缺陷.尤其是当下发的 ...

  4. 【iBoard电子学堂开发板例程】【12个 stm32 例程发布】

    _____________________________________ 深入交流QQ群: A: 204255896(1000人超级群,可加入) B: 165201798(500人超级群,满员) C ...

  5. jsp七大动作指令

    jsp 七大动作指令 1) jsp:include 指令 用于在请求处理阶段包含来自一个Servlet或jsp页面的响应.和编译指令中的include不同,include只能用于包含静态页面,而jsp ...

  6. DS实验题 sights

    算法与数据结构实验题 6.3 sights ★实验任务 美丽的小风姑娘打算去旅游散心,她走进了一座山,发现这座山有 n 个景点, 由于山路难修,所以施工队只修了最少条的路,来保证 n 个景点联通,娇弱 ...

  7. P4factory 运行结果展示 basic_routing 以及 ./run_all_tests 的运行结果

    p4factory子目录下的run_all_tests 安装好p4factory之后,打算跑一下样例来测试是否正确. 但是,跑了targets目录内的basic_routing,make又报错了,但之 ...

  8. Swing 刷新容器

    JPanel pchks = new JPanel();// 容器刷新(重新layout所有空间)pchks.validate();// 容器重绘(当容器内的东西由多变少时,防止多出来的部分没有清楚) ...

  9. 制作支持UEFI PC的Server2008 R2系统安装U盘

    下载R2系统 ISO ed2k://|file|cn_windows_server_2008_r2_standard_enterprise_datacenter_and_web_with_sp1_x6 ...

  10. the basic index concept

    Computer Science An Overview _J. Glenn Brookshear _11th Edition Over the years numerous variations o ...