From 4d3cd1ffa7613427e447728a45c636b9603075da Mon Sep 17 00:00:00 2001
From: Dimo Dimov <961014+dimodi@users.noreply.github.com>
Date: Thu, 25 Sep 2025 10:18:46 +0300
Subject: [PATCH 1/2] kb(Grid): Update CSV export KB with more delimiter
information
---
.../grid-csv-export-change-field-delimiter.md | 108 +++++++++---------
1 file changed, 53 insertions(+), 55 deletions(-)
diff --git a/knowledge-base/grid-csv-export-change-field-delimiter.md b/knowledge-base/grid-csv-export-change-field-delimiter.md
index 06ad1359a4..6154fbc856 100644
--- a/knowledge-base/grid-csv-export-change-field-delimiter.md
+++ b/knowledge-base/grid-csv-export-change-field-delimiter.md
@@ -34,29 +34,24 @@ A possible option is to manually modify the exported CSV file before it reaches
For that purpose use the [`RadSpreadProcessing`](https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/overview) library - it allows you to create spreadsheets from scratch, modify existing documents or convert between the most common spreadsheet formats. In this case, we will focus on the [`CsvFormatProvider` which exposes setting to configure the field delimiter](https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/formats-and-conversion/csv/settings).
-To change the field delimiter, do the following:
+To change the CSV value delimiter, do the following:
-1. Install `Telerik.Documents.Spreadsheet.FormatProviders.Xls` package, so you can use the `CsvFormatProvider`
-
-1. Handle the [OnAfterExport](slug:grid-export-events#onafterexport) event of the Grid. The stream it provides is finalized, so that the resource does not leak. Its binary data, however, is available, so you can copy the stream bytes to a new `MemoryStream` instance.
-
-1. Create a `CsvFormatProvider` instance and use it to [import the new `MemoryStream` in a `workbook`](https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/formats-and-conversion/csv/csvformatprovider#import).
-
-1. Set the desired `Delimiter` through the [settings of the `CsvFormatProvider` instance](https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/formats-and-conversion/csv/settings)
-
-1. [Export the modified `workbook` to a `MemoryStream`](https://docs.telerik.com/devtools/document-processing/knowledge-base/import-export-save-load-workbook#save-workbook-to-filestream-or-memorystream).
-
-1. Pass that `MemoryStream` to the `args.Stream` of the `GridAfterCsvExportEventArgs`, so that the modifications can be saved to the actual exported file.
-
-
-````RAZOR
-@*Customize the field delimiter of the exported CSV file*@
+1. Install the `Telerik.Documents.Spreadsheet.FormatProviders.Xls` NuGet package, so you can use the `CsvFormatProvider`.
+1. Handle the [Grid `OnAfterExport` event](slug:grid-export-events#onafterexport). The `Stream` it provides is finalized, so that the resource does not leak. Its binary data, however, is available, so you can copy the stream bytes to a new `MemoryStream` instance.
+1. Create a `CsvFormatProvider` and [set its `Delimiter` setting to a comma `','`](https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/formats-and-conversion/csv/settings). This is necessary because the delimiter in the exported CSV file is always a comma, while the `CsvFormatProvider` assumes it based on the culture.
+1. [Import the new `MemoryStream` to a `Workbook`](https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/formats-and-conversion/csv/csvformatprovider#import).
+1. Set the desired new `Delimiter` through the [settings of the `CsvFormatProvider` instance](https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/formats-and-conversion/csv/settings).
+1. [Export the modified `Workbook` to a new `MemoryStream`](https://docs.telerik.com/devtools/document-processing/knowledge-base/import-export-save-load-workbook#save-workbook-to-filestream-or-memorystream).
+1. Pass that `MemoryStream` to the `Stream` property of the `GridAfterCsvExportEventArgs`, so that the modifications can be saved to the actual exported file.
+````RAZOR.skip-repl
@using Telerik.Windows.Documents.Spreadsheet.FormatProviders.TextBased.Csv
@using Telerik.Windows.Documents.Spreadsheet.Model
@using System.IO
-
+
Export to CSV
@@ -71,69 +66,72 @@ To change the field delimiter, do the following:
-
-
-
-
-
-
+
+
+
+
+
+
@code {
-
- private async Task OnCSVAfterExport(GridAfterCsvExportEventArgs args)
+ private void OnCSVAfterExport(GridAfterCsvExportEventArgs args)
{
- //args.Stream is finalized. The Import() method of the CSVFormatProvider requires a readable stream, so you should copy the stream bytes to a new MemoryStream instance which will be used for the import.
- var bytes = args.Stream.ToArray();
+ //args.Stream is finalized. The Import() method of the CSVFormatProvider requires a readable stream,
+ //so you should copy the stream bytes to a new MemoryStream for the import.
+ using MemoryStream importCsvStream = new MemoryStream(args.Stream.ToArray());
- var CSVStream = new MemoryStream(bytes);
-
- //create a format provider instance to call the import
+ //Create a CSV format provider that imports and exports the CSV file.
CsvFormatProvider formatProvider = new CsvFormatProvider();
- //import the stream to a workbook
- Workbook workbook = formatProvider.Import(CSVStream, new TimeSpan(0, 0, 5));
+ //The delimiter in the exported CSV file is always a comma,
+ //while the CsvFormatProvider assumes it based on the culture.
+ //Set the delimiter explicitly to avoid mismatch.
+ formatProvider.Settings.Delimiter = ',';
+
+ //Import the stream to a Telerik Workbook
+ Workbook workbook = formatProvider.Import(importCsvStream, new TimeSpan(0, 0, 5));
- //create a new MemoryStream to export the modified workbook in
- MemoryStream modifiedExport = new MemoryStream();
+ //Create a new MemoryStream to export the modified Workbook
+ using MemoryStream exportCsvStream = new MemoryStream();
- //set the desired delimiter
+ //Set the desired new CSV delimiter.
formatProvider.Settings.Delimiter = ';';
- //export the modified workbook to a stream
- formatProvider.Export(workbook, modifiedExport);
+ //Export the modified Workbook.
+ formatProvider.Export(workbook, exportCsvStream, new TimeSpan(0, 0, 5));
- //pass the modified stream to the event arguments
- args.Stream = modifiedExport;
+ //Pass the modified Stream to the OnAfterExport event argument.
+ args.Stream = exportCsvStream;
}
- private List GridData { get; set; }
+ private List? GridData { get; set; }
private bool ExportAllPages { get; set; }
protected override void OnInitialized()
{
- GridData = Enumerable.Range(1, 100).Select(x => new SampleData
- {
- ProductId = x,
- ProductName = $"Product {x}",
- UnitsInStock = x * 2,
- Price = 3.14159m * x,
- Discontinued = x % 4 == 0,
- FirstReleaseDate = DateTime.Now.AddDays(-x)
- }).ToList();
+ GridData = Enumerable.Range(1, 100).Select(x => new Product
+ {
+ Id = x,
+ Name = $"Product {x}",
+ Quantity = x * 2,
+ Price = 3.14159m * x,
+ Discontinued = x % 4 == 0,
+ ReleaseDate = DateTime.Now.AddDays(-x)
+ }).ToList();
}
- public class SampleData
+ public class Product
{
- public int ProductId { get; set; }
- public string ProductName { get; set; }
- public int UnitsInStock { get; set; }
- public decimal Price { get; set; }
+ public int Id { get; set; }
+ public string Name { get; set; } = string.Empty;
+ public decimal? Price { get; set; }
+ public int Quantity { get; set; }
public bool Discontinued { get; set; }
- public DateTime FirstReleaseDate { get; set; }
+ public DateTime ReleaseDate { get; set; }
}
}
````
From d44e8fd44b8034396de646237d8c6eba317e7447 Mon Sep 17 00:00:00 2001
From: Dimo Dimov <961014+dimodi@users.noreply.github.com>
Date: Thu, 25 Sep 2025 10:31:27 +0300
Subject: [PATCH 2/2] polishing
---
.../grid-csv-export-change-field-delimiter.md | 34 +++++++++----------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/knowledge-base/grid-csv-export-change-field-delimiter.md b/knowledge-base/grid-csv-export-change-field-delimiter.md
index 6154fbc856..7884ebcdf0 100644
--- a/knowledge-base/grid-csv-export-change-field-delimiter.md
+++ b/knowledge-base/grid-csv-export-change-field-delimiter.md
@@ -6,35 +6,36 @@ page_title: Grid export to CSV - change the default field delimiter (comma)
slug: grid-kb-csv-export-change-field-delimiter
position:
tags: grid, export, csv, field, delimiter, change, semicolon, comma, custom
-ticketid: 1576816
+ticketid: 1576816, 1699366
res_type: kb
---
## Environment
+
-
-
- Product |
- Grid for Blazor |
-
-
+
+
+ Product |
+ Grid for Blazor |
+
+
-
## Description
+
I want to change the default field delimiter when exporting the Grid to CSV file. How to set a different list separator?
I want to use a semicolon field delimiter for the exported CSV Grid instead of comma. How to achieve this?
->tip At the time of writing (**UI for Blazor 3.5.0**), the Blazor Grid [does not expose a built-in option for configuring the field delimiter](https://feedback.telerik.com/blazor/1577167-option-to-configure-the-field-delimiter-when-exporting-to-csv). You may vote for the enhancement and follow it to receive status updates.
+>tip The Blazor Grid [does not expose a built-in option for setting the CSV delimiter](https://feedback.telerik.com/blazor/1577167-option-to-configure-the-field-delimiter-when-exporting-to-csv). You can vote for the enhancement and follow it to receive status updates. It depends on a [feature of RadSpreadProcessing](https://feedback.telerik.com/document-processing/1356286-spreadstreamprocessing-implement-settings-for-changing-the-delimiter-and-quote-when-exporting-to-csv).
## Solution
-A possible option is to manually modify the exported CSV file before it reaches the client to change the field delimiter.
+Modify the exported CSV file before it reaches the user to change the field delimiter.
-For that purpose use the [`RadSpreadProcessing`](https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/overview) library - it allows you to create spreadsheets from scratch, modify existing documents or convert between the most common spreadsheet formats. In this case, we will focus on the [`CsvFormatProvider` which exposes setting to configure the field delimiter](https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/formats-and-conversion/csv/settings).
+Use the [`RadSpreadProcessing`](https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/overview) library. It allows you to create spreadsheets from scratch, modify existing documents or convert between the most common spreadsheet formats. In this case, we will focus on the [`CsvFormatProvider` which exposes setting to configure the field delimiter](https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/formats-and-conversion/csv/settings).
-To change the CSV value delimiter, do the following:
+To change the CSV value delimiter:
1. Install the `Telerik.Documents.Spreadsheet.FormatProviders.Xls` NuGet package, so you can use the `CsvFormatProvider`.
1. Handle the [Grid `OnAfterExport` event](slug:grid-export-events#onafterexport). The `Stream` it provides is finalized, so that the resource does not leak. Its binary data, however, is available, so you can copy the stream bytes to a new `MemoryStream` instance.
@@ -94,7 +95,7 @@ To change the CSV value delimiter, do the following:
//Import the stream to a Telerik Workbook
Workbook workbook = formatProvider.Import(importCsvStream, new TimeSpan(0, 0, 5));
- //Create a new MemoryStream to export the modified Workbook
+ //Create a new MemoryStream to export the modified Workbook.
using MemoryStream exportCsvStream = new MemoryStream();
//Set the desired new CSV delimiter.
@@ -138,7 +139,6 @@ To change the CSV value delimiter, do the following:
## See Also
- * [Format numbers and dates in the exported CSV file from the Grid](slug:grid-kb-number-formatting-of-the-csv-export)
- * [Custom cell formatting of the exported file with RadSpreadProcessing](slug:grid-kb-custom-cell-formatting-with-radspreadprocessing)
- * [Configure Document Processing Libraries](slug:getting-started-vs-integration-dpl)
-
+* [Format numbers and dates in the exported CSV file from the Grid](slug:grid-kb-number-formatting-of-the-csv-export)
+* [Custom cell formatting of the exported file with RadSpreadProcessing](slug:grid-kb-custom-cell-formatting-with-radspreadprocessing)
+* [Configure Document Processing Libraries](slug:getting-started-vs-integration-dpl)