How to make report inheritance in FastReport.Net
January 29, 2021 by Dmitriy Fedyashov
When you are tasked with creating a large number of reports within one corporate style, you face the problem of duplicating some information, design styles in each report. As a rule, public reports (documents) in a company have the same header with name and contact information. Let's say you have 50 templates with the same header. But the company address changes and you need to open each template in the editor and correct it. But if there are not 50 templates, but 100, it's a real headache.
Avoiding this problem is helped by the inheritance mechanism, where you have a template that can be used in different reports. Changes to this template will appear in all inherited reports.
Report inheritance in FastReport.Net is organized as follows. You start by creating a so-called base report from which you inherit others. This report should contain a template with information common to all inherited reports. For example, it can be a header with the company details.
As mentioned above you can modify the base report template and then it will change in all the legacy reports. But you can also edit the information from the base report in the legacy report. These changes will only be saved in that particular report.
But what if you have modified an object from the base report in an inherited report and then modified the same object in the base report. In this case, the changes from the base report will be applied to that object, but only those that do not overlap with the changes in the legacy report. For example, if you change the font in a text object in an inherited report, and then set bold spelling for the same object in the base report, both changes will be applied. And if you change the font in the base report too, it will not be reflected in the legacy report, as it has already been changed in it.
It is also worth bearing in mind the restrictions on inheriting the report. You may not:
For example, it will contain a report template with the title:
Save this report with a name containing base, so that it is easier to find amongst the other report templates.
To create a legacy report you need to use the legacy report wizard. This is available either in the welcome screen or in the new report window (File->New):
The Legacy Report Wizard will only offer you one action - select the base report using the Open File dialog box. Select the base report you have previously created. All elements of the report have a padlock icon. This means that they are inherited from the base report.
Newly added objects will no longer have this icon. Add a data source to our report and place the fields on the "Data" band. For example, you can use the demo data source nwind.xml from FastReport.Net:
From the data source we select the Categories and Products tables. These tables are linked by key and so we can easily create a Master-Detail report:
As you can see, the added data fields and the Header and DetailData bends do not have a padlock icon. You can always tell the difference between the legacy report objects and the baseline report by this feature.
This way you can create a large number of reports in a single style, and then easily edit them all by changing only the basic template.Для просмотра ссылки Войдиили Зарегистрируйся
Для просмотра ссылки Войдиили Зарегистрируйся
January 29, 2021 by Dmitriy Fedyashov
When you are tasked with creating a large number of reports within one corporate style, you face the problem of duplicating some information, design styles in each report. As a rule, public reports (documents) in a company have the same header with name and contact information. Let's say you have 50 templates with the same header. But the company address changes and you need to open each template in the editor and correct it. But if there are not 50 templates, but 100, it's a real headache.
Avoiding this problem is helped by the inheritance mechanism, where you have a template that can be used in different reports. Changes to this template will appear in all inherited reports.
Report inheritance in FastReport.Net is organized as follows. You start by creating a so-called base report from which you inherit others. This report should contain a template with information common to all inherited reports. For example, it can be a header with the company details.
As mentioned above you can modify the base report template and then it will change in all the legacy reports. But you can also edit the information from the base report in the legacy report. These changes will only be saved in that particular report.
But what if you have modified an object from the base report in an inherited report and then modified the same object in the base report. In this case, the changes from the base report will be applied to that object, but only those that do not overlap with the changes in the legacy report. For example, if you change the font in a text object in an inherited report, and then set bold spelling for the same object in the base report, both changes will be applied. And if you change the font in the base report too, it will not be reflected in the legacy report, as it has already been changed in it.
It is also worth bearing in mind the restrictions on inheriting the report. You may not:
- Delete and move the base report, otherwise all inherited reports will be damaged.
- Inherit a report from another inherited report. That is, multiple inheritance is not allowed.
- Use script, report parameters, "Table" object and "Matrix" object in the base report.
For example, it will contain a report template with the title:
Save this report with a name containing base, so that it is easier to find amongst the other report templates.
To create a legacy report you need to use the legacy report wizard. This is available either in the welcome screen or in the new report window (File->New):
The Legacy Report Wizard will only offer you one action - select the base report using the Open File dialog box. Select the base report you have previously created. All elements of the report have a padlock icon. This means that they are inherited from the base report.
Newly added objects will no longer have this icon. Add a data source to our report and place the fields on the "Data" band. For example, you can use the demo data source nwind.xml from FastReport.Net:
From the data source we select the Categories and Products tables. These tables are linked by key and so we can easily create a Master-Detail report:
As you can see, the added data fields and the Header and DetailData bends do not have a padlock icon. You can always tell the difference between the legacy report objects and the baseline report by this feature.
This way you can create a large number of reports in a single style, and then easily edit them all by changing only the basic template.Для просмотра ссылки Войди
Для просмотра ссылки Войди