Skip to main content
A newer version of this page is available. .

Export to CSV

  • 5 minutes to read

This document describes how to export a report document to CSV format.

You can export a report from the Report Designer’s Preview and the Document Viewer on all supported platforms (WinForms, WPF, ASP.NET Web Forms, ASP.NET MVC, and ASP.NET Core). To export a file, expand the Export Document drop-down list and select CSV File. Specify export options in the invoked dialog, and click OK.

To export a report document to CSV format in code, use one of the following approaches:

  • Export a Report

    Call an XtraReport.ExportToCsv overloaded method to export a report. To specify export options, create a CsvExportOptions class instance and pass this instance to the invoked method, or use the XtraReport‘s ExportOptions.Csv property.

    using DevExpress.XtraPrinting;
    using DevExpress.XtraReports.UI;
    using DevExpress.Utils;
    // ...
    public bool ExportReport(XtraReport report, string filename) {
        try {
            // Specify CSV export options.
            var options = new CsvExportOptions();
            options.SkipEmptyColumns = false;
            options.SkipEmptyRows = false;
            options.EncodeExecutableContent = DefaultBoolean.True;
            // Export a report to CSV.
            report.ExportToCsv(filename, options);
            return true;
        }
        // Return false if the CSV export failed.
        catch {
            return false;
        }
    }
    
  • Export a Document

    Call a PrintingSystem.ExportToCsv overloaded method to export a document. To specify export options, create a CsvExportOptions class instance and pass this instance to the invoked method, or use PrintingSystem‘s ExportOptions.Csv property.

    using DevExpress.XtraPrinting;
    using DevExpress.XtraReports.UI;
    using DevExpress.Utils;
    // ...
    public bool ExportDocument(PrintingSystem printingSystem, string filename) {
        try {
            // Specify CSV export options.
            var options = new CsvExportOptions();
            options.SkipEmptyColumns = false;
            options.SkipEmptyRows = false;
            options.EncodeExecutableContent = DefaultBoolean.True;
            // Export a document to CSV.
            printingSystem.ExportToCsv(filename, options);
            return true;
        }
        // Return false if the CSV export failed.
        catch {
            return false;
        }
    }
    
  • Export a Control

    Call a PrintingLink.ExportToCsv overloaded method to export a control. To specify export options, create a CsvExportOptions class instance and pass this instance to the invoked method.

    using DevExpress.XtraPrinting;
    using DevExpress.XtraReports.UI;
    using DevExpress.Utils;
    // ...
    public bool ExportControl(IPrintable control, string filename) {
        try {
            PrintingSystem printingSystem = new PrintingSystem();
            PrintableComponentLink link = new PrintableComponentLink();
            printingSystem.Links.Add(link);
            link.Component = control;
            // Specify CSV export options.
            var options = new CsvExportOptions();
            options.SkipEmptyColumns = false;
            options.SkipEmptyRows = false;
            options.EncodeExecutableContent = DefaultBoolean.True;
            // Export a document to CSV.
            link.ExportToCsv(filename, options);
            return true;
        }
        // Return false if the CSV export failed.
        catch {
            return false;
        }
    }
    

To export a control to CSV, a report uses the control’s protected GetTextView method that returns a two-dimensional string array as the control’s text representation:

Note

You cannot export reports that use other reports’ pages. The exported file contains only one of the merged reports.

As a workaround:

  • Use subreports to combine multiple reports into a single document.
  • Export all your reports to separate CSV files, then join these files in a single file.

Export Options

Use the following properties to change the CSV export options:

Overlapped Controls

Report controls should not intersect to be correctly exported to CSV. Otherwise, the file layout can be corrupted.

Report Designers highlight overlapped controls. Users can hover the mouse pointer over these controls to see what they need to fix.

ShowExportWarnings