CsvOpenWrite(TextWriter, IReadOnlyCollectionString, Char) Method

Initializes a CsvWriter to write CSV with header row.

Definition

Namespace: FolkerKinzel.CsvTools
Assembly: FolkerKinzel.CsvTools (in FolkerKinzel.CsvTools.dll) Version: 2.0.1+2345335399184346d9b2cc992ed5c814406052c1
C#
public static CsvWriter OpenWrite(
	TextWriter writer,
	IReadOnlyCollection<string?> columnNames,
	char delimiter = ','
)

Parameters

writer  TextWriter
The TextWriter used for writing.
columnNames  IReadOnlyCollectionString

A collection of column names for the header to be written.

The collection determines the order in which the columns appear in the CSV and their index in CsvRecord. The Record of the CsvWriter instance, which the method returns, can be accessed with this column names.

The collection will be copied. If the collection contains null values, empty strings or white space, these are replaced by automatically generated column names. Column names cannot appear twice. By default the comparison is case-sensitive but it will be reset to a case-insensitive comparison if the column names are also unique when treated case-insensitive.

delimiter  Char  (Optional)
The field separator character.

Return Value

CsvWriter
A CsvWriter instance that allows you to write CSV data with writer.

Remarks

When exchanging CSV data with Excel, the appropriate arguments can be determined with GetExcelArguments.

Exceptions

ArgumentNullExceptionwriter or columnNames is null.
ArgumentExceptionA column name in columnNames occurs twice.
ArgumentOutOfRangeExceptiondelimiter is either the double quotes " or a line break character ('\r' or '\n').

See Also