ActiveReports 产品除了本身非常容易使用之外,他还提供了用户自定义的能力,比如我们今天要实现的在ASP.NET系统中“为区域报表导出为PDF添加进度显示功能”,我们将在报表导出过程中显示一个导出进度提示,下面是实际运行的截图:
要实现该功能,我们可以借助jQuery中的Ajax技术。我们将在按钮的单击事件中将报表导出为PDF文件,同时我们会将隐藏的进度提示图片变为可见状态,下面是按钮单击事件的处理代码:
<script language="javascript" type="text/javascript">
function btnExport_onclick() {
document.getElementById("Image1").style.visibility = "visible";
document.getElementById("btnExport").style.visibility = "hidden";
$.ajax({
url: 'WebForm1.aspx?command=pdfexport',
success: function (data) {
window.location = "WebForm1.aspx?command=showpdf";
}
});
}
</script>
在后台代码中我们将导出的 PDF 文档以文件流的显示存放到Session中,Window.Location通过一个带参数的URL地址来显示一个页面,下面是服务端的代码实现:
protected void Page_Load(object sender, EventArgs e)
{
if (Request["command"] != null)
{
if (Request["command"].ToString() == "pdfexport")
{
Session.Add("pdfdata", null);
System.IO.MemoryStream m_stream = new System.IO.MemoryStream();
NewActiveReport1 rpt = new NewActiveReport1();
rpt.Run();
GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport pdfExport1 = new GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport();
if (pdfExport1 == null)
{
pdfExport1 = new GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport();
}
pdfExport1.Export(rpt.Document, m_stream);
m_stream.Position = 0;
Session["pdfdata"] = m_stream;
}
if (Request["command"].ToString() == "showpdf")
{
if (Session["pdfdata"] != null)
{
System.IO.MemoryStream m_stream = new System.IO.MemoryStream();
m_stream = (System.IO.MemoryStream)Session["pdfdata"];
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline;filename=MyExport.pdf");
Response.BinaryWrite(m_stream.ToArray());
Response.End();
}
}
}
}
源码下载:VS2010 + ActiveReports 7
ActiveReports 报表控件| 下载试用
ActiveReports 是一款专注于 .NET 平台的报表控件,全面满足 HTML5 / WinForm / ASP.NET / ASP.NET MVC / WPF 等平台下报表设计和开发工作需求,作为专业的报表工具为全球超过 300,000 开发人员提供了全面的报表开发服务。
您对ActiveReports产品的任何技术问题,都有技术支持工程师提供1对1专业解答,点击此处即可发帖提问>>技术支持论坛
葡萄城热门产品
活字格
打通现有软件,快速定制面向未来的个性化应用

SpreadJS
可嵌入您系统的在线Excel的纯前端表格控件

Wyn商业智能
可与企业自有系统深度集成,增强数据分析的 BI 工具
