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.
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. |
The following steps provide an example of rendering a report in the Csv format.
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); |