Exporting Multiple Reports to a Single File

Below is an example of creating and using a form used to export multiple express reports intto a single XLS file.

Firstly, create a form. Place the following components on the form: Button, Label, EditBox, MetabaseOpenDialog and Memo:

The form should work as follows: a user clicks the Export button, which calls the dialog box opening repository objects. Only express reports can be selected in this dialog box. If a user selects one or several express reports, the reports are to be exported to the file specified in the EditBox component in XLS format. Default file specified in the EditBox component is C:\ExportReport.xls. Messages on export progress are displayed in the Memo component.

Firstly, set the OnCreate event for the form as follows:

Sub BatchExportFormOnCreate(Sender: Object; Args: IEventArgs);
Begin
    EditBox1.Text := "C:\ExportReport.xls";
    Memo1.Lines.Clear;
End Sub BatchExportFormOnCreate;

Then set the OnClick event for the Button component as follows:

Sub Button1OnClick(Sender: Object; Args: IEventArgs);
Var
    Filter: IMetabaseDialogClassFilter;
    Objects: IMetabaseObjectDescriptorList;
    List: IStringList;
    Exp: ExAnalyzerExporter;
    i, Count: integer;
    id: String;
Begin
    MetabaseOpenDialog1.MultiSelect := True;
    //Create filter for the dialog of opening repository object.
    Filter := New MetabaseDialogClassFilter.Create;
    Filter.Description := "Express reports";
    //Determine a type of objects, which will be shown in the dialog on using
    //this filter: express report.
    Filter.ObjectClass := MetabaseObjectClass.KE_CLASS_EXPRESSREPORT;
    List := Memo1.Lines;
    List.Clear;
    MetabaseOpenDialog1.Filters.AddFilter(Filter);
    If MetabaseOpenDialog1.Execute(Self) Then
        //These expressions are performed if the user selected one express report or more.
        Objects := MetabaseOpenDialog1.Objects;
        Count := Objects.Count;
        List.Add("Number of reports selected for export:" + Count.ToString);
        //Start of batch export of selected reports           
        Exp := New ExAnalyzerExporter.Create;
        Exp.StartBatchCommand(EditBox1.Text, "XLS");
        For i := 0 To Count - 1 Do
            id := Objects.Item(i).Id;
            Exp.ExAnalyzer := MetabaseClass.Active.ItemById(id).Bind As IEaxAnalyzer;
            Exp.ExportToFile("""XLS");
            Memo1.Lines.Add("Report '" + Objects.Item(i).Name + "' exported");
        End For;
        //End of batch export of selected reports.
        Exp.FinishBatchCommand;
        List.Add("Export of reports finished");
    End If;
End Sub Button1OnClick;

After the compilation, on the start the form looks like follows:

Click the Export button to open the dialog box opening repository objects. Select the express reports to be exported in this dialog box. The reports are exported to the file C:\ExportReport.xls. Messages on export progress are displayed in the Memo component:

See also:

Examples | IExAnalyzerExporter