FastReport 版本分为VCL(Delphi版)和.Net版(c#版),两者模板创建都差不多,其中Vcl版的格式为fr2和fr3而.Net 版为frx,这里主要介绍一下.Net版本的使用
打印
命名空间引用:(在c#中首先需要导入动态库,然后引用对应的命名空间)
using FastReport;
- 集合形式数据集的打印
string path=AppDomain.CurrentDomain.BaseDirectory+"Reports\\rp1.frx";
Report rp=new Report();//实例化一个报表对象
re.Load(path); //加载报表模板
rp.RegisterData(list,"User");//注册一个集合数据,别名为User,这个别名为在报表模板中使用而定的
DataBand band=rp.FindObject("Data1") as DataBand; //获取报表模板中的数据对象(即报表模板中的DataBand 用于显示数据的区域)
rp.GetDataSource("User").Enabled=true; //设置启用数据集
band.DataSource=rp.GetDataSource("User");//位报表模板数据对象指定数据集
if(rp.Prepare()){
rp.Show();
}
- 数据集合数据打印
string path=AppDomain.CurrentDomain.BaseDirectory+"Reports\\rp1.frx";
Report rp=new Report(); //实例化报表对象
rp.Load(path); //加载报表模板
rp.RegisterData(ds,"Result",true); //这里需要给第三个参数设置为true,启用数据集中的所有的表,这个参数如果设置为false,会导致报表中只显示1行数据
DataBand band=rp.FindObject("Data1") as DataBand;
band.DataSource=rp.GetDataSource("Result");
if(rp.Prepare()){
rp.Show();
}