1:新建�蟊硭�需的���源DataSet.cs

复制代码 代码如下:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Data;

namespace ********
{
    public class DataSet
    {
        public DataTable CreatDataSet()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(“A”);
            dt.Columns.Add(“B”);
            dt.Columns.Add(“C”);
            return dt;

        }
    }
}

指定所需要�定的Table的列,返回dataTable �,CreatDataSet方法名�Q�S便起,也可以在一����Y面定�x多��方法(不同���源)

2:�O��蟊�

�蟊碓O��@�e就不涉及了

3:把第一步新建的���源加到�蟊硌Y面�定

 注意:�@�e需要先引用 Interop.VBA.dll 才可以把新建的CS文件作����源��入

 

把���源��入后�定即可

4:直接把�蟊�С��PDF,Excel等格式

复制代码 代码如下:

ReportViewer viewer = new ReportViewer();

            viewer.ProcessingMode = ProcessingMode.Local;

            viewer.LocalReport.ReportEmbeddedResource = “***.Page.Report.Report1.rdlc”;

            ReportDataSource rds_1 = new ReportDataSource(“DataSet1”, dtReport);//DataSet1��蟊硌Y面的���源名�Q

            viewer.LocalReport.DataSources.Add(rds_1);

            ReportParameter rp1 = new ReportParameter(“���1″,”���1的值” );//�o��蒂x值

            ReportParameter rp2 = new ReportParameter(“���2″,”���2的值” );

            viewer.LocalReport.SetParameters(new ReportParameter[] {rp1, rp2 });

            Warning[] warnings;
            string[] streamIds;
            string mimeType = string.Empty;
            string encoding = string.Empty;
            string extension = string.Empty;

            byte[] bytes = viewer.LocalReport.Render(“Excel”, null, out mimeType, out encoding, out extension, out streamIds, out warnings);
            //Excel ,PDF ,Word 等格式
            // Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = mimeType;
            Response.AddHeader(“content-disposition”, “attachment; filename=1_” + DateTime.Now.ToString(“yyyyMMddhhssmm”) + “” + “.” + extension);
            Response.BinaryWrite(bytes); // create the file
            Response.Flush(); // send it to the client to download

5:在�面引用�蟊恚�rpResult��蟊砜丶�)

复制代码 代码如下:

DataTable dt = new DataTable();//自己拼出���源就可以

                ReportDataSource repDataSource = new ReportDataSource(“DataSet1”, dt);

                //*�O置�蟊���,并�@示

                this.rpResut.LocalReport.ReportEmbeddedResource = “***.Page.Report.Report1.rdlc””;

                this.rpResut.LocalReport.DataSources.Clear();

                this.rpResut.LocalReport.DataSources.Add(repDataSource);

                 ReportParameter rp1 = new ReportParameter(“���1″,”���1的值” );//�o��蒂x值

                  ReportParameter rp2 = new ReportParameter(“���2″,”���2的值” );

                this.rpResut.LocalReport.SetParameters(new ReportParameter[] {rp1, rp2 });

                this.rpResut.DataBind();

                this.rpResut.LocalReport.Refresh();

至此,�蟊淼漠a出和�@示都OK了,如果需要更深入的了解,�查看其它文章

声明:本站(华域联盟www.cnhackhy.com)所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。