通过 ActiveReports 实现 Web 系统的报表直接打印操作

发布时间:2013/10/10 00:10 发布者:jian

返回博客中心

在一些系统中,并不需要先进行预览操作,而是直接打印报表数据。比如在电子商务系统中客户订单打印功能,操作人员在填写必要的用户数据之后,点击单页按钮便可直接打印客户订单。本文就结合 ActiveReports 来实现 Web 系统中直接打印报表的需求。在 ActiveReports 中实现 Web 客户端直接打印操作,主要是借助 ActiveReports 所提供的 Flash 类型的 WebViewer 控件,该控件可以在加载报表之后直接打印。

首先,创建一个 Web 应用程序,添加 ActiveReports 报表到工程中,并在 aspx 页面中添加 WebViewer 控件,然后设置 WebViewer 的 ViewerType 为 FlashViewer。

然后,在打印按钮单击事件的后台代码中设置 WebViewer1.FlashViewerOptions.PrintOptions.StartPrint = true;,以实现加载报表之后直接打印。

    protected void Button2_Click(object sender, EventArgs e)
    {
        GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath(@"Reports\rptInvoice.rdlx")));
        // 获取用户输入数据,并传递到报表中。
        report.Report.ReportParameters[1].DefaultValue.Values.Add(TextBox1.Text);
        report.Report.ReportParameters[2].DefaultValue.Values.Add(TextBox2.Text);
        report.Report.ReportParameters[3].DefaultValue.Values.Add(TextBox3.Text);
        report.Report.ReportParameters[4].DefaultValue.Values.Add(TextBox4.Text);
        report.Report.ReportParameters[5].DefaultValue.Values.Add(TextBox5.Text);
        report.Report.ReportParameters[6].DefaultValue.Values.Add(TextBox6.Text);
        WebViewer1.Report = report;
        WebViewer1.FlashViewerOptions.PrintOptions.StartPrint = true;
        WebViewer1.Visible = true;
        WebViewer1.Width = 0;
        WebViewer1.Height = 0;
    }

预览打印运行截图:

ActiveReports Web 预览打印截图

直接打印运行截图:

ActiveReports Web 直接打印截图

源码下载:VS2010 + ActiveReports 7

 


关于葡萄城

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

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