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

XtraReport.ExportToCsv(Stream, CsvExportOptions) Method

Exports a report to the specified stream in CSV format using the specified CSV-specific options.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v19.2.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

public void ExportToCsv(
    Stream stream,
    CsvExportOptions options
)

Parameters

Name Type Description
stream Stream

A Stream object to which the created CSV file should be sent.

options CsvExportOptions

A CsvExportOptions object which specifies the CSV export options to be applied when a report is exported.

Remarks

Once the document export has started, it will run until the resulting document is complete and cannot be interrupted or canceled in the process.

Use this method to export a report to a CSV format using the specified CSV export options (like TextExportOptionsBase.Encoding, TextExportOptionsBase.Separator and other.) Note that in this instance the current report export options, which are represented by the CsvExportOptions object returned by the ExportOptions.Csv property of a report’s XtraReport.ExportOptions, are ignored.

If you want to use the current export options of a report, you should call the overloaded XtraReport.ExportToCsv method without the options parameter.

Note

For more information on using the ExportToCsv method, and limitations on export to CSV, please refer to the Export to CSV document.

Example

The following example demonstrates how to export a report to CSV format. To do this, the XtraReport.ExportToCsv method should be used. It also demonstrates what specific CsvExportOptions may be used when a report is exported to CSV.

Your project should include a non-blank report named XtraReport1. Handle the Button.Click event of any button on a form to execute the ExportToCSV method. The resulting file is opened in the default program registered for *.csv files in your system.

using System.Text;
using System.Diagnostics;
using System.Globalization;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
// ...

private void ExportToCSV()
{
    // A path to export a report.
    string reportPath = "c:\\Test.csv";

    // Create a report instance.
    XtraReport1 report = new XtraReport1();

    // Get its CSV export options.
    CsvExportOptions csvOptions = report.ExportOptions.Csv;

    // Set CSV-specific export options.
    csvOptions.Encoding = Encoding.Unicode;
    csvOptions.Separator = CultureInfo.CurrentCulture.TextInfo.ListSeparator.ToString();

    // Export the report to CSV.
    report.ExportToCsv(reportPath);

    // Show the result.
    StartProcess(reportPath);
}

// Use this method if you want to automaically open
// the created CSV file in the default program.
public void StartProcess(string path)
{
    Process process = new Process();
    try
    {
        process.StartInfo.FileName = path;
        process.Start();
        process.WaitForInputIdle();
    }
    catch { }
}
See Also