关于ActiveReports导出PDF,exce,word的问题。
哪位大哥能帮个忙。
我现在想做一个通用的导出功能。并且多个报表可以调用。
首先我是
得出工具条的代码我是这样写的。
- /// <summary>
- /// 输出报表工具
- /// </summary>
- /// <param name="rdlxurl"></param>
- /// <param name="WebViewers"></param>
- public void sToolTip(string rdlxurl, GrapeCity.ActiveReports.Web.WebViewer WebViewers, string url)
- {
- //设置显示语言版本为中文
- WebViewers.FlashViewerOptions.ResourceLocale = "zh_CN";
- //创建自定义工具条按钮
- ToolButton btnPDF = Tool.CreateButton("PDF");
- btnPDF.ToolTip = "导出到 PDF";
- btnPDF.Caption = "导出到 PDF";
- //设置点击按钮执行的服务
- btnPDF.ClickNavigateTo = url + "/SubSystem/ActiveReports/ARExport.ashx?exporttype=PDF&PageReportFile=" + rdlxurl;
- //添加按钮到 FlashViewer 中
- WebViewers.FlashViewerToolBar.Tools.Add(btnPDF);
- ToolButton btnWord = Tool.CreateButton("Word");
- btnWord.ToolTip = "导出到 Word";
- btnWord.Caption = "导出到 Word";
- btnWord.ClickNavigateTo = url + "/SubSystem/ActiveReports/ARExport.ashx?exporttype=Word&PageReportFile=" + rdlxurl;
- WebViewers.FlashViewerToolBar.Tools.Add(btnWord);
- ToolButton btnExcel = Tool.CreateButton("Excel");
- btnExcel.ToolTip = "导出到 Excel";
- btnExcel.Caption = "导出到 Excel";
- btnExcel.ClickNavigateTo = url + "/SubSystem/ActiveReports/ARExport.ashx?exporttype=Excel&PageReportFile=" + rdlxurl;
- WebViewers.FlashViewerToolBar.Tools.Add(btnExcel);
- }
复制代码
调用实现如下:
- ;
-
- GrapeCity.ActiveReports.PageReport rpt2 = new GrapeCity.ActiveReports.PageReport();
- string rdlxurl = "~/SubSystem/ActiveReports/IOT_Billhead/Active_IOT_Billhead.rdlx";
- rpt2.Load(new System.IO.FileInfo(Server.MapPath(rdlxurl)));
- //生成PDF,EXCEL,WORD 导出按钮
- sToolTip(rdlxurl, this.WebViewer1, HttpContext.Current.Request.Url.ToString().Substring(0, HttpContext.Current.Request.Url.ToString().IndexOf("/SubSystem")));//主要是这一句调佣出工具条
- WebViewer1.Report = rpt2;
复制代码
这样得出工具条,然后点调整即可导出,在调整的页面传相关的参数进去进行读取数据。
然后再地址栏传参数到指定页面进行输出对应的导出文件
- public void ProcessRequest(HttpContext context)
- {
- context.Response.ContentType = "text/html";
- var key = context.Request["exporttype"];
- var PageReportFile = context.Request["PageReportFile"];
- PageReport pr = new PageReport(new System.IO.FileInfo(context.Server.MapPath(PageReportFile)));
- switch (key)
- {
- case "PDF":
- ExportPdf(context, pr);
- break;
- case "Word":
- ExportWord(context, pr);
- break;
- case "Excel":
- ExportExcel(context, pr);
- break;
- }
- }
- private void ExportExcel(HttpContext context, PageReport _reportDef)
- {
- context.Response.ContentType = "application/excel";
- context.Response.Clear();
- context.Response.AddHeader("content-disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls");
- XlsExport xls = new XlsExport();
- System.IO.MemoryStream memStream = new System.IO.MemoryStream();
- xls.FileFormat = FileFormat.Xlsx;
- xls.Export(_reportDef.Document, memStream);
- context.Response.BinaryWrite(memStream.ToArray());
- context.Response.End();
- }
- private void ExportWord(HttpContext context, PageReport pr)
- {
- context.Response.ContentType = "application/msword";
- context.Response.Clear();
- context.Response.HeaderEncoding = System.Text.Encoding.Default;
- context.Response.AddHeader("content-disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".doc");
- var word = new RtfExport();
- var memStream = new System.IO.MemoryStream();
- word.Export(pr.Document, memStream);
- context.Response.BinaryWrite(memStream.ToArray());
- context.Response.End();
- }
- private void ExportPdf(HttpContext context, PageReport pr)
- {
- context.Response.ContentType = "application/pdf";
- context.Response.Clear();
- context.Response.HeaderEncoding = System.Text.Encoding.Default;
- context.Response.AddHeader("content-disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".pdf");
- var pdf = new PdfExport();
- var memStream = new System.IO.MemoryStream();
- pdf.Export(pr.Document, memStream);
- context.Response.BinaryWrite(memStream.ToArray());
- context.Response.Flush();
- context.Response.End();
- }
复制代码
以上是我的导出代码,请问怎么样赋值,或者是怎么样完善它能导出。 |