Merge reports

Hi.
I have 2 reports (two *.FR3 FILES).
Is it possible create one output from them? I need to merge these two reports in Delphi enviroment - in program code.
Thanks.

Comments

  • Anu de DeusAnu de Deus Hampshire, UK
    edited 12:24PM
  • edited January 2011
    Thank you for answer.
    I will put from there your code here:
    When I need to merge 2 different reports, I actually copy the TfrxReportPage objects from one report into another, in code.
    Something like this:
          for i := 0 to fChildReport.PagesCount - 1 do
          begin
            // get a handle to the page to be merged
            if fChildReport.Pages[i] is TFrxReportPage then
            begin
              lPage := TFrxReportPage(fChildReport.Pages[i]);
              if lPage.visible then // I ignore non-visible pages
              begin
                // create new page, so it doesn't affect original components
                lNewPage := TFrxReportPage.Create(nil { fReport } );
    
                lPageText := ReportObjToText(lPage);  //<< my own function, just saves to a stream and then into a tstringlist to store it as a text.
               <lots of customizations can be done here>
                ReportObjFromText(lNewPage, lPageText);   << loads the new page object with the text contents of the previous one.
                lNewPage.name := NewRandomName << don't use .CreateUniqueName here, it's not good enough for this case
                fReport.InsertComponent(lNewPage);
              end;
         end;
    
    Now, that code is very simple, and work with very simple reports.
    However, some problems must be worked around, as you will need to load all datasources as well into the main report object (not shown in the code above).
    Also, you need to rename datasources and parameters that have the same name in all reports. And if you do that, you will have to update all the fields that reference them to use the new names.
    If you design your reports from the ground with unique names for everything, you will be free of most problems.
    I suggest you try the code above with simple reports without any use of datasources, just to see if it's applicable to you, then move forward step by step, by adding one datasource with only one memoview referencing it in the report.
    And by the way, if you have script code in your reports, you will have to find a way to merge them too. It can be done, because I did it.
    I hope it helps


    An I have a question.
    Where I can find ReportObjToText() and ReportObjFromText() and what type is lPageText, please?
    Can you please put here these your functions?
    Thanks.
  • edited 12:24PM
    inetMark wrote: »
    Hi.
    I have 2 reports (two *.FR3 FILES).
    Is it possible create one output from them? I need to merge these two reports in Delphi enviroment - in program code.
    Thanks.
    Use the frxCompositeReport component. Read the manual for instructions on how to to use. It works well.
  • gpigpi
    edited 12:24PM
    See a Programmer's manual:
    wrote:
    1.9 Building a composite report (batch printing)
    In some cases it is required to organize printing of several reports at once, or
    capsulate and present several reports in one preview window. To perform this, there are
    tools in FastReport, which allow building a new report in addition to an already existing
    one. The ?«TfrxReport.PrepareReport?» method has the optional ?«ClearLastReport?»
    Boolean parameter, which is equal to ?«True?» by default. This parameter defines whether it
    is necessary to clear pages of the previously built report. The following code shows how to
    build a batch from two reports:
    frxReport1.LoadFromFile('1.fr3');
    frxReport1.PrepareReport;
    frxReport1.LoadFromFile('2.fr3');
    frxReport1.PrepareReport(False);
    frxReport1.ShowPreparedReport;
    We load the first report and build it without displaying. Then we load the second
    one into the same ?«TfrxReport?» object and build it with the ?«ClearLastReport?» parameter,
    equal to ?«False?». This allows the second report to be added to the one previously built.
    After that, we display a finished report in the preview window.
  • edited 12:24PM
    Thank you.
    But I can't found information about frxCompositeReport in programmers manual and users manual.
    FastReport 4 VCL

    I was try to find it here http://www.fast-report.com/en/documentation/
  • edited 12:24PM
    to gpi:
    Amazing. Thank you. It looks so easy.
  • edited January 2011
    inetMark wrote: »
    Thank you.
    But I can't found information about frxCompositeReport in programmers manual and users manual.
    FastReport 4 VCL

    I was try to find it here http://www.fast-report.com/en/documentation/
    Yes, sorry for the confusion. There was an actual CompositeReport component way back in FR2.
    FR4 incorporates this into the normal frxReport component but I just continued to name the component I used for composite reports as frxCompositeReport.
    gpi's post spells out the correct way.
  • edited 12:24PM
    Hi
    I try to merge multiple file to one file as well but didnt get the result I expect. All the report files have different datasets and works on its own.
    So, I have a TList filled with TfrxReport's. After printing, the reports are all in one file, but without datas, so there are only empty files.

    I use this code:
    function TbfwPrintSystemMultipleReport.Print: Integer;
    var
      i: Integer;
      rep: TfrxReport;
      ms: TMemoryStream;
      mainrep: TfrxReport;
    begin
      if FReports.Count > 0 then begin
        mainrep:= TfrxReport.Create( nil );
        try
          for i := 0 to FReports.Count - 1 do begin
            ms:= TMemoryStream.Create;
    
            rep:= TfrxReport(FReports[i]);
            if not rep.PrepareReport then begin
              raise Exception.Create('Preparation failed');
            end;
            rep.SaveToStream( ms, true, true, true );
            mainrep.EngineOptions.DoublePass:= true;
            ms.Position:= 0;
            mainrep.LoadFromStream(ms);
            mainrep.PrepareReport( i = 0 );
            ms.Free;
          end;
          mainrep.PrintOptions.ShowDialog:= true;
          mainrep.Print;
    
        finally
          mainrep.free;
        end;
    
      end;
    
      Result := 0;
    
    end;
    

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.