FastReport.Net v2016.6 FastScript安装 安装 VCL mvc FastReport.Net 报表 FastReport.Net v2016.2 TeeChart,图表开发 FastReport FMX 2.3 FastReport.Net v2016.1 FastReport.Net更新 FastCube VCL v2.5 FastReport VCL FastReport Online Designer教程 FastReport Online Designer组件 FastReport在线报表设计器:组件简介 FastReport在线报表设计器:界面结构简介 FastReport在线报表设计器:工作原理 FastReport Online Designer简介 FastReport Online Designer促销 FastReport Online Designer FastReport.Net授权促销 数据库查询构建 使用技巧 fastreport,报表 脚本引擎 FastScript FastScript, 脚本引擎 OLAP控件
作者:zhuhm 来源:FastReport中文网 浏览:Loading... 日期:2012-07-19
本文主要介绍如何使用fastreport通过代码方式创建报表。我们将创建下列报表:
Report report = new Report();
// register the "Products" table
report.RegisterData(dataSet1.Tables["Products"], "Products");
// enable it to use in a report
report.GetDataSource("Products").Enabled = true;
// create A4 page with all margins set to 1cm
ReportPage page1 = new ReportPage();
page1.Name = "Page1";
report.Pages.Add(page1);
// create ReportTitle band
page1.ReportTitle = new ReportTitleBand();
page1.ReportTitle.Name = "ReportTitle1";
// set its height to 1.5cm
page1.ReportTitle.Height = Units.Centimeters * 1.5f;
// create group header
GroupHeaderBand group1 = new GroupHeaderBand();
group1.Name = "GroupHeader1";
group1.Height = Units.Centimeters * 1;
// set group condition
group1.Condition = "[Products.ProductName].Substring(0, 1)";
// add group to the page.Bands collection
page1.Bands.Add(group1);
// create group footer
group1.GroupFooter = new GroupFooterBand();
group1.GroupFooter.Name = "GroupFooter1";
group1.GroupFooter.Height = Units.Centimeters * 1;
// create DataBand
DataBand data1 = new DataBand();
data1.Name = "Data1";
data1.Height = Units.Centimeters * 0.5f;
// set data source
data1.DataSource = report.GetDataSource("Products");
// connect databand to a group
group1.Data = data1;
// create "Text" objects
// report title
TextObject text1 = new TextObject();
text1.Name = "Text1";
// set bounds
text1.Bounds = new RectangleF(0, 0,
Units.Centimeters * 19, Units.Centimeters * 1);
// set text
text1.Text = "PRODUCTS";
// set appearance
text1.HorzAlign = HorzAlign.Center;
text1.Font = new Font("Tahoma", 14, FontStyle.Bold);
// add it to ReportTitle
page1.ReportTitle.Objects.Add(text1);
// group
TextObject text2 = new TextObject();
text2.Name = "Text2";
text2.Bounds = new RectangleF(0, 0,
Units.Centimeters * 2, Units.Centimeters * 1);
text2.Text = "[[Products.ProductName].Substring(0, 1)]";
text2.Font = new Font("Tahoma", 10, FontStyle.Bold);
Working with Windows.Forms 23
// add it to GroupHeader
group1.Objects.Add(text2);
// data band
TextObject text3 = new TextObject();
text3.Name = "Text3";
text3.Bounds = new RectangleF(0, 0,
Units.Centimeters * 10, Units.Centimeters * 0.5f);
text3.Text = "[Products.ProductName]";
text3.Font = new Font("Tahoma", 8);
// add it to DataBand
data1.Objects.Add(text3);
// group footer
TextObject text4 = new TextObject();
text4.Name = "Text4";
text4.Bounds = new RectangleF(0, 0,
Units.Centimeters * 10, Units.Centimeters * 0.5f);
text4.Text = "Count: [CountOfProducts]";
text4.Font = new Font("Tahoma", 8, FontStyle.Bold);
// add it to GroupFooter
group1.GroupFooter.Objects.Add(text4);
// add a total
Total groupTotal = new Total();
groupTotal.Name = "CountOfProducts";
groupTotal.TotalType = TotalType.Count;
groupTotal.Evaluator = data1;
groupTotal.PrintOn = group1.Footer;
// add it to report totals
report.Dictionary.Totals.Add(groupTotal);
// run the report
report.Show();
生成的报表如下:
fastreport常见问题:http://www.fastreportcn.com/FAQ/index.html
Tag标签:FastReport.Net
下一篇: FastReport报表对象介绍
慧都科技旗下网站-FastReport中文网版权所有 Copyright 2012
FastReport,报表控件,FastReport报表,VCL报表,.NET报表,COM/ActiveX报表,OLAP控件,联机分析处理