C#(99):微软报表编程

一、加载报表文件

1、加载本地RDlC文件:

LocalReport localReport =this.reportViewer1.LocalReport ; //或new LocalReport () 创建我获取LocalReport 对象。
LocalReport ReportEmbeddResource=”Salary.Report.test.rdlc”;  //报表路经(嵌入式资源到EXE)
//或 LocalReport.ReportPath=”test.rdlc” ;

2、加载服务器报表

reportViewer1.ProcessMode=frerertones.Remote;
reportViewer1.ServerReport.ReportServerUrl=new Uri(”http://localhost.reportServer”);
reportViewer1.ServerReport.ReportPath=new Uri(”/Domo/test”);


二、报表数据源

string sourerName= localReport .GetDataSourceNames()[0]:
ReportDataSource reportdataSource =new ReportDataSource (sourerName, ds.Tables[0]);
localReport .DataSources.Clear();
localReport .DataSources.Add (reportdataSource );

sourerName为数据集的名称,eg、DataSet1。也可以为Datatable,其中的列名与报表中的字段需一致。也可以为IEnumeable类型,元素的公共属性的名字应与报表中定义的数据源字段名匹配。

eg:生成解决方可见。

List<a> list=new List<a>();
list.Add(new a(“1",“2”));
list.Add(new a(“3",“4”));

三、报表参数

string paraName =localReport.GetParameters()[0].Name;
ReportParameter p=new ReportParameter(paraName,”a”);
localReport.SetParameters (new ReportParameter[]{p});

四、填充教据,刷新展示数的数据

da.Fill(ds.Tables[0]);
localReport.Refresh();
the.reportViewer1.RefreshReports();

五、导出到DPF

sring devInof =”<DeviceInfo><Table>…”;
string miniType,encoding,filenameExt;
stirng[] streams;Waring[] warning;
byte[] bytes=localReport.Render(“PDF”,devinfo,out ..);
File.WriteAllBytes(“file.pdf”,bytes);

或下载

Response.clear();
Response.ContentType=mimType;
Response.AddHeader(“Content-Dispoiton”,”attachment;filename=aa.pdf”);
Response.BinaryWirte(data);

六、打印

this.reportViewer1.PrintDialog();
RsClientRrint控件

原文地址:https://www.cnblogs.com/springsnow/p/9433973.html