How to print the same report multiple times
ets say I have a letter for a customer made with FastReport.
The data comes from a MSSQL Database using queryparameters from reportparameters.
Now I want to print this letter to multiple Customer in one go.
Report report1 = new Report();
report1.Load("customerReport.frx");
report1.SetParameterValue("CustomerNr", 1);
Report report2 = new Report();
report2.Load("customerReport.frx");
report2.SetParameterValue("CustomerNr", 2);
etc.
How is it possible to combine/merge these reports into one and print it?
FastReport.Net Professional 2021.2.12
MS SQL 2017
This discussion has been closed.
Comments
Hello!
To generate a batch of letters for a set of customers (CustomerNr) in a single run without wasting memory on dozens of Report objects:
Use a single instance of Report, load the .frx file once, and call `report.Prepare(append: i > 0)` in a loop:
using var report = new Report(); report.Load(‘customerReport.frx’); for (int i = 0; i < customerIds.Length; i++) { report.SetParameterValue(‘CustomerNr’, customerIds[i]); report.Prepare(append: i > 0); } report.Export(new PDFExport(), ‘all_letters.pdf’); // or ShowPrepared()Alternatively (and even faster with a single SQL query): pass the list of customers via a table or master and place the letter in a child DataBand with StartNewPage = true and ResetPageNumber = true