前面几步跟前面我所讲的水晶报表预览操作一样,只是页面PrintRpt.aspx有所改变,该页面不需要任何页面设计和控件
只是执行代码有所增加
View Code
1 protected void Page_Load(object sender, EventArgs e)
2 {
3 //取得前一页面传来的两个查询条件
4 string setAct_YM = Request["setAct_YM"].ToString();
5 string stockName = Request["stockName"].ToString();
6 //根据条件获得相应信息
7 DataTable dt = new DataTable();
8 dt = acc.getPrintDate(setAct_YM, stockName);
9
10 ReportDocument rptDoc = new ReportDocument();
11 rptDoc.Load(this.Server.MapPath("asm_Rpt.rpt"));
12 rptDoc.SetDataSource(dt);
13 CrystalDecisions.Shared.DiskFileDestinationOptions objFile = new DiskFileDestinationOptions();
14 objFile.DiskFileName = this.Server.MapPath(@"..\..\File\nmail\do\PDF\asm_1.pdf");//在该路径下建一个PDF文件,将报表里的内容映射到了PDF文件上
15 rptDoc.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
16 rptDoc.ExportOptions.DestinationOptions = objFile;
17 rptDoc.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
18 rptDoc.Export();
19
20 Response.Redirect("http://www.cnblogs.com/File/nmail/do/PDF/asm_1.pdf");
21 //弹出PDF,并已下载
22 }