Class ParallelSheetWriterExtensions
Record writes that format and compress batches of rows on several threads and write them in order. Memory is bounded by DegreeOfParallelism batches of BatchRows rows.
public static class ParallelSheetWriterExtensions
- Inheritance
-
ParallelSheetWriterExtensions
- Inherited Members
Remarks
The source is enumerated by one flow at a time, never concurrently. A writeRow delegate runs on pool
threads, several at once, so whatever it captures must be safe to use concurrently; the layouts
from ExcelRecordLayout are. Rows may be written through the normal API before
and after a call, but not while one is running. A call that throws, a cancelled one included,
ends the sheet and its workbook. With shared strings on, string indexes depend on thread
timing, so two runs give the same content in files that differ byte for byte.
Methods
WriteRecordsParallelAsync<T>(XlsbSheetWriter, IAsyncEnumerable<T>, ExcelRecordLayout<T>, ParallelWriteOptions?, CancellationToken)
Writes a header row from layout, then one row per record, in parallel batches.
public static ValueTask WriteRecordsParallelAsync<T>(this XlsbSheetWriter sheet, IAsyncEnumerable<T> records, ExcelRecordLayout<T> layout, ParallelWriteOptions? options = null, CancellationToken ct = default)
Parameters
sheetXlsbSheetWriterThe sheet to write rows to.
recordsIAsyncEnumerable<T>The records to write, one row each, in enumeration order.
layoutExcelRecordLayout<T>The columns to write, from ExcelRecordLayout.
optionsParallelWriteOptionsDegree of parallelism and batch size. Defaults to Default.
ctCancellationTokenA token to cancel the operation between batches.
Returns
Type Parameters
TThe record type being written.
Exceptions
- ArgumentNullException
sheet,recordsorlayoutis null.- ArgumentOutOfRangeException
optionsholds a negative degree or a batch size below 1.- ObjectDisposedException
The sheet has already been ended.
- InvalidOperationException
A row is still active on the sheet.
- ExcelLimitExceededException
The records do not fit in the sheet's 1,048,576 rows.
- OperationCanceledException
ctwas cancelled. Unlike a serial write cancelled between rows, this ends the sheet and its workbook.
WriteRecordsParallelAsync<T>(XlsbSheetWriter, IAsyncEnumerable<T>, Action<XlsbRowWriter, T>, ParallelWriteOptions?, CancellationToken)
Writes one row per record in parallel batches, calling writeRow to populate each row. No header is written.
public static ValueTask WriteRecordsParallelAsync<T>(this XlsbSheetWriter sheet, IAsyncEnumerable<T> records, Action<XlsbRowWriter, T> writeRow, ParallelWriteOptions? options = null, CancellationToken ct = default)
Parameters
sheetXlsbSheetWriterThe sheet to write rows to.
recordsIAsyncEnumerable<T>The records to write, one row each, in enumeration order.
writeRowAction<XlsbRowWriter, T>Populates a row's cells from a single record. It runs on pool threads, several at once.
optionsParallelWriteOptionsDegree of parallelism and batch size. Defaults to Default.
ctCancellationTokenA token to cancel the operation between batches.
Returns
Type Parameters
TThe record type being written.
Exceptions
- ArgumentNullException
sheet,recordsorwriteRowis null.- ArgumentOutOfRangeException
optionsholds a negative degree or a batch size below 1.- ObjectDisposedException
The sheet has already been ended.
- InvalidOperationException
A row is still active on the sheet.
- ExcelLimitExceededException
The records do not fit in the sheet's 1,048,576 rows.
- OperationCanceledException
ctwas cancelled. Unlike a serial write cancelled between rows, this ends the sheet and its workbook.
WriteRecordsParallelAsync<T>(XlsbSheetWriter, IEnumerable<T>, ExcelRecordLayout<T>, ParallelWriteOptions?, CancellationToken)
Writes a header row from layout, then one row per record, in parallel batches.
public static ValueTask WriteRecordsParallelAsync<T>(this XlsbSheetWriter sheet, IEnumerable<T> records, ExcelRecordLayout<T> layout, ParallelWriteOptions? options = null, CancellationToken ct = default)
Parameters
sheetXlsbSheetWriterThe sheet to write rows to.
recordsIEnumerable<T>The records to write, one row each, in enumeration order.
layoutExcelRecordLayout<T>The columns to write, from ExcelRecordLayout.
optionsParallelWriteOptionsDegree of parallelism and batch size. Defaults to Default.
ctCancellationTokenA token to cancel the operation between batches.
Returns
Type Parameters
TThe record type being written.
Exceptions
- ArgumentNullException
sheet,recordsorlayoutis null.- ArgumentOutOfRangeException
optionsholds a negative degree or a batch size below 1.- ObjectDisposedException
The sheet has already been ended.
- InvalidOperationException
A row is still active on the sheet.
- ExcelLimitExceededException
The records do not fit in the sheet's 1,048,576 rows.
- OperationCanceledException
ctwas cancelled. Unlike a serial write cancelled between rows, this ends the sheet and its workbook.
WriteRecordsParallelAsync<T>(XlsbSheetWriter, IEnumerable<T>, Action<XlsbRowWriter, T>, ParallelWriteOptions?, CancellationToken)
Writes one row per record in parallel batches, calling writeRow to populate each row. No header is written.
public static ValueTask WriteRecordsParallelAsync<T>(this XlsbSheetWriter sheet, IEnumerable<T> records, Action<XlsbRowWriter, T> writeRow, ParallelWriteOptions? options = null, CancellationToken ct = default)
Parameters
sheetXlsbSheetWriterThe sheet to write rows to.
recordsIEnumerable<T>The records to write, one row each, in enumeration order.
writeRowAction<XlsbRowWriter, T>Populates a row's cells from a single record. It runs on pool threads, several at once.
optionsParallelWriteOptionsDegree of parallelism and batch size. Defaults to Default.
ctCancellationTokenA token to cancel the operation between batches.
Returns
Type Parameters
TThe record type being written.
Exceptions
- ArgumentNullException
sheet,recordsorwriteRowis null.- ArgumentOutOfRangeException
optionsholds a negative degree or a batch size below 1.- ObjectDisposedException
The sheet has already been ended.
- InvalidOperationException
A row is still active on the sheet.
- ExcelLimitExceededException
The records do not fit in the sheet's 1,048,576 rows.
- OperationCanceledException
ctwas cancelled. Unlike a serial write cancelled between rows, this ends the sheet and its workbook.
WriteRecordsParallelAsync<T>(XlsxSheetWriter, IAsyncEnumerable<T>, ExcelRecordLayout<T>, ParallelWriteOptions?, CancellationToken)
Writes a header row from layout, then one row per record, in parallel batches.
public static ValueTask WriteRecordsParallelAsync<T>(this XlsxSheetWriter sheet, IAsyncEnumerable<T> records, ExcelRecordLayout<T> layout, ParallelWriteOptions? options = null, CancellationToken ct = default)
Parameters
sheetXlsxSheetWriterThe sheet to write rows to.
recordsIAsyncEnumerable<T>The records to write, one row each, in enumeration order.
layoutExcelRecordLayout<T>The columns to write, from ExcelRecordLayout.
optionsParallelWriteOptionsDegree of parallelism and batch size. Defaults to Default.
ctCancellationTokenA token to cancel the operation between batches.
Returns
Type Parameters
TThe record type being written.
Exceptions
- ArgumentNullException
sheet,recordsorlayoutis null.- ArgumentOutOfRangeException
optionsholds a negative degree or a batch size below 1.- ObjectDisposedException
The sheet has already been ended.
- InvalidOperationException
A row is still active on the sheet.
- ExcelLimitExceededException
The records do not fit in the sheet's 1,048,576 rows.
- OperationCanceledException
ctwas cancelled. Unlike a serial write cancelled between rows, this ends the sheet and its workbook.
WriteRecordsParallelAsync<T>(XlsxSheetWriter, IAsyncEnumerable<T>, Action<XlsxRowWriter, T>, ParallelWriteOptions?, CancellationToken)
Writes one row per record in parallel batches, calling writeRow to populate each row. No header is written.
public static ValueTask WriteRecordsParallelAsync<T>(this XlsxSheetWriter sheet, IAsyncEnumerable<T> records, Action<XlsxRowWriter, T> writeRow, ParallelWriteOptions? options = null, CancellationToken ct = default)
Parameters
sheetXlsxSheetWriterThe sheet to write rows to.
recordsIAsyncEnumerable<T>The records to write, one row each, in enumeration order.
writeRowAction<XlsxRowWriter, T>Populates a row's cells from a single record. It runs on pool threads, several at once.
optionsParallelWriteOptionsDegree of parallelism and batch size. Defaults to Default.
ctCancellationTokenA token to cancel the operation between batches.
Returns
Type Parameters
TThe record type being written.
Exceptions
- ArgumentNullException
sheet,recordsorwriteRowis null.- ArgumentOutOfRangeException
optionsholds a negative degree or a batch size below 1.- ObjectDisposedException
The sheet has already been ended.
- InvalidOperationException
A row is still active on the sheet.
- ExcelLimitExceededException
The records do not fit in the sheet's 1,048,576 rows.
- OperationCanceledException
ctwas cancelled. Unlike a serial write cancelled between rows, this ends the sheet and its workbook.
WriteRecordsParallelAsync<T>(XlsxSheetWriter, IEnumerable<T>, ExcelRecordLayout<T>, ParallelWriteOptions?, CancellationToken)
Writes a header row from layout, then one row per record, in parallel batches.
public static ValueTask WriteRecordsParallelAsync<T>(this XlsxSheetWriter sheet, IEnumerable<T> records, ExcelRecordLayout<T> layout, ParallelWriteOptions? options = null, CancellationToken ct = default)
Parameters
sheetXlsxSheetWriterThe sheet to write rows to.
recordsIEnumerable<T>The records to write, one row each, in enumeration order.
layoutExcelRecordLayout<T>The columns to write, from ExcelRecordLayout.
optionsParallelWriteOptionsDegree of parallelism and batch size. Defaults to Default.
ctCancellationTokenA token to cancel the operation between batches.
Returns
Type Parameters
TThe record type being written.
Exceptions
- ArgumentNullException
sheet,recordsorlayoutis null.- ArgumentOutOfRangeException
optionsholds a negative degree or a batch size below 1.- ObjectDisposedException
The sheet has already been ended.
- InvalidOperationException
A row is still active on the sheet.
- ExcelLimitExceededException
The records do not fit in the sheet's 1,048,576 rows.
- OperationCanceledException
ctwas cancelled. Unlike a serial write cancelled between rows, this ends the sheet and its workbook.
WriteRecordsParallelAsync<T>(XlsxSheetWriter, IEnumerable<T>, Action<XlsxRowWriter, T>, ParallelWriteOptions?, CancellationToken)
Writes one row per record in parallel batches, calling writeRow to populate each row. No header is written.
public static ValueTask WriteRecordsParallelAsync<T>(this XlsxSheetWriter sheet, IEnumerable<T> records, Action<XlsxRowWriter, T> writeRow, ParallelWriteOptions? options = null, 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. It runs on pool threads, several at once.
optionsParallelWriteOptionsDegree of parallelism and batch size. Defaults to Default.
ctCancellationTokenA token to cancel the operation between batches.
Returns
Type Parameters
TThe record type being written.
Exceptions
- ArgumentNullException
sheet,recordsorwriteRowis null.- ArgumentOutOfRangeException
optionsholds a negative degree or a batch size below 1.- ObjectDisposedException
The sheet has already been ended.
- InvalidOperationException
A row is still active on the sheet.
- ExcelLimitExceededException
The records do not fit in the sheet's 1,048,576 rows.
- OperationCanceledException
ctwas cancelled. Unlike a serial write cancelled between rows, this ends the sheet and its workbook.
WriteTableParallelAsync<T>(XlsbSheetWriter, IAsyncEnumerable<T>, string, ExcelRecordLayout<T>, ExcelTableOptions?, ParallelWriteOptions?, CancellationToken)
Writes records as an Excel table named name: a header row from
layout, one row per record in parallel batches, then closes the table.
public static ValueTask WriteTableParallelAsync<T>(this XlsbSheetWriter sheet, IAsyncEnumerable<T> records, string name, ExcelRecordLayout<T> layout, ExcelTableOptions? tableOptions = null, ParallelWriteOptions? options = null, CancellationToken ct = default)
Parameters
sheetXlsbSheetWriterThe 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.
tableOptionsExcelTableOptionsPosition and style. Defaults to Default.
optionsParallelWriteOptionsDegree of parallelism and batch size. Defaults to Default.
ctCancellationTokenA token to cancel the operation between batches.
Returns
Type Parameters
TThe record type being written.
Exceptions
- ArgumentNullException
sheet,records,nameorlayoutis null.- ArgumentOutOfRangeException
optionsholds a negative degree or a batch size below 1.- OperationCanceledException
ctwas cancelled. Unlike a serial write cancelled between rows, this ends the sheet and its workbook.
WriteTableParallelAsync<T>(XlsbSheetWriter, IEnumerable<T>, string, ExcelRecordLayout<T>, ExcelTableOptions?, ParallelWriteOptions?, CancellationToken)
Writes records as an Excel table named name: a header row from
layout, one row per record in parallel batches, then closes the table.
public static ValueTask WriteTableParallelAsync<T>(this XlsbSheetWriter sheet, IEnumerable<T> records, string name, ExcelRecordLayout<T> layout, ExcelTableOptions? tableOptions = null, ParallelWriteOptions? options = null, CancellationToken ct = default)
Parameters
sheetXlsbSheetWriterThe 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.
tableOptionsExcelTableOptionsPosition and style. Defaults to Default.
optionsParallelWriteOptionsDegree of parallelism and batch size. Defaults to Default.
ctCancellationTokenA token to cancel the operation between batches.
Returns
Type Parameters
TThe record type being written.
Exceptions
- ArgumentNullException
sheet,records,nameorlayoutis null.- ArgumentOutOfRangeException
optionsholds a negative degree or a batch size below 1.- OperationCanceledException
ctwas cancelled. Unlike a serial write cancelled between rows, this ends the sheet and its workbook.
WriteTableParallelAsync<T>(XlsxSheetWriter, IAsyncEnumerable<T>, string, ExcelRecordLayout<T>, ExcelTableOptions?, ParallelWriteOptions?, CancellationToken)
Writes records as an Excel table named name: a header row from
layout, one row per record in parallel batches, then closes the table.
public static ValueTask WriteTableParallelAsync<T>(this XlsxSheetWriter sheet, IAsyncEnumerable<T> records, string name, ExcelRecordLayout<T> layout, ExcelTableOptions? tableOptions = null, ParallelWriteOptions? options = null, CancellationToken ct = default)
Parameters
sheetXlsxSheetWriterThe 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.
tableOptionsExcelTableOptionsPosition and style. Defaults to Default.
optionsParallelWriteOptionsDegree of parallelism and batch size. Defaults to Default.
ctCancellationTokenA token to cancel the operation between batches.
Returns
Type Parameters
TThe record type being written.
Exceptions
- ArgumentNullException
sheet,records,nameorlayoutis null.- ArgumentOutOfRangeException
optionsholds a negative degree or a batch size below 1.- OperationCanceledException
ctwas cancelled. Unlike a serial write cancelled between rows, this ends the sheet and its workbook.
WriteTableParallelAsync<T>(XlsxSheetWriter, IEnumerable<T>, string, ExcelRecordLayout<T>, ExcelTableOptions?, ParallelWriteOptions?, CancellationToken)
Writes records as an Excel table named name: a header row from
layout, one row per record in parallel batches, then closes the table.
public static ValueTask WriteTableParallelAsync<T>(this XlsxSheetWriter sheet, IEnumerable<T> records, string name, ExcelRecordLayout<T> layout, ExcelTableOptions? tableOptions = null, ParallelWriteOptions? options = null, CancellationToken ct = default)
Parameters
sheetXlsxSheetWriterThe 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.
tableOptionsExcelTableOptionsPosition and style. Defaults to Default.
optionsParallelWriteOptionsDegree of parallelism and batch size. Defaults to Default.
ctCancellationTokenA token to cancel the operation between batches.
Returns
Type Parameters
TThe record type being written.
Exceptions
- ArgumentNullException
sheet,records,nameorlayoutis null.- ArgumentOutOfRangeException
optionsholds a negative degree or a batch size below 1.- OperationCanceledException
ctwas cancelled. Unlike a serial write cancelled between rows, this ends the sheet and its workbook.