Table of Contents

Class SheetWriterExtensions

Namespace
ExcelReader.Core.Writer
Assembly
ExcelReader.Core.dll

Convenience methods layered on ISheetWriter<TRow>: write a whole collection of records to a sheet in one call, driving the start-row/write/dispose lifecycle per record.

public static class SheetWriterExtensions
Inheritance
SheetWriterExtensions
Inherited Members

Remarks

Generic over TRow so callers keep the concrete row writer's full Write overloads (int, double, DateTime, ...).

Methods

WriteRecordsAsync<T>(XlsxSheetWriter, IEnumerable<T>, Action<XlsxRowWriter, T>, CancellationToken)

Writes one row per item in records to an XlsxSheetWriter using its synchronous fast path, calling writeRow for each to populate that row's cells. Behaviorally equivalent to the generic ISheetWriter<TRow> overload, but resolved in preference to it when the caller's static sheet type is XlsxSheetWriter — e.g. plain IEnumerable<T> sources, which are the overwhelming majority.

[SuppressMessage("Reliability", "CA1849:Call async methods when in an async method", Justification = "Deliberately using XlsxSheetWriter/XlsxRowWriter's synchronous fast path — see the <remarks> above.")]
public static ValueTask WriteRecordsAsync<T>(this XlsxSheetWriter sheet, IEnumerable<T> records, Action<XlsxRowWriter, T> writeRow, CancellationToken ct = default)

Parameters

sheet XlsxSheetWriter

The sheet to write rows to.

records IEnumerable<T>

The records to write, one row each, in enumeration order.

writeRow Action<XlsxRowWriter, T>

Populates a row's cells from a single record.

ct CancellationToken

A token to cancel the operation between rows.

Returns

ValueTask

Type Parameters

T

The record type being written.

Remarks

Safe because XlsxSheetWriter/XlsxRowWriter row buffering only ever touches the destination stream on the rare buffer-threshold flush (EndBufferedRow, already synchronous), so this overload skips the per-row ValueTask/async-disposable machinery entirely.

WriteRecordsAsync<T, TRow>(ISheetWriter<TRow>, IAsyncEnumerable<T>, ExcelRecordLayout<T>, CancellationToken)

Writes a header row followed by one row per item produced by records, the columns coming from layout. The sheet stays open; dispose it to end it.

public static ValueTask WriteRecordsAsync<T, TRow>(this ISheetWriter<TRow> sheet, IAsyncEnumerable<T> records, ExcelRecordLayout<T> layout, CancellationToken ct = default) where TRow : IRowWriter

Parameters

sheet ISheetWriter<TRow>

The sheet to write to; no row may have been started on it yet.

records IAsyncEnumerable<T>

The records to write, one row each, in enumeration order.

layout ExcelRecordLayout<T>

The columns to write, from ExcelRecordLayout.

ct CancellationToken

A token to cancel the operation between rows, and passed to the source enumerable.

Returns

ValueTask

Type Parameters

T

The record type being written.

TRow

The concrete row writer type.

WriteRecordsAsync<T, TRow>(ISheetWriter<TRow>, IAsyncEnumerable<T>, Action<TRow, T>, CancellationToken)

Writes one row per item produced by records, calling writeRow for each to populate that row's cells.

public static ValueTask WriteRecordsAsync<T, TRow>(this ISheetWriter<TRow> sheet, IAsyncEnumerable<T> records, Action<TRow, T> writeRow, CancellationToken ct = default) where TRow : IRowWriter

Parameters

sheet ISheetWriter<TRow>

The sheet to write rows to.

records IAsyncEnumerable<T>

The records to write, one row each, in enumeration order.

writeRow Action<TRow, T>

Populates a row's cells from a single record.

ct CancellationToken

A token to cancel the operation between rows, and passed to the source enumerable.

Returns

ValueTask

Type Parameters

T

The record type being written.

TRow

The concrete row writer type.

WriteRecordsAsync<T, TRow>(ISheetWriter<TRow>, IEnumerable<T>, ExcelRecordLayout<T>, CancellationToken)

