C#利用ReportViewer生成報表
本文主要是利用微軟自帶的控件ReportViewer進行報表設計的小例子,具體內(nèi)容如下
涉及知識點:
ReportViewer :位于Microsoft.Reporting.WinForms命名空間, 主要用于報表的顯示
Report:報表,以rdlc結(jié)尾的文件,可視化設計報表模板。
報表數(shù)據(jù):內(nèi)置字段,參數(shù),圖像,數(shù)據(jù)集(本報表主要使用參數(shù),和數(shù)據(jù)集)
ReportParameter:使用名稱和值實例化新的報表參數(shù)
ReportDataSource:報表的數(shù)據(jù)源與DataTable對象聯(lián)系起來
效果圖如下:

相關(guān)代碼如下:
/// <summary>
/// 設置報表
/// </summary>
private void SetReport()
{
//第一步:清除之前的數(shù)據(jù)
this.rptView.LocalReport.DataSources.Clear();
//第二步:指定報表路徑
this.rptView.LocalReport.ReportPath = "Report2.rdlc";
//第三步:構(gòu)造新的DataTable
DataTable dt = new DataTable("DataTable1");
dt.Columns.Add("Name");
dt.Columns.Add("Score");
dt.Columns.Add("Id");
dt.Rows.Add(new object[] { "語文", 80, "Y0001" });
dt.Rows.Add(new object[] { "數(shù)學", 75, "S0001" });
dt.Rows.Add(new object[] { "英文", 96, "E0001" });
//名稱不能寫錯,和報表中的數(shù)據(jù)集名稱一致
ReportDataSource rdsItem = new ReportDataSource("DataSet1", dt);
//此處可以有多個數(shù)據(jù)源
this.rptView.LocalReport.DataSources.Add(rdsItem);
//第四步:構(gòu)造參數(shù)
List<ReportParameter> lstParameter = new List<ReportParameter>() {
new ReportParameter("Title",this.txtTitle.Text),
new ReportParameter("Id",this.txtId.Text),
new ReportParameter("Name",this.txtName.Text),
new ReportParameter("Age",this.txtAge.Text),
new ReportParameter("Sex",this.txtSex.Text),
new ReportParameter("Salary",this.txtSalary.Text),
new ReportParameter("Depart",this.txtDepart.Text)
};
this.rptView.LocalReport.SetParameters(lstParameter);
this.rptView.ZoomMode = ZoomMode.Percent;
this.rptView.ZoomPercent = 100;
//第五步:刷新報表
this.rptView.RefreshReport();
}
源碼下載鏈接
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
深入分析緩存依賴中cachedependency對象及周邊小講
本篇文章是對緩存依賴中cachedependency對象進行了詳細的分析介紹,需要的朋友參考下2013-06-06
PowerShell 定時執(zhí)行.Net(C#)程序的方法
利用PowerShell可以調(diào)用動態(tài)頁面,然后再用 .bat 執(zhí)行 PowerShell 腳本,最后把 .bat 添加到服務器的任務計劃里面。OK,所有操作都做好了,.Net 定時執(zhí)行了,是不是呢,有木有呢。2013-04-04
C#實現(xiàn)多種圖片格式轉(zhuǎn)換的示例詳解
這篇文章主要為大家詳細介紹了C#如何實現(xiàn)多種圖片格式轉(zhuǎn)換,例如轉(zhuǎn)換成圖標圖像ICO,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下2024-01-01

