Skip to content

Commit 228d051

Browse files
committed
KB - Importing and Exporting CSV Files while changing their formatting in Telerik SpreadProcessing.
1 parent ccf4f70 commit 228d051

File tree

3 files changed

+24
-29
lines changed

3 files changed

+24
-29
lines changed
12 KB
Loading
11.4 KB
Loading
Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Importing and Exporting CSV Files while changing their formatting in Telerik SpreadProcessing
3-
description: Learn how to handle culture settings, delimiters, and decimal separators while importing and exporting CSV files in Telerik SpreadProcessing.
3+
description: Learn how to handle culture settings, delimiters, decimal separators, and date formats while importing and exporting CSV files in Telerik SpreadProcessing.
44
type: how-to
55
page_title: Changing Formatting While Importing and Exporting CSV Files in SpreadProcessing
66
meta_title: Changing Formatting While Importing and Exporting CSV Files in SpreadProcessing
@@ -12,22 +12,13 @@ ticketid: 1700417
1212

1313
## Environment
1414

15-
<table>
16-
<tbody>
17-
<tr>
18-
<td> Product </td>
19-
<td> SpreadProcessing for Telerik Document Processing </td>
20-
</tr>
21-
<tr>
22-
<td> Version </td>
23-
<td> 11.1.1 </td>
24-
</tr>
25-
</tbody>
26-
</table>
15+
| Version | Product | Author |
16+
| --- | --- | ---- |
17+
| 2025.3.806 | RadSpreadProcessing |[Yoan Karamanov](https://www.telerik.com/blogs/author/yoan-karamanov)|
2718

2819
## Description
2920

30-
I want to import a CSV file and export its values to another CSV file while applying specific formatting during the process. I need to account for culture settings and delimiters during both import and export operations to ensure the desired formatting results.
21+
This article shows how to import a CSV file and export it with different formatting (delimiters, decimal separators, and date formats) back to CSV. You need to account for culture settings and delimiters during both import and export operations to ensure the desired formatting results.
3122

3223
This knowledge base article also answers the following questions:
3324
- How to change culture settings during CSV import/export in SpreadProcessing?
@@ -36,12 +27,22 @@ This knowledge base article also answers the following questions:
3627

3728
## Solution
3829

39-
To import and export a CSV file with custom formatting, follow these steps:
30+
Example input data (*a comma (",") as the delimiter and a dot (".") as the decimal separator*):
4031

41-
1. Set the culture settings to English (en-EN) and the delimiter to a comma (",") for importing the CSV file.
42-
2. Import the CSV file using the `CsvFormatProvider` and parse the workbook.
43-
3. Switch the culture settings to German (de-DE), the delimiter to a semicolon (";"), and apply the desired formatting.
44-
4. Export the formatted workbook to a new CSV file.
32+
![Input CSV](images/import-export-csv-formatting-input.png)
33+
34+
Example result data (*a semicolon (";") as the delimiter, a comma (",") as the decimal separator, and a formatted date*):
35+
36+
![Output CSV](images/import-export-csv-formatting-output.png)
37+
38+
To import and process the input file correctly you must:
39+
* Set the **Delimiter** property of the [CsvFormatProvider Settings]({%slug radspreadprocessing-formats-and-conversion-csv-settings%}) to a comma (",")
40+
* Set the [culture]({%slug radspreadprocessing-features-setting-the-culture%}) to English ("en-EN"), since its default decimal separator is a dot (".") and must match the file decimal separator
41+
42+
Once the document is imported and parsed, you can:
43+
* Switch to a culture that has a comma (",") as its default decimal separator (e.g German - "de-DE")
44+
* Set a new [Number Format]({%slug radspreadprocessing-features-number-formats%}) with a comma ("#,##") to the number values
45+
* Set the **Delimiter** property of the [CsvFormatProvider Settings]({%slug radspreadprocessing-formats-and-conversion-csv-settings%}) to a semicolon (";")
4546

4647
### Full Code Example
4748

@@ -58,7 +59,7 @@ Workbook workbook;
5859
CsvFormatProvider formatProvider = new CsvFormatProvider();
5960
formatProvider.Settings.Delimiter = ',';
6061

61-
using (Stream input = new FileStream("..\\..\\..\\input.csv", FileMode.Open))
62+
using (Stream input = new FileStream("input.csv", FileMode.Open))
6263
{
6364
workbook = formatProvider.Import(input, TimeSpan.FromSeconds(10));
6465
}
@@ -80,21 +81,15 @@ date.SetFormat(dateFormat);
8081

8182
formatProvider.Settings.Delimiter = ';';
8283

83-
string fileName = "..\\..\\..\\output.csv";
84+
string fileName = "output.csv";
8485
File.Delete(fileName);
8586
using (Stream output = new FileStream(fileName, FileMode.Create))
8687
{
8788
formatProvider.Export(workbook, output, TimeSpan.FromSeconds(10));
8889
}
8990
```
9091

91-
### Key Notes:
92-
- Modify `SpreadsheetCultureHelper` settings before and after importing the file to ensure proper parsing and formatting.
93-
- Use `CsvFormatProvider.Settings.Delimiter` to set the appropriate delimiter for import and export.
94-
- Apply formatting such as `CellValueFormat` to columns before exporting the workbook.
95-
9692
## See Also
9793

98-
- [SpreadProcessing Overview](https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/overview)
99-
- [CsvFormatProvider Documentation](https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/features/import-export/csv)
100-
- [Formatting Cells in SpreadProcessing](https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/features/cells/formatting-cells)
94+
* [SpreadProcessing]({%slug radspreadprocessing-overview%})
95+
* [CsvFormatProvider]({%slug radspreadprocessing-formats-and-conversion-csv-csvformatprovider%})

0 commit comments

Comments
 (0)