0

I am trying to output my data into .csv file. Into separate columns to be specific. And Im facing a problem where the program puts my data into one column.

This is what I get: http://prntscr.com/jk1q2y

And this is what I want to achieve but cant:http://prntscr.com/jk1rjz

Here is my code:

StringBuilder csvcontent = new StringBuilder();
        csvcontent.AppendLine("Fullname,Age");
        csvcontent.AppendLine("Mama,54");
        string csvpath = "D:\\test.csv";
        File.AppendAllText(csvpath, csvcontent.ToString());

I have googled every possible way of outputing data to .csv file and still am stuck with this thing.

I have came across idea that:

When opening the CSV, check that you're using the correct delimiter.

But honestly that doesnt ring any bells to me

Do you guys have any suggestions or ideas about this whole thing? Its driving me nuts. Any help appreciated :)

zaksas
  • 1
  • 1
    Based on the images you posted, this looks like an Excel issue, not a .NET problem. If you open your csv file in a text editor, like Notepad, it should look exactly as you expect. – zambonee May 19 '18 at 22:05
  • This works for me. Which Excel version do you use? I remember that old Excel expected ";" instead of "," by default of something like that. It probably can be set up. – battlmonstr May 19 '18 at 22:14
  • battlmonstr, HUGE THANK YOU. IT WORKS. but why does it work with semi colon instead of comma? – zaksas May 19 '18 at 22:37
  • Exist topic "[CSV with comma or semicolon?](https://stackoverflow.com/a/10141147/9817281)" – Sergey Gornostaev May 20 '18 at 01:21

0 Answers0