• <noscript id="ecgc0"><kbd id="ecgc0"></kbd></noscript>
    <menu id="ecgc0"></menu>
  • <tt id="ecgc0"></tt>

    winfrom報表打印怎么做

    Visual Studio 2017

    方式/步調

    1. 1

      1.起首建立一個窗體Form,然后添加一個報表瀏覽器ReportViewer,該報表瀏覽器可直接從東西箱中拖拽。如下圖所示:

      adaf2edda3cc7cd9f889f4d33601213fb80e9110.jpg
    2. 2

      2.在新建立的Form窗體統一目次下添加報表,右鍵–>添加–>新建項,彈出一個“添加新項”窗口,選擇Reporting菜單項,然后選擇報表,如下圖所示:

      902397dda144ad34302b478ddfa20cf431ad8520.jpg
    3. 3

      3.報表添加完當作后,雙擊打開報表Report1.rdlc,如下圖所示。點擊左側東西箱可以按照需要添加表格,文本框等,設計報表樣式。

      a8014c086e061d9516c1f73274f40ad162d9ca31.jpg
    4. 4

      4.報表設計好后,需要建立報表所需數據集,同樣右鍵–>添加–>新建項,彈出一個“添加新項”窗口。但此次選擇的是Reporting菜單項上方的“數據”菜單項。然后選擇數據集,輸入數據集名字,點擊確定,完當作數據集建立。如下如所示:

      f3d3572c11dfa9ecafa9961d6dd0f703918fc131.jpg
    5. 5

      5.雙擊打開新建立的數據集DataSet,空白處右鍵添加數據表,或者從東西箱中拖拽。

      9e3df8dcd100baa10df787b14810b912c9fc2ee5.jpg
    6. 6

      6.選中數據表,右鍵添加數據列,并輸入數據列的名字?

      242dd42a2834349b538aae8fc6ea15ce36d3be28.jpg
    7. 7

      7.從頭打開報表Report1.rdlc。在設計好的報表中,點擊報表中單位格右上角的數據庫圖標,添加方才建立的數據集到報表中。

      cb8065380cd79123f168547ea2345982b2b78034.jpg
    8. 8

      8.在表格設計中可能會涉及到按照類別分組,如下圖所示表格樣式,行按照類別分組?

      023b5bb5c9ea15ce65f82303b9003af33a87b2a2.jpg
    9. 9

      9.分組方式:選中機型名稱列單位格,右鍵選擇“添加組”–>”行組”–>”父組”,打開Tablix組界面。?

      810a19d8bc3eb135990277b1a91ea8d3fc1f44f7.jpg
    10. 10

      10.添加完當作后,如下圖所示 (列的分組與行分組近似。)

      e7cd7b899e510fb3ee57b49dd633c895d1430c6a.jpg
    11. 11

      11.有些報表可能需要添加報表參數,按照程序動態改變。?
      報表數據中,選擇“參數”,右鍵選擇“添加參數”,如下圖所示?

      d4628535e5dde71114ae80fca8efce1b9d1661b8.jpg
    12. 12

      12.設置參數名稱?

      5366d0160924ab184d10223d3afae6cd7b890bb2.jpg
    13. 13

      13.參數設置完當作后,東西箱中拖拽一個文本框到報表中,設置文本框名。?

      b999a9014c086e0607ebfc410d087bf40ad1cb7d.jpg
    14. 14

      14.然后,右鍵文本框,選擇“文本框”屬性,打開文本框屬性窗口,設置參數名稱和參數值。注重,參數名字必需和文本框名字一致!?

      aec379310a55b3191d0f417f4ca98226cefc17c2.jpg
    15. 15

      15.填湊數據源 ,在給報表填湊數據源時,習慣于寫一個通用方式。如下是本家兒要代碼片段

      ///

      ? ? ? ? /// 生當作圖表

      ? ? ? ? ///

      ? ? ? ? /// 數據源

      ? ? ? ? /// 報表參數

      ? ? ? ? private void generateChart( DataSet ds_source, ReportParameter[] rp)

      ? ? ? ? {

      ? ? ? ? ? ? try

      ? ? ? ? ? ? {

      ? ? ? ? ? ? ? ? if (ds_results.Tables.Count > 0)

      ? ? ? ? ? ? ? ? {

      ? ? ? ? ? ? ? ? ? ? ? ? //重置報表

      ? ? ? ? ? ? ? ? ? ? ? ? this.reportViewer1.Reset();

      ? ? ? ? ? ? ? ? ? ? ? ? this.reportViewer1.LocalReport.ReportEmbeddedResource = "Report1.rdlc";


      ? ? ? ? ? ? ? ? ? ? ? ? //指心猿意馬報表參數

      ? ? ? ? ? ? ? ? ? ? ? ? for (int i = 0; i < rp.Length; i++)

      ? ? ? ? ? ? ? ? ? ? ? ? {

      ? ? ? ? ? ? ? ? ? ? ? ? ? ? this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp[i] });//與報表有關問題

      ? ? ? ? ? ? ? ? ? ? ? ? }


      ? ? ? ? ? ? ? ? ? ? //報表數據源

      ? ? ? ? ? ? ? ? ? ? ReportDataSource rds1 = new ReportDataSource("DataSet1", ds_results.Tables["DataSet1"]);//注重此處數據集名字“DataSet1”必需要和添加的數據集名字不異,不然無法綁定命據源至報表數據集

      ? ? ? ? ? ? ? ? ? ? ReportDataSource rds2= new ReportDataSource("DataSet2", ds_results.Tables["DataSet2"]);? ? ? ? ? ? ? ? ?


      ? ? ? ? ? ? ? ? ? ? reportViewer1.LocalReport.DataSources.Clear();

      ? ? ? ? ? ? ? ? ? ? reportViewer1.LocalReport.DataSources.Add(rds1 );

      ? ? ? ? ? ? ? ? ? ? reportViewer1.LocalReport.DataSources.Add(rds2 );? ? ? ? ? ? ? ? ? ?


      ? ? ? ? ? ? ? ? ? ? reportViewer1.RefreshReport();


      ? ? ? ? ? ? ? ? }

      ? ? ? ? ? ? ? ? else

      ? ? ? ? ? ? ? ? {

      ? ? ? ? ? ? ? ? ? ? MessageBox.Show("沒稀有據!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Information);


      ? ? ? ? ? ? ? ? ? ? ?//報表數據源

      ? ? ? ? ? ? ? ? ? ? ReportDataSource rds1 = new ReportDataSource("DataSet1", ds_results.Tables["DataSet1"]);

      ? ? ? ? ? ? ? ? ? ? ReportDataSource rds2= new ReportDataSource("DataSet2", ds_results.Tables["DataSet2"]);? ? ? ? ? ? ? ? ?


      ? ? ? ? ? ? ? ? ? ? reportViewer1.LocalReport.DataSources.Clear();

      ? ? ? ? ? ? ? ? ? ? reportViewer1.LocalReport.DataSources.Add(rds1 );

      ? ? ? ? ? ? ? ? ? ? reportViewer1.LocalReport.DataSources.Add(rds2 );? ? ? ? ? ? ? ? ? ?


      ? ? ? ? ? ? ? ? ? ? reportViewer1.RefreshReport();

      ? ? ? ? ? ? ? ? }

      ? ? ? ? ? ? }

      ? ? ? ? ? ? catch (Exception ex)

      ? ? ? ? ? ? {


      ? ? ? ? ? ? }

      ? ? ? ? }


      //以下為本家兒方式內代碼:

      ? ? ? ? ? ? ?#region 綁心猿意馬報表參數

      ? ? ? ? ? ? ? ? string p1 = "參數1";

      ? ? ? ? ? ? ? ? string p2="參數2";


      ? ? ? ? ? ? ? ? ReportParameter[] rp = new ReportParameter[2];//

      ? ? ? ? ? ? ? ? string[] rptName = new string[2] { "START_END_TIME", "參數名2" };//這里要注重,報表參數和文本框的名字必需一致

      ? ? ? ? ? ? ? ? object[] rptValue = new object[] { p1, p2};

      ? ? ? ? ? ? ? ? for (int i = 0; i < rp.Length; i++)

      ? ? ? ? ? ? ? ? {

      ? ? ? ? ? ? ? ? ? ? rp[i] = new ReportParameter(rptName[i], rptValue[i].ToString());

      ? ? ? ? ? ? ? ? }


      ? ? ? ? ? ? ? ? #endregion


      //綁心猿意馬報表參數后,籌辦數據集數據源DataSet,然后挪用上面通用方式

      generateChart(ds_source,rp);

      以上,即為報表設計和為報表填湊數據的本家兒要步調。

    • 發表于 2019-10-22 17:00
    • 閱讀 ( 786 )
    • 分類:其他類型

    你可能感興趣的文章

    相關問題

    0 條評論

    請先 登錄 后評論
    聯系我們:uytrv@hotmail.com 問答工具
  • <noscript id="ecgc0"><kbd id="ecgc0"></kbd></noscript>
    <menu id="ecgc0"></menu>
  • <tt id="ecgc0"></tt>
    久久久久精品国产麻豆