See below an example of creating a form and using it to export multiple regular reports to a single XLS file.
First, create a form. Place the following components on the form: Button, Label, EditBox, MetabaseOpenDialog and Memo:
The form should work as follows: the user clicks the Export button, which opens a dialog box for opening repository objects. You can select only regular reports in this dialog box. If the user has selected one or several reports, they should be exported to the XLS file specified in the EditBox component. The default file specified in the EditBox component is C:\ExportReport.xls. Messages on export progress are displayed in the Memo component.
First, set the OnShow event for the form as follows:
Sub TestFormOnShow(Sender: Object; Args: IEventArgs);
Begin
EditBox1.Text := "C:\ExportReport.xls";
Memo1.Lines.Clear;
End Sub TestFormOnShow;
Then set the OnClick event for the Button component as follows:
Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
Filter: IMetabaseDialogClassFilter;
Objects: IMetabaseObjectDescriptorList;
List: IStringList;
Exp: PrxReportExporter;
i, Count: integer;
id: String;
Begin
MetabaseOpenDialog1.MultiSelect := True;
// Create a filter for dialog box of opening repository object.
Filter := New MetabaseDialogClassFilter.Create;
Filter.Description := "Regular reports";
// Determine the type of objects, which will be displayed in the dialog
// on using of this filter: regular report.
Filter.ObjectClass := MetabaseObjectClass.KE_CLASS_PROCEDURALREPORT;
// Create a filter for dialog box of opening a repository object.
MetabaseOpenDialog1.Filters.AddFilter(Filter);
List := Memo1.Lines;
// Clear the Memo component
List.Clear;
If MetabaseOpenDialog1.Execute(Self) Then
// These operations are executed if user has selected one or several regular reports.
Objects := MetabaseOpenDialog1.Objects;
Count := Objects.Count;
List.Add("Number of reports to be exported:" + Count.ToString);
// Start batch export of selected reports
Exp := New PrxReportExporter.Create;
Exp.StartBatchCommand(EditBox1.Text, "XLS");
For i := 0 To Count - 1 Do
id := Objects.Item(i).Id;
Exp.Report := MetabaseClass.Active.ItemById(id).Bind As IPrxReport;
Exp.ExportToFile("", "XLS");
Memo1.Lines.Add("Report '" + Objects.Item(i).Name + "' exported");
End For;
// Finish batch export of selected reports.
Exp.FinishBatchCommand;
List.Add("Report export finished");
End If;
End Sub Button1OnClick;
When you start this form after compilation, it looks like follows:
Click the Export button to open the dialog box opening repository objects. In this dialog box, select regular reports to be exported. The reports are exported to the file C:\ExportReport.xls. Messages on export progress are displayed in the Memo component:
NOTE. You can export multiple reports only when all the sheets have different names.
See also: