本文主要是利用微軟自帶的控件ReportViewer進行報表設(shè)計的小例子,具體內(nèi)容如下
涉及知識點:
ReportViewer :位于Microsoft.Reporting.WinForms命名空間, 主要用于報表的顯示
Report:報表,以rdlc結(jié)尾的文件,可視化設(shè)計報表模板。
報表數(shù)據(jù):內(nèi)置字段,參數(shù),圖像,數(shù)據(jù)集(本報表主要使用參數(shù),和數(shù)據(jù)集)
ReportParameter:使用名稱和值實例化新的報表參數(shù)
ReportDataSource:報表的數(shù)據(jù)源與DataTable對象聯(lián)系起來
效果圖如下:
相關(guān)代碼如下:
/// <summary> /// 設(shè)置報表 /// </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(); }
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站chinadenli.net,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
新聞標題:C#利用ReportViewer生成報表-創(chuàng)新互聯(lián)
文章位置:http://chinadenli.net/article34/ehpse.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動態(tài)網(wǎng)站、定制開發(fā)、全網(wǎng)營銷推廣、企業(yè)建站、品牌網(wǎng)站設(shè)計、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容