ActiveReports 18 .NET Edition
Developers / Export Reports / Export Page/RDLX Reports / CSV Export
In This Topic
    CSV Export
    In This Topic

    Comma-Separated Values (CSV) is a form of structured data in plain text. The text in a CSV file is saved as series of values separated by commas. You can use the CsvRenderingExtension to render your report in this format.

    CSV Rendering Properties

    ActiveReports offers several options to control how reports render to CSV.

    Property Description
    ColumnsDelimiter Sets or returns the text inserted between columns.
    DateTimeFormat Specifies the default format for date values, for example, 'yyyy-MM-dd'.
    Encoding Specifies the encoding schema for output.
    NoHeader Specifies whether to omit the CSV Header.
    NumericFormat Specifies the format for numeric values, for example, '0.####'.  
    QuotationSymbol Sets or returns the qualifier character to put around results.
    RowsDelimiter Sets or returns the text inserted between rows.

    Export Report using CSV Rendering Extension

    The following steps provide an example of rendering a report in the Csv format.

    1. Create a new Visual Studio project.
    2. In the New Project dialog that appears, select ActiveReports 18 Page report Application and specify a name for the project in the Name field.
    3. Click OK to create a new ActiveReports 18 Page report Application. By default, a Page report is added to the project.
    4. Add a reference to MESCIUS.ActiveReports.Export.Xml package in the project.
    5. On the Form.cs or Form.vb that opens, double-click the title bar to create the Form_Load event.
    6. Add the following code inside the Form_Load event.

    VB code. Paste INSIDE the Form Load event.
    Copy Code
    ' Provide the Page report you want to render.
    
    Dim rptPath As System.IO.FileInfo = New System.IO.FileInfo("..\..\PageReport1.rdlx")
    Dim pageReport As GrapeCity.ActiveReports.PageReport = New GrapeCity.ActiveReports.PageReport(rptPath)
    
    ' Create an output directory.
    Dim outputDirectory As New System.IO.DirectoryInfo("C:\MyCSV")
    outputDirectory.Create()
    
    ' Provide settings for your rendering output.
    Dim csvSettings As New GrapeCity.ActiveReports.Export.Text.Page.CsvRenderingExtension.Settings()
    
    csvSettings.ColumnsDelimiter = ","
    csvSettings.Encoding = System.Text.Encoding.UTF8
    csvSettings.NoHeader = True
    csvSettings.QuotationMode = GrapeCity.ActiveReports.Export.Text.Page.QuotationMode.AlwaysQuote
    csvSettings.QuotationSymbol = """"c
    csvSettings.RowsDelimiter = vbCr & vbLf
    
    ' Set the rendering extension and render the report.
    Dim csvRenderingExtension As New GrapeCity.ActiveReports.Export.Text.Page.CsvRenderingExtension()
    Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name))
    
    ' Overwrite output file if it already exists.
    outputProvider.OverwriteOutputFile = True
    
    pageReport.Document.Render(csvRenderingExtension, outputProvider, csvSettings)
    
    C# code. Paste INSIDE the Form Load event.
    Copy Code
    // Provide the Page report you want to render.
    System.IO.FileInfo rptPath = new System.IO.FileInfo(@"..\..\PageReport1.rdlx");
    GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(rptPath);
    
    // Create an output directory.
    System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"C:\MyCSV");
    outputDirectory.Create();
    
    // Provide settings for your rendering output.
    GrapeCity.ActiveReports.Export.Text.Page.CsvRenderingExtension.Settings csvSettings = new GrapeCity.ActiveReports.Export.Text.Page.CsvRenderingExtension.Settings();
    csvSettings.ColumnsDelimiter = ",";
    csvSettings.Encoding = Encoding.UTF8;
    csvSettings.NoHeader = true;
    csvSettings.QuotationMode = GrapeCity.ActiveReports.Export.Text.Page.QuotationMode.AlwaysQuote;
    csvSettings.QuotationSymbol = '"';
    csvSettings.RowsDelimiter = "\r\n";
                             
    // Set the rendering extension and render the report.
    GrapeCity.ActiveReports.Export.Text.Page.CsvRenderingExtension csvRenderingExtension = new GrapeCity.ActiveReports.Export.Text.Page.CsvRenderingExtension();
    GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name));
    
    // Overwrite output file if it already exists.
    outputProvider.OverwriteOutputFile = true;
    pageReport.Document.Render(csvRenderingExtension, outputProvider, csvSettings);