.NET MVC报表的制作
来源:互联网 发布:办公软件下载网站 编辑:程序博客网 时间:2024/05/16 09:57
1,新建一个webForm页面,在该页面拖入ScriptManager和ReportViewer
2,在网站下面添加一个文件夹,例子(Reports文件夹)
3,在Reports文件夹中,选择新建项,添加一个“数据集”。。。后缀名是xsd的(例子。order.xsd)
4,在order.xsd拖放2个datatable控件,也就是相当于数据库的表。只要把想要的数据字段写进去,前提字段名字要和数据库表的列名一样
datatable的名字建议和数据库表的名字一致(例子:Order OrderDetail),最后还需要修改添加字段的数据类型,在属性处选择
5,在Reports文件夹中继续添加新建项,选择报表(Report1.rdlc)
7,在Report1.rdlc的工具箱中拖放控件,一般使用表和文本框
8,配置好数据集之后再webform窗体load里写代码
using Microsoft.Reporting.WebForms;
if (!IsPostBack) {
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/.rdlc的路径");
ReportDataSource ds = new ReportDataSource();
ds.Name = "";//dataset的名字
ds.Value = "";//可以是一个集合,也可以是对象
ReportViewer1.LocalReport.DataSources.Add(ds);
ReportViewer1.LocalReport.Refresh();
}
9,第八个是webForm的方式,那么要用MVC做报表的话,第八种方式就要改成这样
在控制器里面写一个action
public ActionResult Report(int id) {
LocalReport localReport = new LocalReport();//new 一个报表对象
localReport.ReportPath = Server.MapPath("~/Content/Reports/OrderReport.rdlc");//永远是报表
Order order = orderBiz.FetchByKey(id);
ReportDataSource rds1 = new ReportDataSource("Order", new List<Order> { order });
localReport.DataSources.Add(rds1);
ReportDataSource rds2 = new ReportDataSource("OrderDetail", order.Details);
localReport.DataSources.Add(rds2);
//下面是系统默认设置 直接复制就好
string reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
//The DeviceInfo settings should be changed based on the reportType
//http://msdn2.microsoft.com/en-us/library/ms155397.aspx
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>PDF</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0.5in</MarginTop>" +
" <MarginLeft>1in</MarginLeft>" +
" <MarginRight>1in</MarginRight>" +
" <MarginBottom>0.5in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
//Render the report
renderedBytes = localReport.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
//Response.AddHeader("content-disposition", "attachment; filename=NorthWindCustomers." + fileNameExtension);
return File(renderedBytes, mimeType);
}
2,在网站下面添加一个文件夹,例子(Reports文件夹)
3,在Reports文件夹中,选择新建项,添加一个“数据集”。。。后缀名是xsd的(例子。order.xsd)
4,在order.xsd拖放2个datatable控件,也就是相当于数据库的表。只要把想要的数据字段写进去,前提字段名字要和数据库表的列名一样
datatable的名字建议和数据库表的名字一致(例子:Order OrderDetail),最后还需要修改添加字段的数据类型,在属性处选择
5,在Reports文件夹中继续添加新建项,选择报表(Report1.rdlc)
7,在Report1.rdlc的工具箱中拖放控件,一般使用表和文本框
8,配置好数据集之后再webform窗体load里写代码
using Microsoft.Reporting.WebForms;
if (!IsPostBack) {
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/.rdlc的路径");
ReportDataSource ds = new ReportDataSource();
ds.Name = "";//dataset的名字
ds.Value = "";//可以是一个集合,也可以是对象
ReportViewer1.LocalReport.DataSources.Add(ds);
ReportViewer1.LocalReport.Refresh();
}
9,第八个是webForm的方式,那么要用MVC做报表的话,第八种方式就要改成这样
在控制器里面写一个action
public ActionResult Report(int id) {
LocalReport localReport = new LocalReport();//new 一个报表对象
localReport.ReportPath = Server.MapPath("~/Content/Reports/OrderReport.rdlc");//永远是报表
Order order = orderBiz.FetchByKey(id);
ReportDataSource rds1 = new ReportDataSource("Order", new List<Order> { order });
localReport.DataSources.Add(rds1);
ReportDataSource rds2 = new ReportDataSource("OrderDetail", order.Details);
localReport.DataSources.Add(rds2);
//下面是系统默认设置 直接复制就好
string reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
//The DeviceInfo settings should be changed based on the reportType
//http://msdn2.microsoft.com/en-us/library/ms155397.aspx
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>PDF</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0.5in</MarginTop>" +
" <MarginLeft>1in</MarginLeft>" +
" <MarginRight>1in</MarginRight>" +
" <MarginBottom>0.5in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
//Render the report
renderedBytes = localReport.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
//Response.AddHeader("content-disposition", "attachment; filename=NorthWindCustomers." + fileNameExtension);
return File(renderedBytes, mimeType);
}
- .NET MVC报表的制作
- 【.Net码农】RDLC 报表的制作(图文)
- ECharts制作报表模板--.NET
- VB.Net之旅—报表的制作(RDLC)
- .NET重构(七):VS报表的制作
- 水晶报表的制作
- 简单报表的制作
- 报表的制作
- 报表的制作
- winform报表的制作
- .net中mvc问卷制作
- 【SSRS报表】制作一张像样的报表
- 【菁菁报表】常规报表的制作过程
- 【菁菁报表]】交叉报表的制作过程
- VB.net报表制作-《过坎儿秘籍》
- .NET MVC下调用水晶报表
- 几款好用的报表制作软件!!!
- Spread 制作报表的用法
- 第8周任务4:关于圆的计算
- 二维码写入到数据库
- 使用一条INSERT语句完成多表插入
- 如来佛祖和玉皇大帝谁大!!唐僧为什么要取经《西游记》中的政治路
- android平台上调试2款camera sensor
- .NET MVC报表的制作
- 求半平面交学习模板
- JAVA BAE 问题总结
- Mysql函数INSTR、LOCATE、POSITION VS LIKE
- Java编程中“为了性能”需做的26件事
- 谢谢,那些伤害过我的人:伤感日志
- Spring中AOP的实现 (一)
- Myeclipse快捷键
- 怎么使float保留两位小数或多位小数