Anonymous123
Anonymous123

Reputation:

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

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?

Upvotes: 1

Views: 556

Answers (4)

Bob Gettys
Bob Gettys

Reputation: 1202

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

Upvotes: 1

warren
warren

Reputation: 33435

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

Upvotes: 0

Jon Grant
Jon Grant

Reputation: 11530

I'd suggest using Environment.NewLine.

Upvotes: 6

Rob Prouse
Rob Prouse

Reputation: 22647

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

Upvotes: 0

Related Questions