问题一

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. jquery and jquery validation 常见问题解决

    Cannot read property 'settings' of undefined jquery validation 这个问题常常发生在动态添加rule的时候. 解决方法 // 在timeou ...

  2. css 框架——base.css,作用是重设浏览器默认样式和提供通用原子类。自己留存

    今天发下我自己的 css 框架——base.css,作用是重设浏览器默认样式和提供通用原子类. @charset "utf-8"; /*! * @名称:base.css * @功能 ...

  3. python的几个常用内置函数

    dir()查看属性(函数和数据对象) help()查看具体的帮助文档 id() 用来查看数据对象的地址 split 分隔(str ---> list): >>> s=" ...

  4. Linux环境下实现哲学家就餐问题

    #include <stdio.h> #include <stdlib.h> #include <memory.h> #include <pthread.h& ...

  5. SQL - 分页存储过程

    http://www.jb51.net/article/71193.htm http://www.webdiyer.com/utils/spgenerator/ create PROCEDURE [d ...

  6. 根据CSV找出USBGroup中计算机对应的用户

    <USB.CSV> Hostname,Username CNHZPD-TEST1,User1 CNHZLN-01234567,User2   $group = "CN=Enabl ...

  7. JavaScript系列:函数调用方式

    有关JS的问题,持续更新.. 一,函数调用的4种方式 1,函数调用模式 //下面这种模式叫 “函数调用模式”:窗后window来调用 //函数调用四种方式的基础 //这tm不就是作用域this的问题吗 ...

  8. 使用VirtualEnvWrapper隔离python项目的库依赖

    是什么 VirtualEnv用于在一台机器上创建多个独立的python运行环境,VirtualEnvWrapper为前者提供了一些便利的命令行上的封装. 为什么要用 - 隔离项目之间的第三方包依赖,如 ...

  9. PHP实现远程下载文件到本地

    PHP实现远程下载文件到本地 投稿:hebedich 字体:[增加 减小] 类型:转载   经常写采集器发布接口需要使用到远程附件的功能,所以自己写了一个PHP远程下载文件到本地的函数,一般情况下已经 ...

  10. C++类型转化分析(1)

    仔细想想地位卑贱的类型转换功能(cast),其在程序设计中的地位就象goto语句一样令人鄙视.但是它还不是无法令人忍受,因为当在某些紧要的关头,类型转换还是必需的,这时它是一个必需品. 不过C风格的类 ...