Table of Contents

Class XlsxSheetWriter

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

Writes a single worksheet's XML into an XLSX ZIP archive, buffering rows and flushing them to the entry stream once they cross a size threshold.

public sealed class XlsxSheetWriter : ITableSheetWriter<XlsxRowWriter>, ISheetWriter<XlsxRowWriter>, IDisposable, IAsyncDisposable
Inheritance
XlsxSheetWriter
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

name string

The table name: unique in the workbook, ignoring case, and valid as an Excel name.

columns IReadOnlyList<string>

The column names, written as the header row.

options ExcelTableOptions

Position and style. Defaults to Default.

Exceptions

ArgumentNullException

name or columns is 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

name string

The table name: unique in the workbook, ignoring case, and valid as an Excel name.

columns IReadOnlyList<string>

The column names, written as the header row.

options ExcelTableOptions

Position and style. Defaults to Default.

ct CancellationToken

A token to cancel the header write.

Returns

ValueTask

Exceptions

ArgumentNullException

name or columns is 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()

Exceptions

ObjectDisposedException

The sheet has already been ended.

InvalidOperationException

The active XlsxRowWriter has not been disposed.

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

ct CancellationToken

A token to cancel the operation.

Returns

ValueTask

Exceptions

ObjectDisposedException

The sheet has already been ended.

InvalidOperationException

The active XlsxRowWriter has not been disposed.

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

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.

ArgumentOutOfRangeException

columnIndex is negative, 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.

public 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.

ArgumentOutOfRangeException

columnIndex or width is negative.

InvalidOperationException

The first row has already been started.

StartRow()

Synchronous counterpart to StartRowAsync(CancellationToken). Row buffering is synchronous either way, so a caller that never awaits mid-row can skip the per-row ValueTask machinery.

public XlsxRowWriter StartRow()

Returns

XlsxRowWriter

The reusable XlsxRowWriter for the new row.

Exceptions

ObjectDisposedException

The sheet has already been ended.

InvalidOperationException

The previous XlsxRowWriter has not been disposed.

ExcelLimitExceededException

The worksheet's 1,048,576-row limit has been reached.

StartRow(int)

Synchronous counterpart to StartRowAsync(int, CancellationToken).

public XlsxRowWriter StartRow(int styleId)

Parameters

styleId int

The style to apply to every cell of this row.

Returns

XlsxRowWriter

The reusable XlsxRowWriter for the new row.

Exceptions

ArgumentOutOfRangeException

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

ObjectDisposedException

The sheet has already been ended.

InvalidOperationException

The previous XlsxRowWriter has not been disposed.

ExcelLimitExceededException

The worksheet's 1,048,576-row limit has been reached.

StartRowAsync(int, CancellationToken)

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

public ValueTask<XlsxRowWriter> 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<XlsxRowWriter>

The writer for the new row.

Exceptions

ArgumentOutOfRangeException

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

ArgumentOutOfRangeException

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

ObjectDisposedException

The sheet has already been ended.

InvalidOperationException

The previous XlsxRowWriter has not been disposed.

ExcelLimitExceededException

The worksheet's 1,048,576-row limit has been reached.

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<XlsxRowWriter> StartRowAsync(CancellationToken ct = default)

Parameters

ct CancellationToken

A token to cancel the operation.

Returns

ValueTask<XlsxRowWriter>

The writer for the new row.

Exceptions

ObjectDisposedException

The sheet has already been ended.

InvalidOperationException

The previous XlsxRowWriter has not been disposed.

ExcelLimitExceededException

The worksheet's 1,048,576-row limit has been reached.