FlexReport for .NET | ComponentOne
Reports in WPF / Export Reports
In This Topic
    Export Reports
    In This Topic

    Instead of printing the report, you may want to export it into a file and distribute it to your clients or co-workers.  You can export a report to different formats which are listed below in the following table:

    Format Description
    Paged HTML (*.html) Creates one HTML file for each page in the report. The HTML pages contain links that let the user navigate the report.
    Plain HTML (*.html) Creates a single HTML file with no drill-down functionality.
    PDF with non-embedded (linked) fonts (*.pdf) Creates a PDF file that can be viewed on any computer equipped with Adobe's Acrobat viewer or browser plug-ins.
    PDF/A with embedded fonts (*.pdf) Creates a PDF file with embedded font information for extra portability.
    RTF (*.rtf) Creates an RTF file that can be opened by most popular word processors (for example, Microsoft Word, WordPad). It can be saved as Paged or Open XML document.
    Microsoft Excel 97 (*.xls) Creates an XLS file that can be opened by Microsoft Excel.
    Microsoft Excel Open XML (*.xlsx) Creates an XLS file that can be opened by Microsoft Excel 2007 and later.
    Open XML Word (*.docx) Creates a DOCX file that can be opened by Microsoft Word 2007 and later.
    Compressed Metafile (*.zip) Creates a compressed metafile file, of the type EmfOnly, EmfPlusOnly,and EmfPlusDual.
    TIFF (*.tiff), BMP, PNG, JPEG, GIF images Create image file of type TIFF (Tag Image File Format), BMP (Bitmap Images), PNG(Portable Network Graphic), JPEG or GIF.

    Render FlexReport using HTMLFilter class

    FlexReport allows you to render a report to HTML format using the HtmlFilter class, which renders the report into HTML streams or files.

    To render a FlexReport to HTML format, use the following code. This example uses sample created in FlexReport Quick Start.

    C#
    Copy Code
    HtmlFilter f = new HtmlFilter();            
    f.FileName = @"D:\Reports\EmployeeReport.html";
    flexreport.RenderToFilter(f);
    

    Render FlexReport using PdfFilter class

    FlexReport allows you to render a report to PDF format using PdfFilter class which allows you to render the report into PDF streams or files.

    To render a FlexReport in PDF format, use the following code. This example uses sample created in FlexReport Quick Start.

    C#
    Copy Code
    PdfFilter f = new PdfFilter();
    f.FileName = @"D:\Reports\ProductReport.pdf";
    flexreport.RenderToFilter(f);
    

    You can also use the following properties of PdfFilter class:

    Properties Description
    EmbedFonts Used to embed font information in PDF document.
    PdfACompatible Used to generate PDF/A compatible document.
    PdfSecurityOptions Used to specify who can use the Pdf document and what actions are allowed on it.
    UseCompression Used for PDF document compression.
    UseOutlines Used to include an outline tree.

    Export FlexReport using RTFFilter class

    FlexReport allows you to export a report to RTF format using RtfFilter class which allows to export the report into RTF streams or files.

    To export a FlexReport to RTF format, use the following code. The example uses sample created in FlexReport Quick Start.

    C#
    Copy Code
    RtfFilter f = new RtfFilter();
    f.FileName = @"D:\Reports\EmployeeReport.rtf";
    flexreport.RenderToFilter(f);
    

    You can also use the following properties of RtfFilter class:

    Properties Description
    OpenXML Used to export the file in OpenXML format.
    Paged Used to preserve the page layout of the original report.
    ShapesWord2007Compatible Used to indicate the Word 2007 shapes format compatibility in a report to be saved to DOCX format.

    Render FlexReport using Different Export Filters for Images

    FlexReport allows you to render a report to various image file formats, such as PNG, JPG, BMP, GIF, and TIFF. Each of these image file formats have an exclusive export filter for a particular format. PngFilter class can be used to render a report to PNG format. Similarly, JpegFilter class is used to render a report to JPEG format, GifFilter class is used to render a report to GIF format, BmpFilter class is used to render a report to BMP format, and TiffFilter class is used to render a report to TIFF format.

    To render a FlexReport in PNG format, use the following code. This example uses sample created in FlexReport Quick Start.

    C#
    Copy Code
    PngFilter f = new PngFilter();
    f.FileName = @"D:\Reports\Productreport.png";
    flexreport.RenderToFilter(f);
    

    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 the 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.

    1. Add the following namespaces in the code:
      C#
      Copy Code
      using C1.WPF.Document.Export;
      using C1.WPF.Report;
      using System.IO;
      
    2. Add the following code in the code view to create an instance of FlexReport:
      C#
      Copy Code
      FlexReport _report = new FlexReport();
      
    3. Add the following code beneath InitializeComponent() method in the interaction logic for XAML:
      C#
      Copy Code
      foreach (var e in flexreport.SupportedExportProviders)
      {
          cbxExportFormat.Items.Add(e.FormatName);
      }
      cbxExportFormat.SelectedIndex = 0;
      
    4. Add a Button control in the XAML view for exporting a FlexReport to different formats using ExportFilter and ExportProvider class. Use the following code in its Click event:
      C#
      Copy Code
      string[] reports = C1FlexReport.GetReportList(@"..\..\productreportqs.flxr");
      
      ExportProvider ep = flexreport.SupportedExportProviders[cbxExportFormat.SelectedIndex];
      ExportFilter ef = ep.NewExporter() as ExportFilter;
      if (!Directory.Exists(@"D:\Reports"))
          Directory.CreateDirectory(@"D:\Reports");
      
      foreach (string reportName in reports)
      {
          using (C1FlexReport rep = new C1FlexReport())
          {
      
              rep.Load(@"..\..\productreportqs.flxr", "Product Report");
              DataTable dt = GetMyDataTable();
              rep.DataSource.Recordset = dt;
      
      
              ef.FileName = string.Format(@"D:\Reports\{0}.{1}", reportName, ep.DefaultExtension);
              try
              {
                  rep.RenderToFilter(ef);
                  MessageBox.Show("Report Exported");
              }
              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.

    You can also export a file using FlexReportDesigner. For more information, check the description of Export in File Menu to understand the steps to export a report.