0

I try to save a datagrid as csv via copy datagrid to clipboard acording to this post: Copy text from WPF DataGrid to Clipboard to Excel

The export works, but the column delimiter is "," but I use a german region setting with ";" delimiter character. The hole text is in one column:(

Can I change the DataFormats.CommaSeparatedValue delimiter?

Thank you and have a nice day

Chris

Community
  • 1
  • 1
Chris
  • 103
  • 1
  • 8

3 Answers3

0

Not sure if you can change the delimiter. If you don't find a way, you can always do this:

string result1 = ((string)Clipboard.GetData(DataFormats.CommaSeparatedValue)).Replace(";",",");
Shannon Holsinger
  • 2,293
  • 1
  • 15
  • 21
  • hi, thanks. But by this solution the problem is my decimal mark is "," – Chris Sep 13 '16 at 08:35
  • If you have commas in the file and want to use semi-colon, use Replace(",",";"). If you have semi-colon in file and want to use commas, use Replace(";",","). All you're asking the compiler to do is switch one character for another. REPLACE("{CURRENT_STRING}","{DESIRED_STRIGR}"); Cheers! – Shannon Holsinger Sep 13 '16 at 12:01
  • You dont understand me. i have comma as field delimeter AND as decimal mark. regards – Chris Sep 14 '16 at 12:26
  • Sorry - yes, I'm trying to allow for language. Is there ever a comma between two numbers in your data that is a delimiter? In other words, could we say that any comma between two numbers is a decimal indicator, not a separator? – Shannon Holsinger Sep 14 '16 at 15:36
  • Can you share a few line of your CSV? Perhaps we can parse most if not all of it with predictive algorithm. – Shannon Holsinger Sep 14 '16 at 15:46
0

From what I can tell, you can't change it.

I would agree with what someone already said in your link - you shouldn't be saving csv data to an xls file. When you open a .csv file with excel, it will ask you what delimiter you want to use before you import it.

If you want to change your delimiter before saving, take a look at this post. Make sure to also take a look at the link in that answer - you'd need to use the Microsoft.VisualBasic.FileIO namespace.

However, if you still decide to save as .xls, be careful - you might change your delimiter to ';' before saving, but people whose excel expects ',' as a delimiter will have the same problem you have now.

Community
  • 1
  • 1
shwick
  • 105
  • 1
  • 9
  • hi, thanks for the replay. i dont try so safe the file as a xlsx. I save it as .csv but my excel (2007) dont ask my about the delimeter. i open the csv with a double click not over the open dialog. – Chris Sep 13 '16 at 08:19
0

i solved to problem by save the DataTable instead the DataGrid. The DataTableExtensions class in the link below works very well.

c# datatable to csv

Thanks

Community
  • 1
  • 1
Chris
  • 103
  • 1
  • 8