Class SheetWriterExtensions
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
sheetXlsxSheetWriterThe sheet to write rows to.
recordsIEnumerable<T>The records to write, one row each, in enumeration order.
writeRowAction<XlsxRowWriter, T>Populates a row's cells from a single record.
ctCancellationTokenA token to cancel the operation between rows.
Returns
Type Parameters
TThe 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
sheetISheetWriter<TRow>The sheet to write to; no row may have been started on it yet.
recordsIAsyncEnumerable<T>The records to write, one row each, in enumeration order.
layoutExcelRecordLayout<T>The columns to write, from ExcelRecordLayout.
ctCancellationTokenA token to cancel the operation between rows, and passed to the source enumerable.
Returns
Type Parameters
TThe record type being written.
TRowThe 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
sheetISheetWriter<TRow>The sheet to write rows to.
recordsIAsyncEnumerable<T>The records to write, one row each, in enumeration order.
writeRowAction<TRow, T>Populates a row's cells from a single record.
ctCancellationTokenA token to cancel the operation between rows, and passed to the source enumerable.
Returns
Type Parameters
TThe record type being written.
TRowThe 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
sheetISheetWriter<TRow>The sheet to write to; no row may have been started on it yet.
recordsIEnumerable<T>The records to write, one row each, in enumeration order.
layoutExcelRecordLayout<T>The columns to write, from ExcelRecordLayout.
ctCancellationTokenA token to cancel the operation between rows.
Returns
Type Parameters
TThe record type being written.
TRowThe 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
sheetISheetWriter<TRow>The sheet to write rows to.
recordsIEnumerable<T>The records to write, one row each, in enumeration order.
writeRowAction<TRow, T>Populates a row's cells from a single record.
ctCancellationTokenA token to cancel the operation between rows.
Returns
Type Parameters
TThe record type being written.
TRowThe concrete row writer type.
WriteTableAsync<T, TRow>(ITableSheetWriter<TRow>, IAsyncEnumerable<T>, string, ExcelRecordLayout<T>, ExcelTableOptions?, CancellationToken)
Writes the records produced by records as an Excel table named name,
as WriteTableAsync<T, TRow>(ITableSheetWriter<TRow>, IEnumerable<T>, string, ExcelRecordLayout<T>, ExcelTableOptions?, CancellationToken) does.
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
sheetITableSheetWriter<TRow>The XLSX or XLSB sheet to write to.
recordsIAsyncEnumerable<T>The records to write, one row each, in enumeration order.
namestringThe table name; see BeginTable(string, IReadOnlyList<string>, ExcelTableOptions?).
layoutExcelRecordLayout<T>The columns to write, from ExcelRecordLayout.
optionsExcelTableOptionsPosition and style. Defaults to Default.
ctCancellationTokenA token to cancel the operation between rows, and passed to the source enumerable.
Returns
Type Parameters
TThe record type being written.
TRowThe 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
sheetITableSheetWriter<TRow>The XLSX or XLSB sheet to write to.
recordsIEnumerable<T>The records to write, one row each, in enumeration order.
namestringThe table name; see BeginTable(string, IReadOnlyList<string>, ExcelTableOptions?).
layoutExcelRecordLayout<T>The columns to write, from ExcelRecordLayout.
optionsExcelTableOptionsPosition and style. Defaults to Default.
ctCancellationTokenA token to cancel the operation between rows.
Returns
Type Parameters
TThe record type being written.
TRowThe concrete row writer type.