How can we write a separator of type sep = using the CsvHelper library?

we use the CsvHelper library to export some information from our application, our customers usually use Excel to view the results

enter image description here (sample of correctly open data)

everything worked fine until I tested my generated files on another machine using the format installed in German (Austria) , which I found out that excel will no longer parse it correctly, which is understandable because it has a different meaning in this format . enter image description here

adding sep = in the first line seems to fix the problem, but I could not find in the CsvHelper docs that we can achieve this. therefore the question

How can we write a separator like sep = or something similar using the CsvHelper library?

+6
source share
2 answers

Inside the CsvWriter class, CsvWriter is a label named WriteExcelSeparator() that should do this.

Depending on how you use the library, you may even:

 csv.Configuration.Delimiter = ","; csv.Configuration.HasExcelSeparator = true; 

If you use WriteRecords , use the second method, and if you use WriteHeader / WriteRecord , use the first.

 csv.WriteExcelSeparator(); csv.WriteHeader<Simple>(); csv.WriteRecord( record ); 
+7
source

since csvHelper supports specific Excel methods, you can do it now ..

 csvWriter.WriteField("sep=,", false); csvWriter.NextRecord(); csvWriter.WriteRecords(dataToExport); 
0
source

All Articles