Developers / Export Reports / Export Page/RDLX Reports / CSV Export
CSV Export

 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 or open an existing Windows Forms App in Visual Studio project.
  2. Go to the Project Explorer, right-click the project and select Add > New Item.
  3. Select ActiveReports 19 Standalone Report > Add and choose a report type, RDLX, RDLX Dashboard, or Page report and then click Finish.
  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("..\..\..\Report1.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(@"..\..\..\Report1.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);