为区域报表导出为PDF添加进度显示功能

发布时间:2012/11/29 00:11 发布者:葡萄城产品团队

返回博客中心

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

PDFLoadIndicator_C#.zip (616.32 kb)


关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网