zoukankan      html  css  js  c++  java
  • Rdlc报表 数据汇总分组展示

    • 1.从工具箱拉出表或者矩阵(本次使用的是矩阵)

    • 2.选择需要的数据集,没有就新建一个数据集,名称自己起好,下面有用到

    •  3.将行组和行列显示出来(右击报表--试图=>)

    • 4.双击行组下的RowGroup组=>常规=>组表达式=>分组方式,点击FX 选择类别=>字段(DbSetName)=>双击右边的值(选择你要的分组依据),或者直接点击页面矩阵上行右上角的图标添加分组依据(第3步图)。
    • 5.右击行组--RowGroup组,添加组=>子组,同第3步一样 fx 之后的步骤

    6.如果在这个组下有其他数据要展示,右击你添加好的行组所在视图的文本框=>插入列=>组内部-右侧(位置左右自己挑)

                                  7.后台代码

    var list=XXX,在数据层拿到T-SQL数据

    直接输出为PDF下载到本地

    excel格式: 

      var bytes = viewer.LocalReport.Render("Pdf")中把 “PDF”替换”EXCEL“;

          Response.ContentEncoding = Encoding.GetEncoding("GB2312"); 把 “GB2312”替换"application/vnd.ms-excel";
                  

     1   protected void Page_Load(object sender, EventArgs e)
     2         {
     3 
     4             if (IsPostBack) return;
     5            try
     6             {
     7              var list = new reportBL().report();
     8                 if (list.Count == 0)
     9                 {
    10                     Response.Write("没有信息!");
    11                     return;
    12                 }
    13                DataTable dt = ListToDataTable(list);
    14                 var viewer = new ReportViewer();
    15                 viewer.LocalReport.ReportPath = @"RptRdlcSampleForm.rdlc";
    16                 viewer.ProcessingMode = ProcessingMode.Local;
    17                //这里把建好的数据集的名称替换掉DataSetName
    18                 var rds = new ReportDataSource("DataSetName", dt);
    19                 viewer.LocalReport.EnableExternalImages = true;
    20                 viewer.LocalReport.DataSources.Clear();
    21                 viewer.LocalReport.DataSources.Add(rds);
    22                 viewer.LocalReport.EnableExternalImages = true;
    23                 errCode = 8;
    24                 viewer.LocalReport.Refresh();
    25                 var bytes = viewer.LocalReport.Render("Pdf");
    26                 errCode = 10;
    27                 Response.ContentType = "application/pdf";
    28                 //设定编码方式,若输出的excel有乱码,可优先从编码方面解决
    29                 Response.Charset = "gb2312";
    30                 //Response.Charset = "utf-8";
    31                 Response.ContentEncoding = Encoding.GetEncoding("GB2312");
    32                 //关闭ViewState,此属性在Page中
    33                 EnableViewState = false;
    34                 //filenames是自定义的文件名
    35                 Response.AppendHeader("Content-Disposition", string.Format("attachment;filename={0}.pdf", DateTime.Now.ToString("yyyyMMddHHmmssffff")));
    36                 //content是步骤1的html,注意是string类型
    37                 Response.BinaryWrite(bytes);
    38                 Response.End();
    39 
    40 
    41             }
    42             catch (Exception ex)
    43             {
    44 
    45                 Response.Write(ex.Message + ":" + errCode);
    46             }
    47 
    48         }
    49         public static DataTable ListToDataTable<T>(IList<T> list, params string[] propertyName)
    50         {
    51             var propertyNameList = new List<string>();
    52             if (propertyName != null)
    53                 propertyNameList.AddRange(propertyName);
    54             var result = new DataTable();
    55             if (list.Count > 0)
    56             {
    57                 PropertyInfo[] propertys = list[0].GetType().GetProperties();
    58                 foreach (PropertyInfo pi in propertys)
    59                 {
    60                     if (propertyNameList.Count == 0)
    61                     {
    62                         DataColumn dc = new DataColumn();
    63                         dc.AllowDBNull = true;
    64                         dc.ColumnName = pi.Name;
    65                         dc.DataType = pi.PropertyType;
    66                         result.Columns.Add(dc);
    67                     }
    68                     else
    69                     {
    70                         if (propertyNameList.Contains(pi.Name))
    71                             result.Columns.Add(pi.Name, pi.PropertyType);
    72                     }
    73                 }
    74 
    75                 for (var i = 0; i < list.Count; i++)
    76                 {
    77                     var tempList = new ArrayList();
    78                     foreach (PropertyInfo pi in propertys)
    79                     {
    80                         if (propertyNameList.Count == 0)
    81                         {
    82                             object obj = pi.GetValue(list[i], null);
    83                             tempList.Add(obj);
    84                         }
    85                         else
    86                         {
    87                             if (propertyNameList.Contains(pi.Name))
    88                             {
    89                                 var obj = pi.GetValue(list[i], null);
    90                                 tempList.Add(obj);
    91                             }
    92                         }
    93                     }
    94                     object[] array = tempList.ToArray();
    95                     result.LoadDataRow(array, true);
    96                 }
    97             }
    98             return result;
    99         }
    View Code

     

     

  • 相关阅读:
    权限管理系统(五):RBAC新解,基于资源的权限管理
    HTTP报文头Accept和Content-Type总结
    Spring Security教程(七):RememberMe功能
    Spring Security教程(六):自定义过滤器进行认证处理
    权限管理系统(三):自定义开发一套权限管理系统
    Spring Security教程(五):自定义过滤器从数据库从获取资源信息
    Spring Security教程(八):用户认证流程源码详解
    Spring Security教程(四):自定义登录页
    Spring Security教程(三):自定义表结构
    golang 做了个mutex与atomic性能测试
  • 原文地址:https://www.cnblogs.com/zhuzy/p/5523471.html
Copyright © 2011-2022 走看看