为什么[C]在当前市场中的需求如此旺盛?
- 内容介绍
- 文章标签
- 相关推荐
本文共计563个文字,预计阅读时间需要3分钟。
[SQL Server] 通过ReportViewer将报表另存为文件 + 以Reporting Service作为系统的报表方案,各种位应都会需要将报表转换成实例文档的机制,在本文中,我们可以直接在Report操作画面上进行。
[SQL Server]透过ReportViewer将报表另存成文件
以Reporting Service作为系统的报表方案的各位应该都会有需要将报表转成实例档的机会,在面的文章中我们有看到可以直接在Report操作画面上进行报表导出的动作,但这样的动作毕竟需要开启报表档,再按下导出,如果今天我们希望程序执行到一半,可以自动将报表转成文件后导出到Client端,又或者当成Mail的附件直接寄送给主管当成周报表或者月报表的参考数据,岂不方便的多。
Reporting Service的报表布署有两种,一种是布署到ReportServer上,可享有ReportServer的报表管理与安全性机制;另一种就是布署在我们站台下,直接透过ReportViewer指定好报表档与数据来源,在网页上做呈现,本身不具备报表管理的功能,不过这种方式对网站的布署较为简便,因为可连同网站一起布署。
本文主要先提ReportViewer如何指定好rdlc与数据来源后,将报表丢到Client去,我们看以下很简单的Code:
///
支持PDF、Excel、Image等格式
public void ExportReport(string pType)
{
//取得数据
DBCommand tCommand = new DBCommand(@"server=gipi;database=TEST;uid=sa;pwd=sa");
DataTable tDt = tCommand.Query("Select * from TestTable");
//清除数据来源
ReportViewer1.LocalReport.DataSources.Clear();
//指定报表档路径
ReportViewer1.LocalReport.ReportPath = "Report1.rdlc";
//设定数据来源
ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("MyData", tDt));
ReportViewer1.LocalReport.Refresh();
Microsoft.Reporting.WebForms.Warning[] tWarnings;
string[] tStreamids;
string tMimeType;
string tEncoding;
string tExtension;
//调用ReportViewer.LoadReport的Render function,将数据转成想要转换的格式,并产生成Byte数据
byte[] tBytes = ReportViewer1.LocalReport.Render(pType, null, out tMimeType, out tEncoding, out tExtension, out tStreamids, out tWarnings);
//将Byte内容写到Client
Response.Clear();
Response.ContentType = tMimeType;
Response.AppendHeader("Content-Disposition", String.Format("attachment; filename=report.{0}", tExtension));
Response.BinaryWrite(tBytes);
Response.End();
}
游舒帆 (gipi)
探索原力Co-founder,曾任TutorABC协理与鼎新电脑总监,并曾获选两届微软最有价值专家 ( MVP ),离开职场后创办探索原力,致力于协助青少年培养面对未来的能力。认为教育与组织育才其实息息相关,都是在为未来储备能量,2018年起成立为期一年的专题课程《职涯跃升的关键24堂课》,为培养中国台湾未来的领袖而努力。
原文:大专栏 [C#]透过ReportViewer将报表另存成文件
本文共计563个文字,预计阅读时间需要3分钟。
[SQL Server] 通过ReportViewer将报表另存为文件 + 以Reporting Service作为系统的报表方案,各种位应都会需要将报表转换成实例文档的机制,在本文中,我们可以直接在Report操作画面上进行。
[SQL Server]透过ReportViewer将报表另存成文件
以Reporting Service作为系统的报表方案的各位应该都会有需要将报表转成实例档的机会,在面的文章中我们有看到可以直接在Report操作画面上进行报表导出的动作,但这样的动作毕竟需要开启报表档,再按下导出,如果今天我们希望程序执行到一半,可以自动将报表转成文件后导出到Client端,又或者当成Mail的附件直接寄送给主管当成周报表或者月报表的参考数据,岂不方便的多。
Reporting Service的报表布署有两种,一种是布署到ReportServer上,可享有ReportServer的报表管理与安全性机制;另一种就是布署在我们站台下,直接透过ReportViewer指定好报表档与数据来源,在网页上做呈现,本身不具备报表管理的功能,不过这种方式对网站的布署较为简便,因为可连同网站一起布署。
本文主要先提ReportViewer如何指定好rdlc与数据来源后,将报表丢到Client去,我们看以下很简单的Code:
///
支持PDF、Excel、Image等格式
public void ExportReport(string pType)
{
//取得数据
DBCommand tCommand = new DBCommand(@"server=gipi;database=TEST;uid=sa;pwd=sa");
DataTable tDt = tCommand.Query("Select * from TestTable");
//清除数据来源
ReportViewer1.LocalReport.DataSources.Clear();
//指定报表档路径
ReportViewer1.LocalReport.ReportPath = "Report1.rdlc";
//设定数据来源
ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("MyData", tDt));
ReportViewer1.LocalReport.Refresh();
Microsoft.Reporting.WebForms.Warning[] tWarnings;
string[] tStreamids;
string tMimeType;
string tEncoding;
string tExtension;
//调用ReportViewer.LoadReport的Render function,将数据转成想要转换的格式,并产生成Byte数据
byte[] tBytes = ReportViewer1.LocalReport.Render(pType, null, out tMimeType, out tEncoding, out tExtension, out tStreamids, out tWarnings);
//将Byte内容写到Client
Response.Clear();
Response.ContentType = tMimeType;
Response.AppendHeader("Content-Disposition", String.Format("attachment; filename=report.{0}", tExtension));
Response.BinaryWrite(tBytes);
Response.End();
}
游舒帆 (gipi)
探索原力Co-founder,曾任TutorABC协理与鼎新电脑总监,并曾获选两届微软最有价值专家 ( MVP ),离开职场后创办探索原力,致力于协助青少年培养面对未来的能力。认为教育与组织育才其实息息相关,都是在为未来储备能量,2018年起成立为期一年的专题课程《职涯跃升的关键24堂课》,为培养中国台湾未来的领袖而努力。
原文:大专栏 [C#]透过ReportViewer将报表另存成文件

![为什么[C]在当前市场中的需求如此旺盛?](/imgrand/f6F3fP8B.webp)