Class CsvTableWriter
Used to generate a CSV table.
Namespace: Neon.Csv
Assembly: Neon.Common.dll
Syntax
public class CsvTableWriter
Remarks
This class is used to generate a CSV table with column headers with the class handling the mapping of column names to columns. The class is easy to use. Simply construct an instance, passing an array of case insensitive table column header names and then write table rows by calling Set() methods to set row cell values and then WriteRow() to write each row to the output.
Constructors
CsvTableWriter(string[], CsvWriter)
Constructs an instance to write to a CsvWriter.
Declaration
public CsvTableWriter(string[] columnHeaders, CsvWriter writer)
Parameters
Type | Name | Description |
---|---|---|
string[] | columnHeaders | The table column names. |
CsvWriter | writer | The CsvWriter to write to. |
Remarks
note
This method writes the column headers passed to the writer so the application can begin writing rows of data.
CsvTableWriter(string[], Stream, Encoding)
Constructs an instance to write to a stream.
Declaration
public CsvTableWriter(string[] columnHeaders, Stream stream, Encoding encoding)
Parameters
Type | Name | Description |
---|---|---|
string[] | columnHeaders | The table column names. |
Stream | stream | The output stream. |
Encoding | encoding | The file's character Encoding. |
Remarks
note
This method writes the column headers passed to the writer so the application can begin writing rows of data.
CsvTableWriter(string[], TextWriter)
Constructs an instance to write to a TextWriter.
Declaration
public CsvTableWriter(string[] columnHeaders, TextWriter writer)
Parameters
Type | Name | Description |
---|---|---|
string[] | columnHeaders | The table column names. |
TextWriter | writer | The writer. |
Remarks
note
This method writes the column headers passed to the writer so the application can begin writing rows of data.
Properties
ColumnMap
Returns the dictionary that case insensitvely maps a column name to the zero base index of the column.
Declaration
public Dictionary<string, int> ColumnMap { get; }
Property Value
Type | Description |
---|---|
Dictionary<string, int> |
Row
Returns the current row array.
Declaration
public string[] Row { get; }
Property Value
Type | Description |
---|---|
string[] |
Writer
Returns the underlying CsvWriter or null
if the writer is closed.
Declaration
public CsvWriter Writer { get; }
Property Value
Type | Description |
---|---|
CsvWriter |
Methods
Close()
Closes the reader if it is still open.
Declaration
public void Close()
Dispose()
Releases any system resources held by the instance,
Declaration
public void Dispose()
GetColumnIndex(string)
Returns the zero-based index of the specified column.
Declaration
public int GetColumnIndex(string columnName)
Parameters
Type | Name | Description |
---|---|---|
string | columnName | The column name. |
Returns
Type | Description |
---|---|
int | The index of the column or -1 if the column does not exist. |
Set(string, object)
Sets the value of a named table column in the current row.
Declaration
public void Set(string columnName, object value)
Parameters
Type | Name | Description |
---|---|---|
string | columnName | The column name. |
object | value | The column value. |
Remarks
note
This method will do nothing if the columnName
passed does not map to a table column.
Set(string, string)
Sets the value of a named table column in the current row.
Declaration
public void Set(string columnName, string value)
Parameters
Type | Name | Description |
---|---|---|
string | columnName | The column name. |
string | value | The column value. |
Remarks
note
This method will do nothing if the columnName
passed does not map to a table column.
WriteRow()
Writes the current row of data to the output and then clears the row so the application can begin setting the next row.
Declaration
public void WriteRow()