Home > .net 2.0 > ActiveReports and Multi-report Reports

ActiveReports and Multi-report Reports

July 18, 2006

After a post to DataDynamic’s website about needing to run the SAME report multiple times (in a loop), then combining it into a single PDF, I was told that each had to be a separate report… and never heard back from their technical staff after that.

So, after a couple weeks away from it, I decided to tackle it again this morning.

Scenario:

1 three-page, logical report, 20 “subjects”, aka 60 pages that spools into a single PDF.

The gotcha?  You can’t Insert a report into a report, you must open it, spool each page of the report into the “master report,” close it, go to the next, rinse and repeat.

So, here’s the code… previously, you’d have an IList<int> of your PrimaryKeys, or whatever you’re looping through, a System.IO.Path.GetTempFileName that would generate a random file and name (then renamed the .tmp to .pdf).You COULD pregen a DataTable rather than SQL, but.. yeah.  Next revision.🙂

<code>

public void RunClass(List<int> primaryKey, string filepath, string connString) 

// Generate your pdfExporting object. 

DataDynamics.ActiveReports.Export.Pdf.PdfExport pdfDoc = new DataDynamics.ActiveReports.Export.Pdf.PdfExport(); 

// Generate the single report.  

Reporting.Reports.IndividualReport rpt = new Reporting.Reports.IndividualReport(); 

// Generate the “master report” that you’ll insert each single report into. 

Reporting.Reports.AllReports crpt = new Reporting.Reports.AllReports(); 

for (int i = 0; i < primaryKey.Count; i++) 

string sql = “select * from database where primaryKey = ‘” + primaryKey[i] + “‘”; 

rpt.DataSource = new DataDynamics.ActiveReports.DataSources.OleDbDataSource(); 

 ((DataDynamics.ActiveReports.DataSources.OleDbDataSource).rpt.DataSource).ConnectionString = connString; 

 ((DataDynamics.ActiveReports.DataSources.OleDbDataSource).rpt.DataSource).SQL = sql; 

// run the individual report 

rpt.Run(false); 

foreach (DataDynamics.ActiveReports.Document.Page p in rpt.Document.Pages) 

 // insert each report page into the master report. 

 crpt.Document.Pages.Insert(i, p); 

// generate the PDF of the master report.  

pdfDoc.Export(crpt.Document, filepath); 

}
</code>

From here, you would Reponse.Write the PDF back to the browser (if web) or your filepath would be a specified path (if a console application).

Hope this helps someone… something so simple… bleh.

Categories: .net 2.0
  1. JEFF
    December 30, 2008 at 8:35 pm

    Helped me a lot thanks!

  1. No trackbacks yet.
Comments are closed.
%d bloggers like this: