Class XlsSheetWriter
Writes a single sheet of a BIFF8 (.xls) workbook, buffering cell records in memory until the workbook is finalized. Rows beyond the BIFF8 65,536-row cap spill into an auto-generated continuation sheet.
public sealed class XlsSheetWriter : ISheetWriter<XlsRowWriter>, IDisposable, IAsyncDisposable
- Inheritance
-
XlsSheetWriter
- Implements
- Inherited Members
- Extension Methods
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
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()
Marks the sheet (and any continuation sheet it spilled into) as ended.
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
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 sheet 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 sheet has already been started.
SetShowGridLines(bool)
Sets whether the sheet shows its gridlines when opened; sheets show them by default. Must be called before the first row is started. The default implementation does nothing, so sheet writers implemented outside this library keep compiling.
public void SetShowGridLines(bool show)
Parameters
Exceptions
- InvalidOperationException
The first row has already been started.
- InvalidOperationException
The sheet has already been started.
StartRow()
Begins writing the next row, transparently spilling into a continuation sheet once the BIFF8 row cap is reached.
public XlsRowWriter StartRow()
Returns
StartRow(int)
Begins writing the next row with styleId applied to its cells,
transparently spilling into a continuation sheet once the BIFF8 row cap is reached.
public XlsRowWriter StartRow(int styleId)
Parameters
styleIdint
Returns
Exceptions
- ArgumentOutOfRangeException
styleIdis negative or was never returned by AddStyle(CellStyle).
StartRow(int, double)
Begins writing the next row with styleId applied to its cells and a custom
height, transparently spilling into a continuation sheet once the BIFF8 row cap is reached.
public XlsRowWriter StartRow(int styleId, double height)
Parameters
styleIdintThe style to apply to every cell of this row; 0 for none.
heightdoubleThe row height in points, greater than 0 and at most 409.
Returns
Exceptions
- ArgumentOutOfRangeException
styleIdis negative or was never returned by AddStyle(CellStyle), orheightis out of range or NaN.
StartRowAsync(int, double, CancellationToken)
Begins the next row with styleId applied to its cells and a custom height.
The height is chosen here because XLSX writes it into the row's start tag and XLSB/XLS into the
row header. CSV accepts the call and ignores the height.
public ValueTask<XlsRowWriter> StartRowAsync(int styleId, double height, CancellationToken ct = default)
Parameters
styleIdintThe style to apply to every cell of this row; 0 for none.
heightdoubleThe row height in points, greater than 0 and at most 409. Stored to the nearest twip (1/20 point).
ctCancellationTokenA token to cancel the operation.
Returns
- ValueTask<XlsRowWriter>
The writer for the new row.
Exceptions
- ArgumentOutOfRangeException
styleIdis negative or was never returned by AddStyle(CellStyle), orheightis out of range or NaN.- NotSupportedException
The implementation does not support row heights.
StartRowAsync(int, CancellationToken)
Begins the next row, applying styleId (from AddStyle(CellStyle))
to its cells.
public ValueTask<XlsRowWriter> 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<XlsRowWriter>
The writer for the new row.
Exceptions
- 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<XlsRowWriter> StartRowAsync(CancellationToken ct = default)
Parameters
ctCancellationTokenA token to cancel the operation.
Returns
- ValueTask<XlsRowWriter>
The writer for the new row.
Remarks
XLS buffers everything in memory, so this (and the other *Async members below) simply
wraps the synchronous path in a completed ValueTask.