最近一个项目中,涉及到很多报表的开发,以前对水晶报表搞得比较熟,但它的庞大与其它诸多功能限制,特别是发布与部置时面临的困难,实在让人无法忍受(应该很少有人买得起正版吧),决定试一下MS Reporting Services,当然在这里只使用Local Report,对微软的Reporting Services进行了一番了解,蜡人张(http://www.cnblogs.com/waxdoll/category/49402.html)老兄这里有很多很好的学习材料,我也是从蜡人兄那里对自定义报表的研究得出以下部分修正的Demo.
    对于微软提供的ReportView控件,大家都知道,不能在其中对报表的边距等进行自定义,其工具条也是根本上无法自定义控制的,每次用户打印时,都必须对页面,边距等进行调整,对用户来说,这可能是一件无法忍受的事情,这或者是为满足Reporting Services报表而这样设计的.
对蜡人张老兄提供的例子做了一些改进,主要修正以下几点:
1,修正无法使用网络打印机进行打印的问题;
2,报表使用钳入式资源加载方式;
3,提取成一用户控件ReportView,更方便于开发人员将其整合到自己的项目中

Demo文件结构:
MS Local Report

自定义报表控件ReportView源码分如下:

  1MS Local Reportusing System;
  2MS Local Reportusing System.Collections.Generic;
  3MS Local Reportusing System.ComponentModel;
  4MS Local Reportusing System.Drawing;
  5MS Local Reportusing System.Data;
  6MS Local Reportusing System.Text;
  7MS Local Reportusing System.Windows.Forms;
  8MS Local Reportusing System.IO;
  9MS Local Reportusing Microsoft.Reporting.WinForms;
 10MS Local Reportnamespace LocalReportDemo.Report
 11

报表宿主窗口加载报表与数据源的方法:
1MS Local Report DataSet ds = new DataSet();
2MS Local Report            ds.ReadXml(Application.StartupPath + @"\DataSource.xml");
3MS Local Report            this.reportViewer1.MainDataSet = ds;//报表主数据源
4MS Local Report            this.reportViewer1.MainDataSourceName = "ReportDemoDataSet_ReportDemoTable";//数据源名称
5MS Local Report            this.reportViewer1.MReportEmbeddedResource = "LocalReportDemo.ReportDemo.rdlc";//钳入资源的报表路径
6MS Local Report            this.reportViewer1.ReportName = "ReportDemo";//报表名称
7MS Local Report            this.reportViewer1.BindReport();//加载挷定报表

数据源名称如下图所示:
MS Local Report

其中钳入资源的报表路径中,LocalReportDemo为报表钳入的程序集名称

报表格式配置文件ReportSettings.xml:
 1MS Local Report<?xml version="1.0" standalone="yes"?>
 2MS Local Report<ReportSettings>
 3MS Local Report  <ReportDemo>
 4MS Local Report    <ReportName>ReportDemo</ReportName>
 5MS Local Report    <PrinterName>Microsoft Office Document Image Writer</PrinterName>
 6MS Local Report    <PaperName>A4</PaperName>
 7MS Local Report    <PageWidth>21.01</PageWidth>
 8MS Local Report    <PageHeight>29.69</PageHeight>
 9MS Local Report    <MarginTop>0.5</MarginTop>
10MS Local Report    <MarginBottom>0.2</MarginBottom>
11MS Local Report    <MarginLeft>2.3</MarginLeft>
12MS Local Report    <MarginRight>0.2</MarginRight>
13MS Local Report    <Orientation>Z</Orientation>
14MS Local Report  </ReportDemo>
15MS Local Report</ReportSettings>

此Demo运行效果:
MS Local Report

打印预览:
MS Local Report

有任何问题欢迎在此提出,大家共同讨论解决

此Demo完整代码下载:
/Files/mshwu/LocalReportDemo.rar

相关文章:

  • 2021-06-26
  • 2021-05-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-22
  • 2021-07-21
  • 2021-10-21
  • 2021-04-24
  • 2021-05-30
相关资源
相似解决方案