1:新建報表所需的數據源DataSet.cs
复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
namespace ********
{
public class DataSet
{
public DataTable CreatDataSet()
{
DataTable dt = new DataTable();
dt.Columns.Add("A");
dt.Columns.Add("B");
dt.Columns.Add("C");
return dt;
}
}
}
指定所需要綁定的Table的列,返回dataTable 類,CreatDataSet方法名稱隨便起,也可以在一個類裏面定義多個方法(不同數據源)
2:設計報表
報表設計這裡就不涉及了
3:把第一步新建的數據源加到報表裏面綁定
注意:這裡需要先引用 Interop.VBA.dll 才可以把新建的CS文件作為數據源導入
把數據源導入后綁定即可
4:直接把報表導出為PDF,Excel等格式
复制代码 代码如下:
ReportViewer viewer = new ReportViewer();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportEmbeddedResource = "***.Page.Report.Report1.rdlc";
ReportDataSource rds_1 = new ReportDataSource("DataSet1", dtReport);//DataSet1為報表裏面的數據源名稱
viewer.LocalReport.DataSources.Add(rds_1);
ReportParameter rp1 = new ReportParameter("參數1","參數1的值" );//給參數賦值
ReportParameter rp2 = new ReportParameter("參數2","參數2的值" );
viewer.LocalReport.SetParameters(new ReportParameter[] {rp1, rp2 });
Warning[] warnings;
string[] streamIds;
string mimeType = string.Empty;
string encoding = string.Empty;
string extension = string.Empty;
byte[] bytes = viewer.LocalReport.Render("Excel", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
//Excel ,PDF ,Word 等格式
// Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=1_" + DateTime.Now.ToString("yyyyMMddhhssmm") + "" + "." + extension);
Response.BinaryWrite(bytes); // create the file
Response.Flush(); // send it to the client to download
5:在頁面引用報表(rpResult為報表控件)
复制代码 代码如下:
DataTable dt = new DataTable();//自己拼出數據源就可以
ReportDataSource repDataSource = new ReportDataSource("DataSet1", dt);
//*設置報表參數,并顯示
this.rpResut.LocalReport.ReportEmbeddedResource = "***.Page.Report.Report1.rdlc"";
this.rpResut.LocalReport.DataSources.Clear();
this.rpResut.LocalReport.DataSources.Add(repDataSource);
ReportParameter rp1 = new ReportParameter("參數1","參數1的值" );//給參數賦值
ReportParameter rp2 = new ReportParameter("參數2","參數2的值" );
this.rpResut.LocalReport.SetParameters(new ReportParameter[] {rp1, rp2 });
this.rpResut.DataBind();
this.rpResut.LocalReport.Refresh();
至此,報表的產出和顯示都OK了,如果需要更深入的了解,請查看其它文章
Asp.net,自带报表
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- 纪钧瀚《钢琴阅读时光 雨中书店聆听轻音乐》[FLAC/分轨][399.62MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[320K/MP3][87.4MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[FLAC/分轨][184.94MB]
- 陈慧娴.2018-Priscilla-Ism演唱会3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郑秀文.1999-我应该得到(国)【华纳】【WAV+CUE】
- 陈家慧.2011-钢琴酒吧2CD【龙吟唱片】【WAV+CUE】
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[320K/MP3][45.01MB]
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[FLAC/分轨][109.13MB]
- 赞多《序章》[320K/MP3][45.54MB]
- 许巍.2004-每一刻都是崭新的【步升大风】【WAV+CUE】
- 群星.2024-四方馆影视原声带【韶愔音乐】【FLAC分轨】
- 陈雷.1997-安锁咧【金圆唱片】【WAV+CUE】
- 关淑怡.2013-MY.FAVORITE.SK.3CD【环球】【WAV+CUE】
- Sweety.2006-花言乔语【丰华】【WAV+CUE】
- 李恕权.2003-回·20年全精选2CD【SONY】【WAV+CUE】