Class CsvWorkbookWriter
Writes a CSV file through the IWorkbookWriter<TSheet> contract. A CSV file holds exactly one sheet, so only a single AddSheet(string) call is supported.
public sealed class CsvWorkbookWriter : IWorkbookWriter<CsvSheetWriter>, IDisposable, IAsyncDisposable
- Inheritance
-
CsvWorkbookWriter
- Implements
- Inherited Members
- Extension Methods
Methods
AddSheet(string)
Begins a new sheet named name and returns its writer. Only one sheet may be
open (started and not yet ended) at a time; the previous sheet's writer must be ended and
disposed before starting the next one.
public CsvSheetWriter AddSheet(string name)
Parameters
namestringThe sheet's name, shown to Excel; must be unique (ignoring case) within the workbook and meet Excel's sheet-name restrictions (1-31 characters, no
: \ / ? * [ ]).
Returns
- CsvSheetWriter
The writer for the new sheet.
Exceptions
- ArgumentNullException
nameis null.- ArgumentException
nameis empty, longer than 31 characters, or contains one of: \ / ? * [ ].- ObjectDisposedException
The workbook has already been ended.
- InvalidOperationException
A sheet was already added; a CSV file holds only one.
AddSheet(string, ExcelSheetVisibility)
Validates visibility, then ignores it: delimited text has no tab bar, so a
CSV file cannot record that a sheet is hidden.
public CsvSheetWriter AddSheet(string name, ExcelSheetVisibility visibility)
Parameters
namestringThe sheet's name, shown to Excel; must be unique (ignoring case) within the workbook and meet Excel's sheet-name restrictions (1-31 characters, no
: \ / ? * [ ]).visibilityExcelSheetVisibility
Returns
- CsvSheetWriter
The writer for the new sheet.
Exceptions
- ArgumentNullException
nameis null.- ArgumentException
nameis empty, longer than 31 characters, or contains one of: \ / ? * [ ].- ObjectDisposedException
The workbook has already been ended.
- InvalidOperationException
A sheet was already added; a CSV file holds only one.
- ArgumentOutOfRangeException
visibilityis not a defined value.
AddStyle(CellStyle)
No-op: CSV has no cell styles. Always returns 0.
public int AddStyle(CellStyle style)
Parameters
styleCellStyleThe number format/bold/italic combination to register.
Returns
- int
The style's index, for use with SetColumnStyle(int, int) and StartRowAsync(int, CancellationToken).
Exceptions
- ArgumentException
The style's number format is longer than 255 characters.
- ExcelLimitExceededException
The workbook already has 200 distinct number formats, the most Excel opens.
Create(Stream, bool, CsvWriterOptions?)
Creates a writer that emits a CSV file to stream.
public static CsvWorkbookWriter Create(Stream stream, bool leaveOpen = false, CsvWriterOptions? options = null)
Parameters
streamStreamThe destination stream.
leaveOpenboolIf true, the stream is left open when the writer is disposed.
optionsCsvWriterOptionsDelimiter/quote options; defaults to Default when omitted.
Returns
Dispose()
Synchronous counterpart to DisposeAsync(), for native/unmanaged callers whose ABI is synchronous.
public void Dispose()
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.
End()
Synchronous counterpart to EndAsync(CancellationToken), for native/unmanaged callers whose ABI is synchronous.
public void End()
Exceptions
- ObjectDisposedException
The workbook has already been ended.
EndAsync(CancellationToken)
Finalizes the workbook, writing any trailing structure (e.g. the workbook manifest/index) so the destination stream contains a complete, readable file. No further sheets may be added afterward. Idempotent with disposal: disposing an already-ended workbook is a no-op beyond releasing resources. A call that fails part-way still ends the workbook: it cannot be retried, and disposing it only releases the stream. A token already canceled on entry leaves the workbook untouched.
public ValueTask EndAsync(CancellationToken ct = default)
Parameters
ctCancellationTokenA token to cancel the operation.
Returns
Exceptions
- ObjectDisposedException
The workbook has already been ended.
Flush()
Synchronous counterpart to FlushAsync(CancellationToken), for native/unmanaged callers whose ABI is synchronous.
public void Flush()
FlushAsync(CancellationToken)
Flushes any buffered output for the workbook and its current sheet to the destination stream.
public ValueTask FlushAsync(CancellationToken ct = default)
Parameters
ctCancellationTokenA token to cancel the operation.