RDLC报表一、RDLC介绍在VS2005之前,SQL Server Reporting Services中已经提供了一种被称为报表定义语言(Report Definition Language, RDL)的语言;在VS2005中,Microsoft提供了针对这种报表的设计器,并提供了在WinForm和WebForm中使用这种报表的能力。
RDL是Report Definition Language的缩写,C代表Client-side processing,凸显了它的客户端处理能力。
从SQL Server2005开始,微软提供了一个报表服务,即Reporting Service,利用该服务部署在服务器端的报表扩展名为rdl;而通过自主生成一些数据源,在本地展现出来的报表扩展名为rdlc,这种方式称之为Local Report。
二、如何开发下面是LocalReport的开发步骤,对于ServerReport还没有进行研究。
1.新建一个Web工程,新建一个aspx页面。
2.将ReportViewer控件添加到新建的aspx页面中。
(视图—工具箱—数据—ReportViewer)VS2005的数据控件中有名为ReportViewer的控件,用于展现报表。
该控件即可以展现rdl 报表也可以展现rdlc报表。
3.新建报表文件选中web工程—右键添加—新建项—选中报表(如下图)4.创建自己的报表布局(以柱状图为例)工具箱—图表—拖放到报表文件主体中选中图表—右键—图表类型—柱形图—简单柱形图可以直接修改属性调整布局,也可以利用工具栏中的布局按钮布局(包括水平居中、垂直居中、对齐网格等)5.创建数据集(选中web工程—右键添加—新建项—选中数据集)在新建的数据集面板右键—添加—TableAdapter配好数据库连接之后,下一步,有三种选择方式:使用sql语句、新建存储过程、使用现有存储过程。
根据需求选择一种配好自己的数据源。
6.设计报表(绑定数据集)打开建好的rdlc报表文件,双击添加的图表,会看到下图几个区域:工具栏—数据—显示数据源找到刚刚创建的数据集,将对应的字段方别拖放到数据字段区、类别字段区。
序列图例会根据数据字段自动生成。
现在可以修改图表的属性来修改柱形图的配色、X和Y轴的间距、示例序列的文字、网格线的显示样式等丰富的设置来设计自己的图表。
7.打开新建的aspx页面,在ReportViewer任务窗口中,选择刚才建立的rdlc文件如下图:选择报表中选择刚刚新建的ReportDemo.rdlc报表8.保存,编译如果配置的数据源为Sql语句方式,或者是不带参数的存储过程,此时就可以浏览一下aspx 页面,不用写一句代码就可以看到一个柱形图的报表。
三、动态生成报表实际项目开发中,我们多会采用带参数的存储过程来获得想要的数据,这样就能根据条件有选择的查看数据,而不是每次都查看全部,这就涉及到传递参数,动态生成报表。
可以在前台页面设置查询条件,然后获取条件后重新为报表绑定数据源。
后台代码如下:当然,也可以不配置数据集,而是在后台代码通过或者企业库等获得DataSet,然后再动态绑定到报表。
示例后台代码:四、控制报表自带的导出格式RDLC自带丰富的导出格式,导出的Excel文件格式非常完美,任何其它报表在这方面都不能与之比拟。
但是有时候我们不需要一些格式,比如不需要pdf等格式,怎么实现?另外:ReportViewer的一些属性可以控制工具条上一些按钮的显示ShowFindControls 是否显示查找ShowPageNavigationControls 是否显示分页ShowPrintButton 是否显示打印ShowRefreshButton 是否显示刷新ShowZoomControl 是否显示调整大小五、ReportViewer control - Choosing between LocalReport andServerReportThere was a similar discussion in this group previously. You can refer the same: /Forums/en/vsreportcontrols/thread/1b06b84a-3c6e-40f1-908e-07 e332a45a04 [ReportViewer control local and remote mode differences]Both Local Mode and Remote mode has their own advantages.. This is completely based on your requirement you can choose Local mode or remote mode of report processing.When to Use Local ProcessingLocal processing mode is recommended for applications that include small to medium-sized reports and datasets. Because all data and report processing is performed on the client, you might encounter performance degradation or memory limitations if you attempt to process large or complex reports and queries.Local processing mode is less scalable than remote processing and is intended for standalone applications that do not require a report server. Users who are familiar with server reports that run on a remote SQL Server Reporting Services report server should note the following differences: In remote processing mode, the report server both retrieves the data and processes the report, whereas in local processing mode, the ReportViewer control processes the report only, and the the host application must retrieve the data and supply it to the ReportViewer control.Client report definitions do not include query information.Report parameters in client report definitions (.rdlc) do not map to data source query parameters.There is no parameter input area for a client report definition that accepts values that are subsequently used in a queryWhen to Use Remote ProcessingServer-based reporting lets you centralize report storage and management, set policies and secure access to reports and folders, control how reports are processed and distributed, and standardize how reports are used in your business. Reporting Services can be installed in single-server, distributed, and clustered configurations. Consider using remote processing if your report has the following characteristics:Report will be accessed by many users.Report has a very complex query or contains a very large amount of data, resulting in system resource overload on the computer that hosts the application.Report is already published on a report server, and you want to include it an application that you create and deploy.Reference articles:/en-us/library/ms251704.aspx [Configuring ReportViewer for Local Processing]/en-us/library/ms252075(VS.80).aspx [Configuring ReportViewer for Remote Processing]Hope this helps!本地报表模式和远程模式各有各的优点,到底选择本地模式还是远程模式完全取决于你的需求。
何时选用Local Report?当应用中涉及到的报表较简单,处理的数据集较小时推荐使用Local Report,因为Local Report模式所有的数据和报表处理都在本地执行。
当处理数据量大、逻辑复杂的报表时就可能遇到性能下降和内存不足的问题。