Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Class

CsvRowWriter

OfficeIMO.CSV

Namespace
OfficeIMO.CSV
Assembly
OfficeIMO.CSV
Source revision
e163ccb36643 with working tree changes
Implements
IDisposable
Modifiers
sealed

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

Constructors

public CsvRowWriter(TextWriter writer, CsvSaveOptions? options = null, bool leaveOpen = false) #

Initializes a streaming row writer.

Parameters

writer System.IO.TextWriter required
Destination text writer.
options OfficeIMO.CSV.CsvSaveOptions? = null optional
Optional CSV save options.
leaveOpen bool = false optional
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 required
Destination CSV path.
options OfficeIMO.CSV.CsvSaveOptions? = null optional
Optional CSV serialization settings.
append bool = false optional
Whether rows should be appended to an existing uncompressed file.
bufferSize int = 262144 optional
File and text-writer buffer size.

Returns

CsvRowWriter A writer that owns the destination file and releases it when disposed.
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 required
Writable destination stream.
options OfficeIMO.CSV.CsvSaveOptions? = null optional
CSV serialization, encoding, and compression settings. Auto compression means none for streams.
leaveOpen bool = false optional
Whether disposal keeps the supplied stream open. Compression wrappers are always completed and disposed.
bufferSize int = 262144 optional
Text and byte buffer size.

Returns

CsvRowWriter A writer that owns its buffering and observes the requested stream ownership.
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 required
Requested compression type.
path string required
Destination path used when compressionType is CsvCompressionType.Auto.

Returns

CsvCompressionType The effective compression type.
WriteDataReader 2 overloads
public void WriteDataReader(IDataReader reader) #

Writes all rows from an IDataReader using the reader field names as CSV columns.

Parameters

reader System.Data.IDataReader required
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 required
Source data reader positioned before the first row.
cancellationToken System.Threading.CancellationToken required
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 required
Source reader positioned before the first row.
parallelOptions OfficeIMO.CSV.CsvWriteParallelOptions? = null optional
Parallel worker and batch limits.
cancellationToken System.Threading.CancellationToken = default optional
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? required
Object, dictionary, or flattened row to write.
WriteRow 3 overloads
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> required
Column names for the first row and validation for later rows.
values System.Collections.Generic.IReadOnlyList<object?> required
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> required
Column names for the first row and validation for later rows.
values object?[] required
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?[] required
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> required
Column names shared by every row.
rows System.Collections.Generic.IEnumerable<object?[]?> required
Rows whose values use the same order as columns.
WriteRow``1 2 overloads
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 required
Number of values exposed by valueAccessor.
state TState? required
Caller state passed to valueAccessor for each column index.
valueAccessor System.Func<TState?, int, object?> required
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> required
Column names for the first row and validation for later rows.
valueCount int required
Number of values exposed by valueAccessor.
state TState? required
Caller state passed to valueAccessor for each column index.
valueAccessor System.Func<TState?, int, object?> required
Function that returns the value for a column index.
WriteTextRow 2 overloads
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> required
Column names for the first row and validation for later rows.
values string?[] required
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?[] required
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> required
Column names shared by every row.
rows System.Collections.Generic.IEnumerable<string?[]?> required
Text rows whose values use the same order as columns.
WriteTextRow``1 2 overloads
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> required
Column names for the first row and validation for later rows.
valueCount int required
Number of values exposed by valueAccessor.
state TState? required
Caller state passed to valueAccessor for each column index.
valueAccessor System.Func<TState?, int, string?> required
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 required
Number of values exposed by valueAccessor.
state TState? required
Caller state passed to valueAccessor for each column index.
valueAccessor System.Func<TState?, int, string?> required
Function that returns the already-formatted text for a column index.
WriteUtf8Row 2 overloads
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> required
Column names used to establish or validate the schema.
values System.ReadOnlyMemory<byte>?[] required
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>?[] required
Validated synchronously; null and empty memory retain their distinct formatting semantics.
WriteUtf8Row``1 2 overloads
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> required
Column names used to establish or validate the schema.
valueCount int required
Number of fields returned by the accessor.
state TState? required
State passed to the accessor.
valueAccessor System.Func<TState?, int, System.ReadOnlyMemory<byte>?> required
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 required
Number of fields returned by the accessor.
state TState? required
State passed to the accessor.
valueAccessor System.Func<TState?, int, System.ReadOnlyMemory<byte>?> required
Called once per field; its memory is consumed synchronously.

Properties

public bool HasRows { get; } #

Gets whether at least one row was written.