ActiveReports Flash Viewer 提供了灵活的定制接口,我们可以向其中添加自定义按钮用于实现自定义功能。导出报表到客户端也是比较常见的使用场景,本篇文章将阐述如何实现以上功能。
下面分布阐述:
//设置显示语言版本为中文
this.WebViewer1.FlashViewerOptions.ResourceLocale = "zh_CN";
//创建自定义工具条按钮
ToolButton btnPDF = Tool.CreateButton("PDF");
btnPDF.ToolTip = "导出到 PDF";
btnPDF.Caption = "导出到 PDF";
//设置点击按钮执行的服务
btnPDF.ClickNavigateTo = "ARExport.ashx?exporttype=PDF";
//添加按钮到 FlashViewer 中
this.WebViewer1.FlashViewerToolBar.Tools.Add(btnPDF);
ToolButton btnWord = Tool.CreateButton("Word");
btnWord.ToolTip = "导出到 Word";
btnWord.Caption = "导出到 Word";
btnWord.ClickNavigateTo = "ARExport.ashx?exporttype=Word";
this.WebViewer1.FlashViewerToolBar.Tools.Add(btnWord);
ToolButton btnExcel = Tool.CreateButton("Excel");
btnExcel.ToolTip = "导出到 Excel";
btnExcel.Caption = "导出到 Excel";
btnExcel.ClickNavigateTo = "ARExport.ashx?exporttype=Excel";
this.WebViewer1.FlashViewerToolBar.Tools.Add(btnExcel);
var key = context.Request["exporttype"];
switch (key)
{
case "PDF":
ExportPdf(context, pr);
break;
case "Word":
ExportWord(context, pr);
break;
case "Excel":
ExportExcel(context, pr);
break;
}
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;test.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;test.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();
}
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;test.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();
}
文章转自:葡萄城控件产品博客,http://blog.gcpowertools.com.cn
原文地址:http://blog.gcpowertools.com.cn/post/2014/11/13/customize_flashviewer.aspx