Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »


1. 新建 Winform项目



2. 添加新项-选择区域报表,保证必要dll及 Package 都可以安装在项目中(后面不需要可删除),再添加自己的报表文件RDL或页面报表。



3. 将 Viewer 拖拽到 Winfrom窗体中

安装完成区域报表后,工具箱会出现 ActiveReports 14 的节点,下方会有Viewer控件

4. 选中 Viewer 后在属性窗口中 Dock属性设置为 Fill

5. 双击窗体,创建Form_Load事件的事件处理方法。


6. 在 Form_Load 事件中,添加如下所示代码,以运行报表并将其显示在查看器。





Visual Basic.NET中的代码

  • 加载页面/RDL报表

将以下 Visual Basic. NET 代码粘贴到 Form_Load 中

Dim file_name As String = "..\..\PageReport1.rdlx"

Dim pageReport As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(file_name))

Dim pageDocument As New GrapeCity.ActiveReports.Document.PageDocument(pageReport)

Viewer1.LoadDocument(pageDocument)

  • 加载基于代码的区域报表

将以下 Visual Basic. NET 代码粘贴到 Form_Load 中

Dim sectionReport As New SectionReport1()

Viewer1.LoadDocument(sectionReport)


  • 加载基于模板的区域报表

    • Visual Basic. NET 代码粘贴到 Form_Load 中

Dim sectionReport As New GrapeCity.ActiveReports.SectionReport()

Dim xtr As New System.Xml.XmlTextReader("..\..\SectionReport1.rpx")

sectionReport.LoadLayout(xtr)

xtr.Close()

Viewer1.LoadDocument(sectionReport)


C#中的代码

  • 加载页面/RDL报表

将以下 C# 代码粘贴到 Form_Load 中

string file_name = @"..\..\PageReport1.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);


  • 加载基于代码的区域报表

将以下 C# 代码粘贴到 Form_Load 中

SectionReport1 sectionReport = new SectionReport1();

viewer1.LoadDocument(sectionReport);


  • 加载基于模板的区域报表

将以下 C# 代码粘贴到 Form_Load 中

GrapeCity.ActiveReports.SectionReport sectionReport = new GrapeCity.ActiveReports.SectionReport();

System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(@"..\..\SectionReport1.rpx");

sectionReport.LoadLayout(xtr);

xtr.Close();

viewer1.LoadDocument(sectionReport);

注意

如果报找不到报表文件时候,需要将报表文件的属性设置为,始终复制:

  • No labels