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 comma. You can use the CsvRenderingExtension to render your report in this format.
The following steps provide an example of rendering a report in the Csv format.
Visual Basic.NET code. Paste INSIDE the Form Load event. |
Copy Code
|
---|---|
' Provide the page report you want to render. Dim report As New GrapeCity.ActiveReports.PageReport() Dim reportDocument As New GrapeCity.ActiveReports.Document.PageDocument(report) ' 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.RowsDelimiter = vbCr & vbLf csvSettings.QuotationSymbol = """"c csvSettings.Encoding = System.Text.Encoding.UTF8 ' 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 reportDocument.Render(csvRenderingExtension, outputProvider, csvSettings) |
C# code. Paste INSIDE the Form Load event. |
Copy Code
|
---|---|
// Provide the page report you want to render. GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(); GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report); // 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.RowsDelimiter = "\r\n"; csvSettings.QuotationSymbol = '"'; csvSettings.Encoding = Encoding.UTF8; // 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; reportDocument.Render(csvRenderingExtension, outputProvider, csvSettings); |