Sometimes your work needs one and the same report, but with a few changes. For example, different headers for different departments. So, for example, a user of the ActiveReports report generator wants to create such a report:
Let's implement such a report in FastReport .NET. You can generate the same report and pass it different parameters for the header. But if you want to receive similar reports with different headlines in one report, you can do otherwise. We can duplicate the pages of the original report, and then modify the headers in these pages. The easiest way is to show on the report with one page.
The report will have a parameter that lists the number of titles that you want to display in this report through a comma. In the report script, we duplicate the page based on the number of values in the setting, then replace the text in the headlines of the new pages to the desired.
In this way, we can form pages with different titles depending on the numbers that are transferred. However, there is one difficulty. You'll have to manually calculate the number of the text object in which you want to replace the text. For example, there are 9 text objects in my report. The first is the headline. So the tenth will also be the headline, but on the new page. If you add another 9 to 10, we get the title number on the third page and so on.
It will become more clear when you the script code:
Let's take a closer look at this script. We used the StartReport event at the Report object. In the event handler, we will manipulate the report pages. The report already has one page developed - in fact it is a ready-made "combat" report, on the basis of which we want to make several, but with different headlines.
First of all, we parse a report parameter. As mentioned earlier, the parameter is passed in sequence identifier patterns that we want to display. Identificators are separated by commas. Next, iterate loop parameter IDs obtained from the report. For each of them creates a page based on an existing text object is calculated with a header. Depending on the text object header template identifier is set. Once we have established a "pack" the necessary pages, remove the first page of the sample.
As a result, we get multiple reports within a single. A controlled number of these reports pages may be passing in the report parameter value - the desired combination of identifiers or headers.