Table of Contents

Interface ISheetWriter<TRow>

Namespace
ExcelReader.Core.Writer
Assembly
ExcelReader.Core.dll

Writes one sheet's rows to the workbook. Obtained from AddSheet(string); a caller optionally sets column styles and widths, writes rows in order via StartRowAsync(CancellationToken), then ends the sheet. The sheet's leading structure is written when the first row starts, or at EndAsync(CancellationToken) for a sheet with no rows.

public interface ISheetWriter<TRow> : IDisposable, IAsyncDisposable

Type Parameters

TRow

The concrete IRowWriter this sheet produces.

Inherited Members

Remarks

Only ExcelReader implements this interface, and a minor version can add members to it. See versioning and compatibility.

Methods

End()

Synchronous counterpart to EndAsync(CancellationToken): finalizes the sheet without the async/await machinery, for native/unmanaged callers whose ABI is synchronous.

[SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = "'End' is not reserved in C#, this project's primary language; matches the sync/async naming pair (End/EndAsync) already used throughout this codebase (e.g. XlsSheetWriter.End).")]
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.

ValueTask EndAsync(CancellationToken ct = default)

Parameters

ct CancellationToken

A token to cancel the operation.

Returns

ValueTask

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.

void SetColumnStyle(int columnIndex, int styleId)

Parameters

columnIndex int

The 0-based column index.

styleId int

The style to apply, from AddStyle(CellStyle).

Exceptions

ArgumentOutOfRangeException

columnIndex is negative or beyond the format's last column, or styleId is 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.

void SetColumnWidth(int columnIndex, double width)

Parameters

columnIndex int

The 0-based column index.

width double

The column width, in characters.

Exceptions

ArgumentOutOfRangeException

columnIndex is negative or beyond the format's last column, or width is negative or greater than 255.

InvalidOperationException

The first row has already been started.

StartRow()

Synchronous counterpart to StartRowAsync(CancellationToken): begins the next row, without the async/await machinery, for native/unmanaged callers whose ABI is synchronous.

TRow StartRow()

Returns

TRow

The writer for the new row.

StartRow(int)

Synchronous counterpart to StartRowAsync(int, CancellationToken): begins the next row with styleId applied to its cells, without the async/await machinery.

TRow StartRow(int styleId)

Parameters

styleId int

The style to apply to every cell of this row.

Returns

TRow

The writer for the new row.

Exceptions

ArgumentOutOfRangeException

styleId is negative or was never returned by AddStyle(CellStyle).

StartRowAsync(int, CancellationToken)

Begins the next row, applying styleId (from AddStyle(CellStyle)) to its cells.

ValueTask<TRow> StartRowAsync(int styleId, CancellationToken ct = default)

Parameters

styleId int

The style to apply to every cell of this row.

ct CancellationToken

A token to cancel the operation.

Returns

ValueTask<TRow>

The writer for the new row.

Exceptions

ArgumentOutOfRangeException

styleId is 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.

ValueTask<TRow> StartRowAsync(CancellationToken ct = default)

Parameters

ct CancellationToken

A token to cancel the operation.

Returns

ValueTask<TRow>

The writer for the new row.