C# winform 动态构建fastreport报表
private void DoPrint()
{
DataView dv = (DataView)dgv_apply_details.DataSource;
Report report = new Report();
//给report注册数据源
report.RegisterData(dv, "Purchasment");
//设置能在报表中使用
report.GetDataSource("Purchasment").Enabled = true;
ReportPage page1 = new ReportPage();
page1.Name = "Page1";
page1.SetDefaults(); //设置标题
page1.ReportTitle = new ReportTitleBand();
page1.ReportTitle.Name = "ReportTitle1";
page1.ReportTitle.Height = ;//Units.Centimeters * 0.1f;
//给标题赋值
TextObject txtTitle = new TextObject();
txtTitle.Name = "TextTitle";
txtTitle.Bounds = new RectangleF(, , Units.Centimeters * , Units.Centimeters * );
txtTitle.Text = "药品采购汇总单";
txtTitle.HorzAlign = HorzAlign.Center;
txtTitle.VertAlign = VertAlign.Center;
txtTitle.Font = new Font("微软雅黑", , FontStyle.Bold);
page1.ReportTitle.Objects.Add(txtTitle); GroupHeaderBand group1 = new GroupHeaderBand();
group1.Name = "GroupHeader1";
group1.Height = Units.Centimeters * 2f;
group1.Condition = "[Purchasment.order_id]";//分组条件 DataBand data1 = new DataBand();
data1.Name = "Data1";
data1.Height = Units.Centimeters * 1.5f;//Units.Centimeters * 3f;//调的是data里面数据(即dataHeaderBand)的间距,也是table中row之间的间距
data1.DataSource = report.GetDataSource("Purchasment"); #region 分组表头
//GetDataBand(ref dataBand, ref dataHeaderBand);
//TextObject txt2 = new TextObject();
//txt2.Name = "Text2";
//txt2.Bounds = new RectangleF(0, 0, Units.Centimeters * 20, Units.Centimeters * 3);
//txt2.VertAlign = VertAlign.Center;
//txt2.Font = new Font("宋体", 9, FontStyle.Bold);
//txt2.Text = dataHeaderBand;//"订单号:[Purchasment.order_id]";
//group1.Objects.Add(txt2); //TextObject txt3 = new TextObject();
//txt3.Name = "Text3";
//txt3.Bounds = new RectangleF(Units.Centimeters * 8, 0, Units.Centimeters * 20, Units.Centimeters * 3);
//txt3.VertAlign = VertAlign.Center;
//txt3.Text = "申请药房:[Purchasment.storage_name]";
//group1.Objects.Add(txt3); ////<TextObject Name="Text38" Left="198.45" Top="18.9" Width="75.6" Height="28.35" Text="订单状态:" VertAlign="Center"/>
//TextObject txt4 = new TextObject();
//txt4.Name = "Text4";
////txt4.Bounds = new RectangleF(float.Parse("198.45"), float.Parse("18.9"), float.Parse("75.6"), float.Parse("28.35"));
//txt4.Bounds = new RectangleF(Units.Centimeters * 15, 0, Units.Centimeters * 10, Units.Centimeters * 1);
//txt4.VertAlign = VertAlign.Center;
//txt4.Text = "采购科室:[Purchasment.sourceStorage]";
//group1.Objects.Add(txt4);
#endregion
//DataHeaderBand dataHeader1 = new DataHeaderBand();
//dataHeader1.Name = "DataHeader1";
//dataHeader1.Height = Units.Centimeters * 1;
//data1.Objects.Add(dataHeader1);
//GetDataBand(ref dataBand, ref dataHeaderBand); //TextObject txt6 = new TextObject();
//txt6.Name = "Text6";
//txt6.Bounds = new RectangleF(0, Units.Centimeters * 2, Units.Centimeters * 30, Units.Centimeters * 1);
//txt6.Text = dataHeaderBand;
//txt6.Font = new Font("宋体", 9, FontStyle.Bold);
//dataHeader1.Objects.Add(txt6);
////group1.Objects.Add(txt6); //TextObject txt7 = new TextObject();
//txt7.Name = "Text7";
//txt7.Bounds = new RectangleF(0, Units.Centimeters * 3, Units.Centimeters * 30, Units.Centimeters * 1f);
//txt7.Text = dataBand;
//txt7.Font = new Font("宋体", 9);
//data1.Objects.Add(txt7); #region Table表格
TableObject table1 = new TableObject();
table1.Name = "Table1";
table1.Border.Lines = BorderLines.All;
table1.Height = Units.Centimeters * 1.5f;
//table1.Width = Units.Centimeters * 30; #region TableColumn
//TableColumn column1 = new TableColumn();
//column1.Name = "Column1";
//column1.Width = Units.Centimeters * 3;
//table1.AddChild(column1);//AddChild应为添加子节点,适用于table内部
////table1.ChildObjects.Add(column);//试过这种添加方式,不过这样就不显示表格了 //TableColumn column2 = new TableColumn();
//column2.Name = "Column2";
//column2.Width = Units.Centimeters * 3;
//table1.AddChild(column2); //TableColumn column3 = new TableColumn();
//column3.Name = "Column3";
//column3.Width = Units.Centimeters * 3;
//table1.AddChild(column3); //TableColumn column4 = new TableColumn();
//column4.Name = "Column4";
//column4.Width = Units.Centimeters * 3;
//table1.AddChild(column4); //TableColumn column5 = new TableColumn();
//column5.Name = "Column5";
//column5.Width = Units.Centimeters * 3;
//table1.AddChild(column5); //TableColumn column6 = new TableColumn();
//column6.Name = "Column6";
//column6.Width = Units.Centimeters * 3;
//table1.AddChild(column6);
#endregion TableRow row1 = new TableRow();
row1.Name = "Row1";
row1.Height = Units.Centimeters * 1.5f;
table1.AddChild(row1); #region TableCell cell1
//TableCell cell1 = new TableCell();
//cell1.Name = "Cell1";
//cell1.HorzAlign = HorzAlign.Center;
//cell1.VertAlign = VertAlign.Center;
//cell1.Border.Lines = BorderLines.All;
//cell1.Text = "[Purchasment.drug_name]";
//cell1.Font = new Font("宋体", 9);
//row1.AddChild(cell1); //TableCell cell2 = new TableCell();
//cell2.Name = "Cell2";
//cell2.HorzAlign = HorzAlign.Center;
//cell2.VertAlign = VertAlign.Center;
//cell2.Border.Lines = BorderLines.All;
//cell2.Text = "[Purchasment.package_spec]";
//cell2.Font = new Font("宋体", 9);
//row1.AddChild(cell2); //TableCell cell3 = new TableCell();
//cell3.Name = "Cell3";
//cell3.HorzAlign = HorzAlign.Center;
//cell3.VertAlign = VertAlign.Center;
//cell3.Border.Lines = BorderLines.All;
//cell3.Text = "[Purchasment.sale_price]";
//cell3.Font = new Font("宋体", 9);
//row1.AddChild(cell3); //TableCell cell4 = new TableCell();
//cell4.Name = "Cell4";
//cell4.HorzAlign = HorzAlign.Center;
//cell4.VertAlign = VertAlign.Center;
//cell4.Border.Lines = BorderLines.All;
//cell4.Text = "[Purchasment.manufacture_name]";
//cell4.Font = new Font("宋体", 9);
//row1.AddChild(cell4); //TableCell cell5 = new TableCell();
//cell5.Name = "Cell5";
//cell5.HorzAlign = HorzAlign.Center;
//cell5.VertAlign = VertAlign.Center;
//cell5.Border.Lines = BorderLines.All;
//cell5.Text = "[Purchasment.distributor_name]";
//cell5.Font = new Font("宋体", 9);
//row1.AddChild(cell5); //TableCell cell6 = new TableCell();
//cell6.Name = "Cell6";
//cell6.HorzAlign = HorzAlign.Center;
//cell6.VertAlign = VertAlign.Center;
//cell6.Border.Lines = BorderLines.All;
//cell6.Text = "[Purchasment.amount]";
//cell6.Font = new Font("宋体", 9);
//row1.AddChild(cell6);
#endregion SetDataHeaderAndTable(group1, page1.PaperWidth, table1, row1); data1.Objects.Add(table1); #endregion #region 报表底
page1.PageFooter = new PageFooterBand();
page1.PageFooter.Name = "PageFooter1";
page1.PageFooter.Height = Units.Centimeters * ;//这个高度必须>=PageFooter包含文字的RectangleF里面的y的值 TextObject ftxt1 = new TextObject();
ftxt1.Name = "FText1";
ftxt1.Bounds = new RectangleF(, Units.Centimeters * , Units.Centimeters * , Units.Centimeters * );
ftxt1.Text = "打印时间:[Date]";
ftxt1.Font = new Font("宋体", );
ftxt1.VertAlign = VertAlign.Center;
page1.PageFooter.Objects.Add(ftxt1); TextObject ftxt2 = new TextObject();
ftxt2.Name = "FText2";
ftxt2.Bounds = new RectangleF(Units.Centimeters * , Units.Centimeters * , Units.Centimeters * , Units.Centimeters * );
ftxt2.Text = "页码:[PageN]/[TotalPages#]";
ftxt2.Font = new Font("宋体", );
ftxt2.VertAlign = VertAlign.Center;
page1.PageFooter.Objects.Add(ftxt2); TextObject ftxt3 = new TextObject();
ftxt3.Name = "FText3";
ftxt3.Bounds = new RectangleF(Units.Centimeters * , Units.Centimeters * , Units.Centimeters * , Units.Centimeters * );
ftxt3.Text = "打印人:[operator]";
ftxt3.Font = new Font("宋体", );
ftxt3.VertAlign = VertAlign.Center;
page1.PageFooter.Objects.Add(ftxt3);
report.SetParameterValue("operator", SysConfig.UserCode);
#endregion //group1.Objects.Add(data1);
group1.Data = data1;
page1.Bands.Add(group1);
report.Pages.Add(page1);
report.Show();
}
/// <summary>
/// 根据当前显示的字段,动态添加数据首和表格
/// </summary>
private void SetDataHeaderAndTable(GroupHeaderBand group1, float pageWidth, TableObject table1, TableRow row1)
{
int count = ;//记录显示的列数
int index = ;
DataTable dt = OrderBL.SelectFreecombination(this.Name);
if (dt != null)
{
for (int i = ; i < dgv_apply_details.Columns.Count; i++)
{
if (dgv_apply_details.Columns[i].Visible)
{
count++;
}
}
if (count <= )
{
YxMessageBox.ShowWarning("当前没有可打印的数据!");
return;
}
for (int i = ; i < dt.Rows.Count; i++)
{
if (DbHelper.GetBool(dt.Rows[i], "print_status"))
{
TextObject text = new TextObject();
text.Name = "Text" + index.ToString();
text.Bounds = new RectangleF( + index * ( * pageWidth / count), , * pageWidth / count, Units.Centimeters * );
text.VertAlign = VertAlign.Center;
text.Font = new Font("宋体", , FontStyle.Bold);
text.Text = DbHelper.GetString(dt.Rows[i], "header_text");
group1.Objects.Add(text); TableColumn column1 = new TableColumn();
column1.Name = "Column" + index.ToString(); ;
column1.Width = * pageWidth / count;//Units.Centimeters * 3;
table1.AddChild(column1); TableCell cell1 = new TableCell();
cell1.Name = "Cell" + index.ToString(); ;
cell1.HorzAlign = HorzAlign.Center;
cell1.VertAlign = VertAlign.Center;
cell1.Border.Lines = BorderLines.All;
cell1.Text = "[Purchasment." + DbHelper.GetString(dt.Rows[i], "dataproperty_name") + "] ";
cell1.Font = new Font("宋体", );
row1.AddChild(cell1); index++;
}
}
}
}
打印效果如图:
C# winform 动态构建fastreport报表的更多相关文章
- 使用FastReport报表工具生成报表PDF文档
在我们开发某个系统的时候,客户总会提出一些特定的报表需求,固定的报表格式符合他们的业务处理需要,也贴合他们的工作场景,因此我们尽可能做出符合他们实际需要的报表,这样我们的系统会得到更好的认同感.本篇随 ...
- FastReport报表设计(仔细看)
FastReport报表设计 2011-06-16 16:56:19| 分类: 系统开发|举报|字号 订阅 下载LOFTER我的照片书 | 目录 5.1 前言 5.2 基本概念及操 ...
- FastReport报表设计
[转载]FastReport报表设计 (2012-10-24 20:37:26) 转载▼ 标签: 转载 原文地址:FastReport报表设计作者:小黑 FastReport报表设计 目录 5.1 ...
- 使用FastReport报表工具生成标签打印文档
在我们实际开发报表的时候,我们需要按一定的业务规则组织好报表的模板设计,让报表尽可能的贴近实际的需求,在之前的随笔中<使用FastReport报表工具生成报表PDF文档>介绍了FastRe ...
- 使用FastReport报表工具生成图片格式文档
之前我在随笔<使用FastReport报表工具生成报表PDF文档>介绍过使用FastReport.Net来根据报表模板进行生成PDF,以及随笔<使用FastReport报表工具生成标 ...
- 使用 SailingEase WinForm 框架构建复合式应用程序(插件式应用程序)
对于一些较小的项目,具备一定经验的开发人员应该能够设计和构建出便于进行维护和扩展的应用程序.但是,随着功能模块数量(以及开发维护这些部件的人员)的不断增加,对项目实施控制的难度开始呈指数级增长. Sa ...
- FastReport报表控件使用技巧总结
FastReport报表控件使用技巧总结 1.FastReport中如何访问报表中的对象? 可以使用FindObject方法. TfrxMemoView(frxReport1.FindObject(' ...
- Winform中在FastReport的PreviewControl预览控件中对report控件模板中控件值进行修改
场景 FastReport安装包下载.安装.去除使用限制以及工具箱中添加控件: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/10 ...
- 使用FastReport报表工具实现信封套打功能
在较早期的报表套打的时候,我倾向于使用LODOP的ActiveX进行报表的打印或者套打,BS效果还是很不错的.之前利用它在Winform程序里面实现信封套打功能,详细参考<基于信封套打以及批量打 ...
随机推荐
- The SDK directory '/home/wangju/gitProject/Automation/D:\Android_SDK' does not exist.
执行gradle clean命令报错 gradle clean FAILURE: Build failed with an exception. * What went wrong: A proble ...
- xml解析用正则解决没有标签的文本的解析不出异常
如 <q>sasas<w>eqwe</w>ddas</q> package com.people.xmlToSql; import java.io.F ...
- python改变导入模块中的变量的问题
Python中循环函数1调用函数2,函数2中import了一个模块,函数1: def run(): for a in b: runTest(a,patter) 函数2: def runTest(cas ...
- Gcd的原理理解
Ps:最小公倍数=a*b/gcd(a,b) a除以b的商为p,余数为q,a=b*p+q,gcd(b,q)可以整除a和b,因此gcd(b,q)也能整除gcd(a,b):反过来,gcd(a,b)也能整除g ...
- Mysql 2019-07-01
- Scapy——Scrapy shell的使用
在开发爬虫的使用,scrapy shell可以帮助我们定位需要爬取的资源 启动Scrapy Shell 在终端中输入以下内容即可启动scrapy shell,其中url是要爬取的页面,可以不设置 sc ...
- python基础--新式类实现单例模式
在网上看了有关python实现单例模式的博客,发现好多都是转载的,并且都是按照python2.x版本旧式类的方式写的. 虽然也能读懂,但对于我这种一开始学的就是python3.x的新手来说,心里总有点 ...
- ConcurrentHashMap(锁分段技术)
线程不安全的HashMap 因为多线程环境下,使用Hashmap进行put操作会引起死循环,导致CPU利用率接近100%,所以在并发情况下不能使用HashMap. 效率低下的HashTab ...
- DB2临时表空间的作用
临时表空间分为系统临时表空间和用户临时表空间 系统临时表空间用来存储各种数据操作(排序.重组表.创建索引.连接表)中所需的内部临时数据,虽然可以创建任意多个系统临时表空间,但建议用户只使用大多数表所使 ...
- Java8 Stream流API常用操作
Java版本现在已经发布到JDK13了,目前公司还是用的JDK8,还是有必要了解一些JDK8的新特性的,例如优雅判空的Optional类,操作集合的Stream流,函数式编程等等;这里就按操作例举一些 ...