-1

I am working on C# in Win 7.

I need to print to a .txt file by Streamwriter.

  StreamWriter outputfile              = new StreamWriter(MYPATH, true);
  outputfile.Write(String.Format(WIDTH_1 + Constants.WIDTH_1, item1 + " " + subitem + "(ave.)" , item2 + " "+ subitem + "(dev.)"));

Here, WIDTH_1 is "{0,30}", WIDTH_2 is "{1,30}". item2 and item1 are all strings. subitme is string.

When I open it in EXCEL 2012, all columns are in one cell.

I need to print each column in a distinct cell.

Any help would be appreciated.

Thanks

user2420472
  • 1,127
  • 1
  • 12
  • 20

1 Answers1

0

1.Make sure the file you are outputting to is in CSV format (*.CSV)

2.Make sure you have commas between the different columns as follows:

outputfile.Write(String.Concat(col1value, ",", col2value, ",", col3value));

3.Consider using a specific CSV library, rather than rolling your own. Follow the advice 'don't roll your own'.

Are there any CSV readers/writer libraries in C#?

Community
  • 1
  • 1
Jon Barker
  • 1,788
  • 15
  • 25