您可以将多个主页和 RDL 报告合并或合并为一个报告。合并是通过使用 ReportCombiner 类执行的,该类将报表添加为子报表。报表将按添加顺序依次合并。要正确合并报表,应使用具有相同布局的报表:对于页面报表,您需要为所有报表设置相等的边距;对于 RDL 报表,您需要为所有报表设置相等的边距和宽度。
可以使用 BuildReport 方法来利用 PageReport 类的所有功能。您还可以在合并时插入分页符并指定两个报表之间的间距。默认情况下,报表之间将添加 1 英寸的间隙。
以下代码合并了三个报表。您需要将 GrapeCity.ActiveReports.Core.Rendering 程序集添加到项目中。该代码还以 PDF 格式导出合并的报表,因此您需要添加 GrapeCity.ActiveReports.Export.Pdf 程序集。
| Vb.Net |
Dim combiner = New GrapeCity.ActiveReports.ReportsCore.Tools.ReportCombiner() Dim r1 = New GrapeCity.ActiveReports.PageReport() r1.Load(New System.IO.FileInfo("c:\temp\Report1.rdlx")) Dim r2 = New GrapeCity.ActiveReports.PageReport() r2.Load(New System.IO.FileInfo("c:\temp\Report2.rdlx")) Dim r3 = New GrapeCity.ActiveReports.PageReport() r3.Load(New System.IO.FileInfo("c:\temp\Report3.rdlx")) combiner.AddReport(r1) Dim options = New GrapeCity.ActiveReports.ReportsCore.Tools.LocationOptions options.Gap = "5in" 'adds a 5 inch gap from the first report. By default this gap is 1 inch. options.PageBreakBefore = True 'adds a page break. combiner.AddReport(r2, options) combiner.AddReport(r3) 'PDF Rendering extension Dim pdfRe = New GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension() Dim provider = New GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(New System.IO.DirectoryInfo("c:\temp\"), "CombinedReport") Viewer1.LoadDocument(combiner.BuildReport().Document) 'load combined report in viewer combiner.BuildReport().Document.Render(pdfRe, provider) 'export combined report in PDF format |
| C# |
var combiner = new GrapeCity.ActiveReports.ReportsCore.Tools.ReportCombiner(); var r1 = new GrapeCity.ActiveReports.PageReport(); r1.Load(new System.IO.FileInfo(@"c:\temp\Report1.rdlx")); var r2 = new GrapeCity.ActiveReports.PageReport(); r2.Load(new System.IO.FileInfo(@"c:\temp\Report2.rdlx")); var r3 = new GrapeCity.ActiveReports.PageReport(); r3.Load(new System.IO.FileInfo(@"c:\temp\Report3.rdlx")); combiner.AddReport(r1); combiner.AddReport(r2, new LocationOptions() { PageBreakBefore = true, Gap = "5in" }); //adds second report after a page break and a 5 inch gap from the first report. By default this gap is 1 inch. combiner.AddReport(r3); //PDF Rendering extension var pdfRe = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension(); var provider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(new System.IO.DirectoryInfo(@"c:\temp\"), "CombinedReport"); viewer1.LoadDocument(combiner.BuildReport().Document); //load combined report in viewer combiner.BuildReport().Document.Render(pdfRe, provider); //export combined report in PDF format |
可以通过多种方式修改合并的报告,如下所述。
在特定索引处添加报表
如果要在第一个报告 r4 之后添加报表
r1,请使用具有索引“1”的以下代码:
| Vb.Net |
combiner.Insert(1, r4, New GrapeCity.ActiveReports.ReportsCore.Tools.LocationOptions()) report = combiner.BuildReport() |
| C# |
combiner.Insert(1, r4, new LocationOptions()); report = combiner.BuildReport(); |
添加报告列表
| Vb.Net |
Dim reports As IEnumerable(Of GrapeCity.ActiveReports.PageReport) = {r1, r2, r3, r4} combiner.AddRange(reports, New GrapeCity.ActiveReports.ReportsCore.Tools.LocationOptions()) report = combiner.BuildReport() |
| C# |
combiner.AddRange(new PageReport[] {r1, r2, r3, r4 }, new LocationOptions()) report = combiner.BuildReport(); |
删除报表
如果要删除排在第一位的报表,请使用以下带有索引“0”的代码:
Vb.Net
combiner.RemoveAt(0)
report = combiner.BuildReport()
| C# |
|
同样,如果要删除第二个位置的报告,请使用索引“1”。
如果要删除报表 r2 的所有实例,请使用以下代码:
| Vb.Net |
combiner.RemoveAll(r2) report = combiner.BuildReport() |
| C# |
combiner.RemoveAll(r2); report = combiner.BuildReport(); |
注: