Working with FlexReport > Exporting Reports > Export Reports using ExportFilter Class |
As an alternative to using a specific format filter (for example, PdfFilter) for exporting a report to a particular format ( say, PDF format), FlexReport allows you to export a report to different formats using ExportFilter class. The ExportFilter class is an abstract base class for all exporter classes. An object of ExportFilter class is used to export a report to different formats. The ExportFilter class accesses the ExportProvider abstract class which describes supported export formats.
In the following code, we have used the ExportFilter class that accesses the ExportProvider class to list all the export formats in a ComboBox, which are described in the ExportProvider class. To do so, a ComboBox control is added in the design view to show the list of available export formats and its name is set to cbxExportFormat.
Imports C1.WPF.Document.Export Imports C1.WPF.FlexReport Imports System.IO
using C1.WPF.Document.Export; using C1.WPF.FlexReport; using System.IO;
Private _report As New C1FlexReport()
private C1FlexReport _report = new C1FlexReport();
' build list of supported export filters For Each e In _report.SupportedExportProviders cbxExportFormat.Items.Add(e.FormatName) Next cbxExportFormat.SelectedIndex = 0
// build list of supported export filters foreach (var e in _report.SupportedExportProviders) { cbxExportFormat.Items.Add(e.FormatName); } cbxExportFormat.SelectedIndex = 0;
Dim reports As String() = C1FlexReport.GetReportList("..\..\FlexCommonTasks_WPF.flxr") Dim ep As ExportProvider = _report.SupportedExportProviders(cbxExportFormat.SelectedIndex) Dim ef As ExportFilter = TryCast(ep.NewExporter(), ExportFilter) If Not Directory.Exists("..\..\ExportResults") Then Directory.CreateDirectory("..\..\ExportResults") End If For Each reportName As String In reports Using rep As New C1FlexReport() rep.Load("..\..\FlexCommonTasks_WPF.flxr", reportName) ef.FileName = String.Format("..\..\ExportResults\{0}.{1}", reportName, ep.DefaultExtension) Try rep.RenderToFilter(ef) Catch ex As Exception MessageBox.Show(String.Format("Exception while export [{0}] report:" _ & vbCr & vbLf & "{1}", reportName, ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.[Error]) End Try End Using Next
string[] reports = C1FlexReport.GetReportList(@"..\..\FlexCommonTasks_WPF.flxr"); ExportProvider ep = _report.SupportedExportProviders[cbxExportFormat.SelectedIndex]; ExportFilter ef = ep.NewExporter() as ExportFilter; if (!Directory.Exists(@"..\..\ExportResults")) Directory.CreateDirectory(@"..\..\ExportResults"); foreach (string reportName in reports) { using (C1FlexReport rep = new C1FlexReport()) { rep.Load(@"..\..\FlexCommonTasks_WPF.flxr", reportName); ef.FileName = string.Format(@"..\..\ExportResults\{0}.{1}", reportName, ep.DefaultExtension); try { rep.RenderToFilter(ef); } catch (Exception ex) { MessageBox.Show(string.Format ("Exception while export [{0}] report:\r\n{1}", reportName, ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }
You can also use the following properties available in ExportFilter class:
Properties | Description |
---|---|
FileName | Used to name the output file. |
MultiFile | Used to indicate whether multiple files were generated during export. |
OutputFiles | Used to show the list of files which were generated by the call to Export(string). |
PageSettings | Used to specify the settings that apply to a page. |
Preview | Used to indicate whether the exported document should be opened after exporting it to a disk file. |
Range | Used to represent the range of pages to be exported. |
ShowOptions | Used to indicate whether the options dialog should be shown before exporting the document. |
Stream | Used to specify the output stream. |
UseZipForMultipleFiles | Used to indicate whether the output (stream or file) should be a zipped archive with the generated files, if multiple files are created during export. |