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

1. 新建 Winform项目

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

3. 打开工具栏,把Activereports v15的Viewer 拖拽到 Winfrom窗体中

如果工具栏没有ActivereportsV15对应的Viewer,需要添加对应的引用,具体可以如下操作

找到管理Nuget包

浏览找到Grapecity.Activereports.Design.Win  安装


打开工具栏,在工具栏就可以找到ActiveReports15,如果还是找不到还可以重置下工具栏,应该就可以找到了。如果还是找不到就在添加一个区域报表的文件在项目中,然后关闭整个项目再重新打开下就可以了。
重置工具箱:

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