logo
small logo
  • Products
  • Buy
  • Support
  • About
  • Customer panel Support
    • en
    • de
    • JP
    • ZH
  • Home
  • /
  • Articles
  • /
  • Making the same report pages with different headers
  • Report generators family FastReport brief review

    March 23, 2020

    Without reporting it is impossible to carry on business in any sphere of life. Bureaucracy

    read more
  • How to import a report from StimulSoft into FastReport .NET

    July 6, 2022

    Import of StimulSoft reports is now available with the 2022.2.13 release. To use it,

    read more
  • How to print one page of the report in several copies

    February 24, 2022

    If you need to print particular pages of the report in several copies, we

    read more
  • How to display multiple reports on single Blazor page

    July 12, 2022

    Often, our users need to display two reports with different data on the same

    read more
  • Import of reports Crystal Reports to FastReport .NET

    September 1, 2021

    Often, the developers of report generators create their formats to store templates. For example,

    read more

Making the same report pages with different headers

January 8, 2020

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:

For example, the user select copies for the customer and for administration department.

The application creates the same report but each one has a label in the header that shows something like "Copy for the customer", "Copy for the administration department".

After, the application has to show the two pages in a form viewer.

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
private void _StartReport(object sender, EventArgs e)
 {
 //Parse parameter
 string parameter = (string)Report.GetParameterValue("Parameter");
 string[] arr = parameter.Split(',');
 
 //Number of text obj that is header
 int step = 10;
 
 foreach (string item in arr)
 {
 ReportPage newPage = new ReportPage();
 newPage.AssignAll(Page1);
 Report.Pages.Add(newPage);
 newPage.CreateUniqueName();
 foreach (object obj in newPage.AllObjects)
 {
 if (obj is Base)
 { 
 (obj as Base).CreateUniqueName();
 }
 }
 TextObject txt = Report.FindObject("Text"+ step.ToString()) as TextObject;
 switch (item)
 {
 case "1":
 txt.Text = "Header 1"; 
 break;
 case "2":
 txt.Text = "Header 2"; 
 break;
 case "3":
 txt.Text = "Header 3"; 
 break;
 }
 step = step + 9;
 }
 Report.Pages.Remove(Page1);
 }

 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.

 

about product buy
avatar
Dmitriy Fedyashov
Technical Writer
Fast Reports Team: Dmitriy Fedyashov - Technical Writer at Fast Reports
.NET FastReport Report

Add comment
logo
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314
  • Buy
  • Download
  • Documentation
  • Testimonials
  • How to uninstall
  • FAQ
  • Tutorial Video
  • Forum
  • Support SLA
  • Articles
  • Our News
  • Press about us
  • Resellers
  • Extended licensing
  • Contact us

© 1998-2023 by Fast Reports Inc.

  • Privacy Policy

Trustpilot