FlexReport for .NET | ComponentOne
Reports in WinForms / 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. To export a file in FlexReportDesigner, select Export option from the File menu and use the Export Report to File dialog box to specify the location, File name and Save as type.

    The FlexReportDesigner supports the following export formats:

    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 PdfFilter class

    FlexReport allows you to render a report to PDF format files or streams using PdfFilter class. 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 = @"C:\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.

    Render FlexReport using HTMLFilter class

    FlexReport allows you to render a report to HTML format using HtmlFilter class. The HtmlFilter class 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 = @"C:\Reports\EmployeeReport.html";
    flexreport.RenderToFilter(f);
    

    Render FlexReport using Different Export Filters for Images

    FlexReport allows you to render a report into various image file formats, such as PNG, JPG, BMP, GIF, and TIFF. Each format has a specific export filter class: PngFilter for PNG, JpegFilter for JPEG, GifFilter for GIF, BmpFilter for BMP, and TiffFilter for TIFF.

    To render a FlexReport in PNG format, use the following code example from the FlexReport Quick Start guide.

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

    Export FlexReport using RTFFilter class

    FlexReport allows you to export a report to RTF format using RtfFilter class. The RtfFilter class exports 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 = @"C:\Reports\Productreport.png";
    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.

    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.

    1. Add the following namespaces in the code as shown in the code below:
      C#
      Copy Code
      using C1.Win.Document.Export;
      using C1.Win.FlexReport;
      using System.IO;
      
      Note: Replace C1.Win.Document.Export with C1.Win.C1Document.Export for .NET Framework 4.x version.
    2. Add the following code in the code view to create an instance of FlexReport:
      C#
      Copy Code
      C1FlexReport flexreport = new C1FlexReport();
      
    3. Add the following code beneath InitializeComponent() method in the code window to load the ComboBox with the available formats:
      C#
      Copy Code
      foreach (var e in flexreport.SupportedExportProviders)
      {
          cbxExportFormat.Items.Add(e.FormatName);
      }
      cbxExportFormat.SelectedIndex = 0;
      
    4. Add a Button control in the design 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(@"C:\Reports"))
          Directory.CreateDirectory(@"C:\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(@"C:\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", MessageBoxButtons.OK, MessageBoxIcon.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.