Table of Contents

Class XlsxWorkbookWriter

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

Writes a workbook to the XLSX (Office Open XML) format, streaming each sheet's rows into a ZIP archive as they're written.

public sealed class XlsxWorkbookWriter : IWorkbookWriter<XlsxSheetWriter>, IDisposable, IAsyncDisposable
Inheritance
XlsxWorkbookWriter
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 XlsxSheetWriter AddSheet(string name)

Parameters

name string

The 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

XlsxSheetWriter

The writer for the new sheet.

Exceptions

ArgumentNullException

name is null.

ArgumentException

name is empty, longer than 31 characters, or contains one of : \ / ? * [ ].

ObjectDisposedException

The workbook has already been ended.

InvalidOperationException

The previously added sheet has not been ended, or a sheet named name already exists.

AddSheet(string, ExcelSheetVisibility)

Begins a new sheet named name with the given tab-bar visibility, and returns its writer. Same contract as AddSheet(string) otherwise.

public XlsxSheetWriter AddSheet(string name, ExcelSheetVisibility visibility)

Parameters

name string

The 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 : \ / ? * [ ]).

visibility ExcelSheetVisibility

Whether the sheet is shown in the workbook's tab bar. A workbook whose sheets are all hidden is rejected when it is ended, since Excel reports such a file as damaged.

Returns

XlsxSheetWriter

The writer for the new sheet.

Exceptions

ArgumentOutOfRangeException

visibility is not a defined value.

ArgumentNullException

name is null.

ArgumentException

name is empty, longer than 31 characters, or contains one of : \ / ? * [ ].

ArgumentOutOfRangeException

visibility is not a defined value.

ObjectDisposedException

The workbook has already been ended.

InvalidOperationException

The previously added sheet has not been ended, or a sheet named name already exists.

AddStyle(CellStyle)

Registers style and returns its index, reusing the index of an already-registered style with the same value. Index 0 is always the general/default style; index 1 is always the builtin date style every date cell already uses.

public int AddStyle(CellStyle style)

Parameters

style CellStyle

The 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, XlsxWriterOptions?)

Creates a new XlsxWorkbookWriter that writes an XLSX package to stream.

public static XlsxWorkbookWriter Create(Stream stream, bool leaveOpen = false, XlsxWriterOptions? options = null)

Parameters

stream Stream

The destination stream; the returned writer takes ownership of the ZIP archive built on top of it.

leaveOpen bool

When true, stream is left open after the workbook is disposed.

options XlsxWriterOptions

Compression, shared-string and background-deflate settings. Defaults to Default.

Returns

XlsxWorkbookWriter

Exceptions

ArgumentNullException

stream is null.

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.

InvalidOperationException

No sheet has been added yet.

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

ct CancellationToken

A token to cancel the operation.

Returns

ValueTask

Exceptions

ObjectDisposedException

The workbook has already been ended.

InvalidOperationException

No sheet has been added yet.

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

ct CancellationToken

A token to cancel the operation.

Returns

ValueTask