Class XlsbSheetWriter
Writes a single worksheet's rows into an .xlsb workbook produced by XlsbWorkbookWriter.
public sealed class XlsbSheetWriter : ITableSheetWriter<XlsbRowWriter>, ISheetWriter<XlsbRowWriter>, IDisposable, IAsyncDisposable
- Inheritance
-
XlsbSheetWriter
- Implements
- Inherited Members
- Extension Methods
Methods
BeginTable(string, IReadOnlyList<string>, ExcelTableOptions?)
Writes a header row with columns at the sheet's next row and opens a table there.
The table covers every row written until EndTable() or the end of the sheet.
public void BeginTable(string name, IReadOnlyList<string> columns, ExcelTableOptions? options = null)
Parameters
namestringThe table name: unique in the workbook, ignoring case, and valid as an Excel name.
columnsIReadOnlyList<string>The column names, written as the header row.
optionsExcelTableOptionsPosition and style. Defaults to Default.
Exceptions
- ArgumentNullException
nameorcolumnsis null.- ArgumentException
The name, a column name or the style is not valid, or the name is already used in this workbook.
- ArgumentOutOfRangeException
FirstColumn is negative.
- InvalidOperationException
A table is already open on this sheet, or a row is still active.
- ObjectDisposedException
The sheet has already been ended.
- ExcelLimitExceededException
The sheet has no room left for a header row and a data row.
BeginTableAsync(string, IReadOnlyList<string>, ExcelTableOptions?, CancellationToken)
Writes a header row with columns at the sheet's next row and opens a table there.
The table covers every row written until EndTable() or the end of the sheet.
public ValueTask BeginTableAsync(string name, IReadOnlyList<string> columns, ExcelTableOptions? options = null, CancellationToken ct = default)
Parameters
namestringThe table name: unique in the workbook, ignoring case, and valid as an Excel name.
columnsIReadOnlyList<string>The column names, written as the header row.
optionsExcelTableOptionsPosition and style. Defaults to Default.
ctCancellationTokenA token to cancel the header write.
Returns
Exceptions
- ArgumentNullException
nameorcolumnsis null.- ArgumentException
The name, a column name or the style is not valid, or the name is already used in this workbook.
- ArgumentOutOfRangeException
FirstColumn is negative.
- InvalidOperationException
A table is already open on this sheet, or a row is still active.
- ObjectDisposedException
The sheet has already been ended.
- ExcelLimitExceededException
The sheet has no room left for a header row and a data row.
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()
EndAsync(CancellationToken)
Finalizes the sheet, writing any trailing structure so the sheet is complete within the workbook. The active row writer, if any, must already be disposed. No further rows may be started afterward.
public ValueTask EndAsync(CancellationToken ct = default)
Parameters
ctCancellationTokenA token to cancel the operation.
Returns
EndTable()
Closes the open table at the last row written. Writes nothing; the table is stored when the sheet ends.
public void EndTable()
Exceptions
- InvalidOperationException
No table is open on this sheet.
- ObjectDisposedException
The sheet has already been ended.
SetColumnStyle(int, int)
Applies styleId to every cell of column columnIndex
that does not carry its own row style. Must be called before the first row is started.
public void SetColumnStyle(int columnIndex, int styleId)
Parameters
columnIndexintThe 0-based column index.
styleIdintThe style to apply, from AddStyle(CellStyle).
Exceptions
- ArgumentOutOfRangeException
columnIndexis negative or beyond the format's last column, orstyleIdis negative or was never returned by AddStyle(CellStyle).- InvalidOperationException
The first row has already been started.
- ArgumentOutOfRangeException
columnIndexis negative, orstyleIdis negative or was never returned by AddStyle(CellStyle).- InvalidOperationException
The first row has already been started.
SetColumnWidth(int, double)
Sets the display width, in characters, of column columnIndex. Must be
called before the first row is started.
public void SetColumnWidth(int columnIndex, double width)
Parameters
Exceptions
- ArgumentOutOfRangeException
columnIndexis negative or beyond the format's last column, orwidthis negative or greater than 255.- InvalidOperationException
The first row has already been started.
- ArgumentOutOfRangeException
columnIndexorwidthis negative.- InvalidOperationException
The first row has already been started.
StartRow()
Synchronous counterpart to StartRow(), for native/unmanaged callers whose ABI is synchronous.
public XlsbRowWriter StartRow()
Returns
StartRow(int)
Synchronous counterpart to StartRow(int), for native/unmanaged callers whose ABI is synchronous.
public XlsbRowWriter StartRow(int styleId)
Parameters
styleIdint
Returns
Exceptions
- ArgumentOutOfRangeException
styleIdis negative or was never returned by AddStyle(CellStyle).
StartRowAsync(int, CancellationToken)
Begins the next row, applying styleId (from AddStyle(CellStyle))
to its cells.
public ValueTask<XlsbRowWriter> StartRowAsync(int styleId, CancellationToken ct = default)
Parameters
styleIdintThe style to apply to every cell of this row.
ctCancellationTokenA token to cancel the operation.
Returns
- ValueTask<XlsbRowWriter>
The writer for the new row.
Exceptions
- ArgumentOutOfRangeException
styleIdis negative or was never returned by AddStyle(CellStyle).- ArgumentOutOfRangeException
styleIdis negative or was never returned by AddStyle(CellStyle).
StartRowAsync(CancellationToken)
Begins the next row, in order starting from the first, and returns its writer. Only one row may be open (started and not yet disposed) at a time; the previous row's writer must be disposed before starting the next one.
public ValueTask<XlsbRowWriter> StartRowAsync(CancellationToken ct = default)
Parameters
ctCancellationTokenA token to cancel the operation.
Returns
- ValueTask<XlsbRowWriter>
The writer for the new row.
WriteRow(ReadOnlySpan<XlsbCell>)
Writes an entire row in one call, mapping each element of values to a column starting at 0.
public void WriteRow(ReadOnlySpan<XlsbCell> values)
Parameters
valuesReadOnlySpan<XlsbCell>