CsvRowWriter
OfficeIMO.CSV
Streams typed, projected, or data-reader rows to CSV without materializing a CsvDocument.
Inheritance
- object
- CsvRowWriter
Usage
Explore 2 API references to this type
This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.
Returned or exposed by 2
- Method CsvRowWriter.CreateFile
- Method CsvRowWriter.CreateStream
Constructors
public CsvRowWriter(TextWriter writer, CsvSaveOptions? options = null, bool leaveOpen = false) #Initializes a streaming row writer.
Parameters
- writer System.IO.TextWriter
- Destination text writer.
- options OfficeIMO.CSV.CsvSaveOptions? = null
- Optional CSV save options.
- leaveOpen bool = false
- Whether to leave the destination writer open when this writer is disposed.
Methods
public static CsvRowWriter CreateFile(string path, CsvSaveOptions? options = null, bool append = false, int bufferSize = 262144) #Creates a row writer for a file, applying the encoding, compression, append, and no-clobber settings.
Parameters
- path string
- Destination CSV path.
- options OfficeIMO.CSV.CsvSaveOptions? = null
- Optional CSV serialization settings.
- append bool = false
- Whether rows should be appended to an existing uncompressed file.
- bufferSize int = 262144
- File and text-writer buffer size.
public static CsvRowWriter CreateStream(Stream destination, CsvSaveOptions? options = null, bool leaveOpen = false, int bufferSize = 262144) #Creates a row writer at the destination stream's current position.
Parameters
- destination System.IO.Stream
- Writable destination stream.
- options OfficeIMO.CSV.CsvSaveOptions? = null
- CSV serialization, encoding, and compression settings. Auto compression means none for streams.
- leaveOpen bool = false
- Whether disposal keeps the supplied stream open. Compression wrappers are always completed and disposed.
- bufferSize int = 262144
- Text and byte buffer size.
public void Dispose() #Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public static CsvCompressionType ResolveCompression(CsvCompressionType compressionType, string path) #Resolves explicit or file-extension-inferred compression for a destination path.
Parameters
- compressionType OfficeIMO.CSV.CsvCompressionType
- Requested compression type.
- path string
- Destination path used when compressionType is CsvCompressionType.Auto.
public void WriteDataReader(IDataReader reader) #Writes all rows from an IDataReader using the reader field names as CSV columns.
Parameters
- reader System.Data.IDataReader
- Source data reader positioned before the first row.
public void WriteDataReader(IDataReader reader, CancellationToken cancellationToken) #Writes all rows from an IDataReader using the reader field names as CSV columns.
Parameters
- reader System.Data.IDataReader
- Source data reader positioned before the first row.
- cancellationToken System.Threading.CancellationToken
- Token observed while projecting and writing rows.
public void WriteDataReaderParallel(IDataReader reader, CsvWriteParallelOptions? parallelOptions = null, CancellationToken cancellationToken = default) #Writes an IDataReader by reading it sequentially and formatting bounded row batches in parallel. Output order always matches source order.
Parameters
- reader System.Data.IDataReader
- Source reader positioned before the first row.
- parallelOptions OfficeIMO.CSV.CsvWriteParallelOptions? = null
- Parallel worker and batch limits.
- cancellationToken System.Threading.CancellationToken = default
- Token observed while reading, formatting, and committing batches.
public void WriteObject(object? item) #Writes one object row, inferring columns from the first row.
Parameters
- item object?
- Object, dictionary, or flattened row to write.
public void WriteRow(IReadOnlyList<string> columns, IReadOnlyList<object?> values) #Writes one already-projected row using the provided column order.
Parameters
- columns System.Collections.Generic.IReadOnlyList<string>
- Column names for the first row and validation for later rows.
- values System.Collections.Generic.IReadOnlyList<object?>
- Values in the same order as columns.
public void WriteRow(IReadOnlyList<string> columns, object?[] values) #Writes one already-projected row using the provided column order.
Parameters
- columns System.Collections.Generic.IReadOnlyList<string>
- Column names for the first row and validation for later rows.
- values object?[]
- Values in the same order as columns.
public void WriteRow(object?[] values) #Writes one already-projected row using the column order that was established by a previous row.
Parameters
- values object?[]
- Values in the same order as the established CSV columns.
public void WriteRows(IReadOnlyList<string> columns, IEnumerable<object?[]?> rows) #Writes already-projected rows using one shared column order.
Parameters
- columns System.Collections.Generic.IReadOnlyList<string>
- Column names shared by every row.
- rows System.Collections.Generic.IEnumerable<object?[]?>
- Rows whose values use the same order as columns.
public void WriteRow<TState>(int valueCount, TState? state, Func<TState?, int, object?> valueAccessor) #Writes one already-projected row using a caller-provided value accessor and the established column order.
Type Parameters
- TState
- State type used by the value accessor.
Parameters
- valueCount int
- Number of values exposed by valueAccessor.
- state TState?
- Caller state passed to valueAccessor for each column index.
- valueAccessor System.Func<TState?, int, object?>
- Function that returns the value for a column index.
public void WriteRow<TState>(IReadOnlyList<string> columns, int valueCount, TState? state, Func<TState?, int, object?> valueAccessor) #Writes one projected row using a caller-provided value accessor.
Type Parameters
- TState
- State type used by the value accessor.
Parameters
- columns System.Collections.Generic.IReadOnlyList<string>
- Column names for the first row and validation for later rows.
- valueCount int
- Number of values exposed by valueAccessor.
- state TState?
- Caller state passed to valueAccessor for each column index.
- valueAccessor System.Func<TState?, int, object?>
- Function that returns the value for a column index.
public void WriteTextRow(IReadOnlyList<string> columns, string?[] values) #Writes one already-formatted text row using the provided column order.
Parameters
- columns System.Collections.Generic.IReadOnlyList<string>
- Column names for the first row and validation for later rows.
- values string?[]
- Text values in the same order as columns.
public void WriteTextRow(string?[] values) #Writes one already-formatted text row using the column order that was established by a previous row.
Parameters
- values string?[]
- Text values in the same order as the established CSV columns.
public void WriteTextRows(IReadOnlyList<string> columns, IEnumerable<string?[]?> rows) #Writes already-formatted text rows using one shared column order.
Parameters
- columns System.Collections.Generic.IReadOnlyList<string>
- Column names shared by every row.
- rows System.Collections.Generic.IEnumerable<string?[]?>
- Text rows whose values use the same order as columns.
public void WriteTextRow<TState>(IReadOnlyList<string> columns, int valueCount, TState? state, Func<TState?, int, string?> valueAccessor) #Writes one already-formatted text row using a caller-provided value accessor.
Type Parameters
- TState
- State type used by the value accessor.
Parameters
- columns System.Collections.Generic.IReadOnlyList<string>
- Column names for the first row and validation for later rows.
- valueCount int
- Number of values exposed by valueAccessor.
- state TState?
- Caller state passed to valueAccessor for each column index.
- valueAccessor System.Func<TState?, int, string?>
- Function that returns the already-formatted text for a column index.
public void WriteTextRow<TState>(int valueCount, TState? state, Func<TState?, int, string?> valueAccessor) #Writes one already-formatted text row using the column order that was established by a previous row.
Type Parameters
- TState
- State type used by the value accessor.
Parameters
- valueCount int
- Number of values exposed by valueAccessor.
- state TState?
- Caller state passed to valueAccessor for each column index.
- valueAccessor System.Func<TState?, int, string?>
- Function that returns the already-formatted text for a column index.
public void WriteUtf8Row(IReadOnlyList<string> columns, ReadOnlyMemory<byte>?[] values) #Writes one already-formatted UTF-8 row in the supplied column order.
Parameters
- columns System.Collections.Generic.IReadOnlyList<string>
- Column names used to establish or validate the schema.
- values System.ReadOnlyMemory<byte>?[]
- UTF-8 field text. Null uses NullValue; empty memory is an empty text field.
public void WriteUtf8Row(ReadOnlyMemory<byte>?[] values) #Writes UTF-8 text using the schema established by a previous row.
Parameters
- values System.ReadOnlyMemory<byte>?[]
- Validated synchronously; null and empty memory retain their distinct formatting semantics.
public void WriteUtf8Row<TState>(IReadOnlyList<string> columns, int valueCount, TState? state, Func<TState?, int, ReadOnlyMemory<byte>?> valueAccessor) #Writes a UTF-8 row using a caller-provided accessor.
Type Parameters
- TState
- Caller state type.
Parameters
- columns System.Collections.Generic.IReadOnlyList<string>
- Column names used to establish or validate the schema.
- valueCount int
- Number of fields returned by the accessor.
- state TState?
- State passed to the accessor.
- valueAccessor System.Func<TState?, int, System.ReadOnlyMemory<byte>?>
- Called once per field. Borrowed values are consumed before this method returns.
public void WriteUtf8Row<TState>(int valueCount, TState? state, Func<TState?, int, ReadOnlyMemory<byte>?> valueAccessor) #Writes UTF-8 text through an accessor using the established schema.
Type Parameters
- TState
- Caller state type.
Parameters
- valueCount int
- Number of fields returned by the accessor.
- state TState?
- State passed to the accessor.
- valueAccessor System.Func<TState?, int, System.ReadOnlyMemory<byte>?>
- Called once per field; its memory is consumed synchronously.