Writes a header row followed by one row per item in records, the columns coming from layout. Headers match the names ExcelParser<T> looks for, so the sheet parses straight back. The sheet stays open; dispose it to end it.

public static ValueTask WriteRecordsAsync<T, TRow>(this ISheetWriter<TRow> sheet, IEnumerable<T> records, ExcelRecordLayout<T> layout, CancellationToken ct = default) where TRow : IRowWriter

Parameters

sheet ISheetWriter<TRow>

The sheet to write to; no row may have been started on it yet.

records IEnumerable<T>

The records to write, one row each, in enumeration order.

layout ExcelRecordLayout<T>

The columns to write, from ExcelRecordLayout.

ct CancellationToken

A token to cancel the operation between rows.

Returns

ValueTask

Type Parameters

T

The record type being written.

TRow

The concrete row writer type.

WriteRecordsAsync<T, TRow>(ISheetWriter<TRow>, IEnumerable<T>, Action<TRow, T>, CancellationToken)

Writes one row per item in records, calling writeRow for each to populate that row's cells.

public static ValueTask WriteRecordsAsync<T, TRow>(this ISheetWriter<TRow> sheet, IEnumerable<T> records, Action<TRow, T> writeRow, CancellationToken ct = default) where TRow : IRowWriter

Parameters

sheet ISheetWriter<TRow>

The sheet to write rows to.

records IEnumerable<T>

The records to write, one row each, in enumeration order.

writeRow Action<TRow, T>

Populates a row's cells from a single record.

ct CancellationToken

A token to cancel the operation between rows.

Returns

ValueTask

Type Parameters

T

The record type being written.

TRow

The concrete row writer type.

WriteTableAsync<T, TRow>(ITableSheetWriter<TRow>, IAsyncEnumerable<T>, string, ExcelRecordLayout<T>, ExcelTableOptions?, CancellationToken)

public static ValueTask WriteTableAsync<T, TRow>(this ITableSheetWriter<TRow> sheet, IAsyncEnumerable<T> records, string name, ExcelRecordLayout<T> layout, ExcelTableOptions? options = null, CancellationToken ct = default) where TRow : IRowWriter

Parameters

sheet ITableSheetWriter<TRow>

The XLSX or XLSB sheet to write to.

records IAsyncEnumerable<T>

The records to write, one row each, in enumeration order.

name string

The table name; see BeginTable(string, IReadOnlyList<string>, ExcelTableOptions?).

layout ExcelRecordLayout<T>

The columns to write, from ExcelRecordLayout.

options ExcelTableOptions

Position and style. Defaults to Default.

ct CancellationToken

A token to cancel the operation between rows, and passed to the source enumerable.

Returns

ValueTask

Type Parameters

T

The record type being written.

TRow

The concrete row writer type.

WriteTableAsync<T, TRow>(ITableSheetWriter<TRow>, IEnumerable<T>, string, ExcelRecordLayout<T>, ExcelTableOptions?, CancellationToken)

Writes records as an Excel table named name: a header row from layout, then one row per record, then closes the table. The sheet stays open.

public static ValueTask WriteTableAsync<T, TRow>(this ITableSheetWriter<TRow> sheet, IEnumerable<T> records, string name, ExcelRecordLayout<T> layout, ExcelTableOptions? options = null, CancellationToken ct = default) where TRow : IRowWriter

Parameters

sheet ITableSheetWriter<TRow>

The XLSX or XLSB sheet to write to.

records IEnumerable<T>

The records to write, one row each, in enumeration order.

name string

The table name; see BeginTable(string, IReadOnlyList<string>, ExcelTableOptions?).

layout ExcelRecordLayout<T>

The columns to write, from ExcelRecordLayout.

options ExcelTableOptions

Position and style. Defaults to Default.

ct CancellationToken

A token to cancel the operation between rows.

Returns

ValueTask

Type Parameters

T

The record type being written.

TRow

The concrete row writer type.