在WPF系统中使用ActiveReports 7报表

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

返回博客中心

ActiveReports 7本身没有对WPF系统提供支持,不过我们可以通过WPF提供的WindowsFromHost控件来实现这一功能,通过WindowsFromHost 可以在WPF系统中使用WinForms平台的控件。所以,我们只需要将ActiveReports 7的Viewer控件通过WindowsFormHost进行宿主就可以在WPF中浏览ActiveReports 7开发出来的报表。

详细操作步骤如下:
1、在Visual Studio中创建一个WPF应用程序
2、在工程中添加一个ActiveReports 7 Section Report (code-based)类型的报表文件
3、在工程中添加一个ActiveReports 7 Page Report类型的报表文件
4、在XAML设计界面添加一个WindowsFormsHost控件
5、在XAML的后台代码中添加以下代码:

 
private void btnSectionRpt_Click(object sender, RoutedEventArgs e)
    {
        Invoice rpt = new Invoice();
          
        rpt.Run();
        viewer1.Document = rpt.Document;
        windowsFormsHost2.Child = viewer1;

    }

    private void btnPageReport_Click(object sender, RoutedEventArgs e)
    {
        string file_name = GetPath("Invoice1.rdlx");
        GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(file_name));
        GrapeCity.ActiveReports.Document.PageDocument pageDocument = new GrapeCity.ActiveReports.Document.PageDocument(pageReport);
        viewer1.LoadDocument(pageDocument);
        windowsFormsHost2.Child = viewer1;
    }
复制代码



源码下载:VS2010 + ActiveReports 7

WPFAR7_Csharp.zip (40.87 K, 下载次数:6)

关于葡萄城

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

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