FastReport .Net是适用于Windows Forms,ASP.NET,MVC和.NET Core的全功能报表解决方案。它可以在Microsoft Visual Studio 2005-2019中使用。支持.Net Framework 2.0-4.x,.NET Core 3.0及以上版本。
在FastReport .NET 2021.1的新版本中,我们实现了对.NET 5的支持。添加了新条形码-Deutsce Post Leitcode。将RTF转换为报告对象的算法已得到显着改进。并且还添加了用于转换数字的新功能。欢迎下载体验。(点击下方按钮下载)
立即点击下载FastReport.NET v2021.1最新版
下载FastReport组件必须的dll文件,如下图:
创建个WinForm项目
引用dll文件
引用dll文件创建FastReport控件工具
创建打印设置From
C#代码:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Windows.Forms; using FastReport; using System.Data.SqlClient; namespace PrintTest001 { public partial class FrmPrintDesigner : Form { public FrmPrintDesigner() { InitializeComponent(); } private void FrmPrintDesigner_Load(object sender, EventArgs e) { Report dReport = new Report(); //实例化一个Report报表 String reportFile = "Report/Report01.frx"; dReport.Load(reportFile); //载入报表文件 this.designerControl1.Report = dReport; //这里不一样的是把Report赋给控件的属性 DataSet ds1 = new DataSet(); ds1 = getDataHz(); dReport.RegisterData(ds1, "单据汇总"); DataSet ds2 = new DataSet(); ds2 = getDataMx(); dReport.RegisterData(ds2, "单据明细"); dReport.Prepare(); //准备 dReport.Design(); //显示 } private DataSet getDataHz() { String connStr = ReturnDataSet.connectionString; SqlConnection conn = new SqlConnection(connStr); conn.Open(); String sqlStr = ReturnDataSet.HzSql; SqlCommand comm = new SqlCommand(); comm.CommandText = sqlStr; comm.CommandType = CommandType.Text; comm.Connection = conn; DataSet ds = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(comm); adapter.Fill(ds, "单据汇总"); conn.Close(); return ds; } private DataSet getDataMx() { String connStr = ReturnDataSet.connectionString; SqlConnection conn = new SqlConnection(connStr); conn.Open(); String sqlStr = ReturnDataSet.MxSql; SqlCommand comm = new SqlCommand(); comm.CommandText = sqlStr; comm.CommandType = CommandType.Text; comm.Connection = conn; DataSet ds = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(comm); adapter.Fill(ds, "单据明细"); conn.Close(); return ds; } } }
创建打印预览From
C#代码:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using FastReport; using System.Data.SqlClient; namespace PrintTest001 { public partial class FrmPrintPreview : Form { public FrmPrintPreview() { InitializeComponent(); } private void FrmPrintPreview_Load(object sender, EventArgs e) { Report dReport = new Report(); //实例化一个Report报表 String reportFile = "Report/Report01.frx"; dReport.Load(reportFile); //载入报表文件 dReport.Preview = previewControl1; //设置报表的Preview控件(这里的previewControl1就是我们之前拖进去的那个) DataSet ds1 = new DataSet(); ds1 = getDataHz(); dReport.RegisterData(ds1, "单据汇总"); DataSet ds2 = new DataSet(); ds2 = getDataMx(); dReport.RegisterData(ds2, "单据明细"); dReport.Prepare(); //准备 dReport.ShowPrepared(); //显示 } private DataSet getDataHz() { String connStr = ReturnDataSet.connectionString; SqlConnection conn = new SqlConnection(connStr); conn.Open(); String sqlStr = ReturnDataSet.HzSql; SqlCommand comm = new SqlCommand(); comm.CommandText = sqlStr; comm.CommandType = CommandType.Text; comm.Connection = conn; DataSet ds = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(comm); adapter.Fill(ds, "单据汇总"); conn.Close(); return ds; } private DataSet getDataMx() { String connStr = ReturnDataSet.connectionString; SqlConnection conn = new SqlConnection(connStr); conn.Open(); String sqlStr = ReturnDataSet.MxSql; SqlCommand comm = new SqlCommand(); comm.CommandText = sqlStr; comm.CommandType = CommandType.Text; comm.Connection = conn; DataSet ds = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(comm); adapter.Fill(ds, "单据明细"); conn.Close(); return ds; } } }
示例:
打印设置效果: 打印预览效果:
本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:FastReport控件中文网 [https://www.fastreportcn.com/]
本文地址:https://www.fastreportcn.com/post/2939.html
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:FastReport控件中文网 [https://www.fastreportcn.com/]
本文地址:https://www.fastreportcn.com/post/2939.html