Sunday, February 13, 2011

Generating a CSV file to be imported into Excel, what should I use for a newline character?

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?

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

    From Rob Prouse
  • I'd suggest using Environment.NewLine.

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

    From warren
  • 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

    From firebird84

0 comments:

Post a Comment