最近公司的功能需要使用报表,用的是微软自带的报表,谈一谈我们的做法,希望可以给想学习的人一些指导

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方法名稱隨便起,也可以在一個類裏面定義多個方法(不同數據源)

2:設計報表

報表設計這裡就不涉及了

3:把第一步新建的數據源加到報表裏面綁定

注意:這裡需要先引用 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為報表裏面的數據源名稱
viewer.LocalReport.DataSources.Add(rds_1); ReportParameter rp1 = new ReportParameter("參數1","參數1的值" );//給參數賦值
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); //*設置報表參數,并顯示
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的值" );//給參數賦值
ReportParameter rp2 = new ReportParameter("參數2","參數2的值" ); this.rpResut.LocalReport.SetParameters(new ReportParameter[] {rp1, rp2 });
this.rpResut.DataBind();
this.rpResut.LocalReport.Refresh();

6:子報表的使用

        void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
string MasterID = e.Parameters["MasterID"].Values[];
DataRow[] drs_Main = dtSubReport.Select("MasterID = '" + MasterID + "'");
DataTable dtReport = drs_Main.CopyToDataTable();
e.DataSources.Add(new ReportDataSource("DataSetMain", dtReport)); }

7:調用

ReportViewer viewer = new ReportViewer();
viewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);

至此,報表的產出和顯示都OK了,如果需要更深入的了解,請查看其它文章

Reporting Services的简单使用的更多相关文章

  1. 迁移Reporting Services的方法与WMI错误

    今天上午,接到一个任务:迁移SQL SERVER 2005的报表服务到另外一台SQL SERVER 2008服务器,结果等我备份了两边服务器的ReportServer,ReportServerTemp ...

  2. 充分利用 SQL Server Reporting Services 图表

    最近在查SSRS的一些文章,看到MSDN在有一篇不错的文章,许多图表设置都有说明,共享给大家.. 其中有说明在SSRS中如果去写条件表达写和报表属性中的“自定义代码”,文章相对比较长,需要大家耐心的查 ...

  3. Reporting Services 的伸缩性和性能表现规划(转载)

    简介 Microsoft? SQL Server? Reporting Services 是一个将集中管理的报告服务器具有的伸缩性和易管理性与基于 Web 和桌面的报告交付手段集于一身的报告平台.Re ...

  4. 代码导出Reporting Services报表文件

    背景部分 使用Reporting Services很容易制作和发布我们需要的报表,报表效果也还不错 不过如果报表数据过大或报表数量过多,打开及查看报表感觉可能就是另外一回事了 好在Reporting ...

  5. 【Reporting Services 报表开发】— 交互式报表

    我们知道,界面是人与系统间的对话方式,当使用者面对的是冷冰冰的界面,不但会造成使用者对于系统的热情减低,也会因为不便而产生诸多抱怨.尤其像报表时企业内几乎每日都会使用到的工具,因此,如何让使用者可以再 ...

  6. 【Reporting Services 报表开发】— 数据表存储格式修改

    文本框 Format属性:日期:输入d(表示简易日期).2007/5/1 0:00:00   输入d之后 变成 2007/5/1 金额:输入C0(表示货币),系统会根据设定值产生对应的货币符号,至于0 ...

  7. 配置SQL Server 2008 R2 Reporting Services

    记录如何在本地配置SQL Server 2008 R2 Reporting Services,笔者环境为Windows 7 64位 + SQL Server 2008 R2 一.准备工作 其实准备工作 ...

  8. [翻译]初识SQL Server 2005 Reporting Services Part 3

    原文:[翻译]初识SQL Server 2005 Reporting Services Part 3 这是关于SSRS文章中四部分的第三部分.Part 1提供了一个创建基本报表的递阶教程.Part 2 ...

  9. [翻译]初识SQL Server 2005 Reporting Services Part 4

    原文:[翻译]初识SQL Server 2005 Reporting Services Part 4 这一篇是关于SQL Server 2005 Reporting Services四篇文章中最后一篇 ...

随机推荐

  1. web项目中获取spring的bean对象

    Spring是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架,如何在程序中不通过注解的形式(@Resource.@Autowired)获取Spring配置的bean呢? Bean工厂(c ...

  2. 四大VDI客户端 总有一款适合你

    [TechTarget中国原创] 交付虚拟桌面时IT管理员必须要考虑到用户如何访问虚拟桌面,因为这会影响用户体验以及VDI部署最终的成败. IT可以转向简便的HTML5客户端,HTML 5客户端功能丰 ...

  3. android中Activity中的WindowManager与Window

    在做项目的过程中,需要实现Activity非全屏显示.窗口背景透明显示的效果. 在实现这些功能的过程中,涉及到Window与WindowManager两个类,经过查一些相关资料,了解二者之间的不同点如 ...

  4. (原)App源码

    序) 人生就像卫生纸,有事没事少扯 前言) 最近偶尔和一位极客大牛聊了一次,这个极客在汇编的造诣算是相当高,不过野路子出来看不起各种规矩,因此是适合做个自己蒙头研究技术的极客男,不适合大型团队,不适合 ...

  5. css3实现圆角边框渐变

    <button class="border">112233</button> 创建button .border{ position: relative; b ...

  6. Python namedtuple(命名元组)使用实例

    Python namedtuple(命名元组)使用实例 #!/usr/bin/python3 import collections MyTupleClass = collections.namedtu ...

  7. HDU 4661 Message Passing ( 树DP + 推公式 )

    参考了: http://www.cnblogs.com/zhsl/archive/2013/08/10/3250755.html http://blog.csdn.net/chaobaimingtia ...

  8. FOJ Problem 1016 无归之室

     Problem 1016 无归之室 Accept: 926    Submit: 7502Time Limit: 1000 mSec    Memory Limit : 32768 KB  Prob ...

  9. vue.$refs 的用法

    官网给出的解释是: 被用来给元素或子组件注册引用信息.引用信息将会注册在父组件的 $refs 对象上. 1.如果在普通的 DOM 元素上使用,引用指向的就是 DOM 元素; 2.如果用在子组件上,引用 ...

  10. spring in action 学习十一:property placeholder Xml方式实现避免注入外部属性硬代码化

    这里用到了placeholder特有的一个语言或者将表达形式:${},spring in action 描述如下: In spring wiring ,placeholder values are p ...