tags:

views:

278

answers:

4

Hi,

Creating a CSV file in a winforms application, it is to be improted into Excel.

The file output looks like:

"header1", "header2", "header3", 1,2,3, 4,5,6

What should I use to signify a newline character when generating the CSV file?

A: 

use \r\n although it will work with just \n

Rob Prouse
+6  A: 

I'd suggest using Environment.NewLine.

Jon Grant
A: 

I generally stick with "\n" - because it will be "correct" for the platform on which it is used.

warren
+1  A: 

RFC 4108

While there are various specifications and implementations for the CSV format (for ex. [4], [5], [6] and [7]), there is no formal specification in existence, which allows for a wide variety of interpretations of CSV files. This section documents the format that seems to be followed by most implementations:

  1. Each record is located on a separate line, delimited by a line break (CRLF). For example:

    aaa,bbb,ccc CRLF
    zzz,yyy,xxx CRLF

firebird84