报告生成器FastReport .NET实践指南:使用代码VB.Net创建一个新报告

说到.Net框架,我们通常会想到#C编程语言。仅仅是因为C#程序员的人数众多。但是我们也不应忘记其他语言。本文介绍了如何使用代码VB.Net创建一个新报告

报表生成器

Fastreport在线下单立享85折起!赶紧加入购物清单吧!

说到.Net框架,我们通常会想到#C编程语言。仅仅是因为C#程序员的人数众多。但是我们也不应忘记其他语言。例如,来自Stimulsoft的报告生成器的用户希望使用VB.Net语言的应用程序代码创建报告:

“目前,我只是在测试,我想使用VB中的代码创建一个报告。 目前,我试图显示一份我在VB中编写的标题的报告。但不向我显示Web应用程序中的任何内容。

您能否给我一些指导,以指导如何从VB设计报告并显示出来或者,如果我省略任何指示或对象来进行报告

像允许您从代码创建报告的任何其他报告生成器一样,可以从VB.Net语言的代码中使用Stimulsoft Reports.Net。开发人员已向用户解释了如何执行此操作。

但是,当考虑使用FastReport.Net的某些情况时,实际上我们看不到VB.Net语言中的任何示例。这就是为什么我们要更正本文,并向您展示一个示例,该示例使用VB.Net语言从用户应用程序的代码创建报告。

实际上,它只是C#代码的一种解释:

 Dim AppFolder As String Dim report As New Report() 'create instance of class Report Dim ds As New DataSet() 'create dataset object AppFolder = "C:UsersUsersourcereposVBCodeReportVBCodeReportApp_Data" 'load data ds.ReadXml(AppFolder + "nwind.xml") report.RegisterData(ds) report.GetDataSource("Products").Enabled = True 'create report page Dim page As New ReportPage() report.Pages.Add(page) 'add created page to report page collection page.CreateUniqueName() 'with generated name 'create group header band Dim group As New GroupHeaderBand() page.Bands.Add(group) 'add the band to band collection group.CreateUniqueName() 'with generated name group.Height = Units.Centimeters * 1 group.Condition = "[Products.ProductName].Substring(0,1)" 'set the group condition group.SortOrder = FastReport.SortOrder.Ascending 'and set sort order 'create text object Dim groupTxt As New TextObject() groupTxt.Parent = group 'set the object on whitch the text will be shown groupTxt.CreateUniqueName() groupTxt.Bounds = New RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 1) 'set the text object bounds groupTxt.Text = "[[Products.ProductName].Substring(0,1)]" 'set the text value groupTxt.Font = New Font("Arial", 14, FontStyle.Bold) 'set the font style groupTxt.VertAlign = VertAlign.Center ' set the text align groupTxt.Fill = New LinearGradientFill(Color.LightGoldenrodYellow, Color.Gold, 90, 0.5F, 1) 'set the text object fill 'create data band Dim data As New DataBand() group.Data = data 'set the group data data.CreateUniqueName() data.DataSource = report.GetDataSource("Products") 'set data band source data.Height = Units.Centimeters * 0.5F 'set data band height 'create one more text object Dim productText As New TextObject() productText.Parent = data 'add the text object to data band productText.CreateUniqueName() productText.Bounds = New RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 0.5F) 'set the text object bounds productText.Text = "[Products.ProductName]" 'set the text value 'create group footer band group.GroupFooter = New GroupFooterBand() group.GroupFooter.CreateUniqueName() group.GroupFooter.Height = Units.Centimeters * 1 'set the group footer height 'create total object Dim groupTotal As New Total() groupTotal.Name = "TotalRows" 'set total object name groupTotal.TotalType = TotalType.Count 'set total type groupTotal.Evaluator = data 'set the band for which the total will be calculated groupTotal.PrintOn = group.GroupFooter 'set the total place report.Dictionary.Totals.Add(groupTotal) 'add the total object to totals collection 'create text object Dim totalText As New TextObject() totalText.Parent = group.GroupFooter 'set the object on whitch the text will be shown totalText.CreateUniqueName() totalText.Bounds = New RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 0.5F) 'set the text object bounds totalText.Text = "Rows: [TotalRows]" 'set the text value totalText.HorzAlign = HorzAlign.Right 'set the text align totalText.Border.Lines = BorderLines.Top 'set the border lines type report.Show() 'show report

 从代码和注释中可以清楚地看到,创建了带有数据分组的报告。但是,此示例显示了简单报表中使用最频繁的对象的工作。请注意,创建报告对象还不够,您仍然需要将其“放置”在要显示它的对象上。这是从代码正确创建报告的关键。

报告生成器FastReport .NET实践指南:使用代码VB.Net创建一个新报告

虽然FastReport Open Source是非常强大的,但仍然有许多限制,你可以点击下方链接查看具体差异。

【功能对比】报表开发工具FastReport Open Source和FastReport .NET都有哪些差异和限制

FastReport Open Source与FastReport .Net间的功能差异还是非常明显的,如果您是企业用户或是需要更完整的功能,建议您直接购买FastReport .Net,盛夏狂欢,在线下单立享85折起!点击查看优惠价格,或咨询在线客服了解详情。

标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年8月26日
下一篇 2020年8月26日

相关推荐

发表回复

登录后才能评论